Commit a80db515 authored by Janez K's avatar Janez K

dodal streaming widgete za clank

parent 219d2b3a
......@@ -2,16 +2,13 @@
{% load url from future %}
{% block "streamnav" %}
<div class="navbar">
<div class="navbar-inner">
<a class="brand">{{stream}}</a>
<ul class="nav">
{% for w in stream.stream_visualization_widgets %}
<br>
<nav class="navbar navbar-default" role="navigation">
<ul class="nav navbar-nav">
{% for w in stream.stream_visualization_widgets %}
<li {% if widget.pk == w.pk %}class="active"{% endif %}><a href="{% url 'stream widget visualization' stream.pk w.pk %}">{{w}}</a></li>
{% endfor %}
</ul>
</div>
</div>
</nav>
{% endblock %}
......@@ -65,6 +65,10 @@
</nav>
<div class="container">
{% block "streamnav" %}
{% endblock %}
{% block 'container' %}
{% endblock %}
</div>
......
......@@ -36,7 +36,7 @@
{% else %}
<a href="{% url 'activate stream' stream.pk %}" class="btn btn-success btn-large">Activate</a>
{% endif %}
<a href="javascript:;" class="reset-stream btn btn-warning btn-danger btn-large">Reset</a>
<a href="{% url 'reset stream' stream.pk %}" class="reset-stream btn btn-warning btn-danger btn-large">Reset</a>
</div>
</div>
<hr>
......@@ -54,7 +54,7 @@
{% for w in stream.stream_visualization_widgets %}
<tr>
<td class="name">{{w}}</td>
<td><a href="{% url 'stream widget visualization' stream.pk w.pk %}" class="btn btn-mini">View results</a></td>
<td><a href="{% url 'stream widget visualization' stream.pk w.pk %}" class="btn btn-sm btn-default">View results</a></td>
</tr>
{% endfor %}
</tbody>
......
......@@ -23,8 +23,8 @@
<td>
{% if w.can_be_streaming %}
{% if w.stream %}
{% if w.stream.active %}<span class="label label-success"><span class="glyphicon glyphicon-ok"></span> Active</span> <a href="{{w.stream.get_absolute_url}}" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-wrench"></span></a>
{% else %}<span class="label label-warning"><span class="glyphicon glyphicon-remove"></span> Inactive</span> <a href="{{w.stream.get_absolute_url}}" class="btn btn-mini"><i class="icon-wrench"></i></a>{% endif %}
{% if w.stream.active %}<span class="label label-success"><span class="glyphicon glyphicon-ok"></span> Active</span> <a href="{{w.stream.get_absolute_url}}" class="btn btn-default btn-xs btn-default"><span class="glyphicon glyphicon-wrench"></span></a>
{% else %}<span class="label label-warning"><span class="glyphicon glyphicon-remove"></span> Inactive</span> <a href="{{w.stream.get_absolute_url}}" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-wrench"></span></a>{% endif %}
{% else %}<a href="{% url 'start stream' w.pk %}" class="btn btn-info btn-xs">Start stream mining</a>{% endif %}
{% else %}<span class="label label-default"><span class="glyphicon glyphicon-remove"></span> No streaming widgets</span>{% endif %}
</td>
......
......@@ -218,6 +218,120 @@
"description": ""
}
},
{
"pk": 243,
"model": "workflows.abstractwidget",
"fields": {
"category": 43,
"treeview_image": "",
"name": "Get news article",
"is_streaming": true,
"uid": "96cc52ff-109a-48b3-ac54-e0a8e3d4f1fa",
"interaction_view": "",
"image": "",
"package": "streaming",
"static_image": "",
"post_interact_action": "",
"user": null,
"visualization_view": "",
"streaming_visualization_view": "",
"action": "streaming_get_article_text",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"has_progress_bar": false,
"order": 1,
"description": ""
}
},
{
"pk": 522,
"model": "workflows.abstractinput",
"fields": {
"widget": 243,
"name": "URL",
"short_name": "url",
"uid": "9cf13cf8-deb9-4175-8a71-d11da0984c99",
"default": "",
"required": false,
"multi": false,
"parameter_type": null,
"variable": "url",
"parameter": false,
"order": 1,
"description": "URL of a news article"
}
},
{
"pk": 251,
"model": "workflows.abstractoutput",
"fields": {
"widget": 243,
"name": "Text",
"short_name": "txt",
"variable": "text",
"uid": "1ca48b0e-8d71-41f5-9754-61cbd1e2b9bc",
"order": 1,
"description": "Summary"
}
},
{
"pk": 242,
"model": "workflows.abstractwidget",
"fields": {
"category": 43,
"treeview_image": "",
"name": "Porter stemmer on triplets",
"is_streaming": true,
"uid": "9dc49613-daa0-440f-bb2c-80909edee633",
"interaction_view": "",
"image": "",
"package": "streaming",
"static_image": "",
"post_interact_action": "",
"user": null,
"visualization_view": "",
"streaming_visualization_view": "",
"action": "streaming_triplet_porter_stemmer",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"has_progress_bar": false,
"order": 1,
"description": ""
}
},
{
"pk": 521,
"model": "workflows.abstractinput",
"fields": {
"widget": 242,
"name": "Triplets",
"short_name": "tri",
"uid": "4887ef25-3d11-47a7-97b3-6d225eddb38a",
"default": "",
"required": false,
"multi": false,
"parameter_type": null,
"variable": "triplets",
"parameter": false,
"order": 1,
"description": ""
}
},
{
"pk": 250,
"model": "workflows.abstractoutput",
"fields": {
"widget": 242,
"name": "Triplets",
"short_name": "tri",
"variable": "triplets",
"uid": "90738598-90c0-41ed-9039-d541a6c61133",
"order": 1,
"description": "Triplets"
}
},
{
"pk": 225,
"model": "workflows.abstractwidget",
......@@ -230,7 +344,7 @@
"interaction_view": "",
"image": "",
"package": "streaming",
"static_image": "",
"static_image": "rss.png",
"post_interact_action": "",
"user": null,
"visualization_view": "",
......@@ -609,6 +723,63 @@
"description": ""
}
},
{
"pk": 240,
"model": "workflows.abstractwidget",
"fields": {
"category": 43,
"treeview_image": "",
"name": "Summarize news article",
"is_streaming": true,
"uid": "90c0715f-36e0-4e06-a2ef-7fb88bf95943",
"interaction_view": "",
"image": "",
"package": "streaming",
"static_image": "summary.png",
"post_interact_action": "",
"user": null,
"visualization_view": "",
"streaming_visualization_view": "",
"action": "streaming_summarize_url",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"has_progress_bar": false,
"order": 1,
"description": "Summarizes a news article retrieved by URL."
}
},
{
"pk": 519,
"model": "workflows.abstractinput",
"fields": {
"widget": 240,
"name": "URL",
"short_name": "url",
"uid": "e475bee2-b965-48fe-b027-4447bc0c6005",
"default": "",
"required": false,
"multi": false,
"parameter_type": null,
"variable": "url",
"parameter": false,
"order": 1,
"description": "URL of a news article"
}
},
{
"pk": 249,
"model": "workflows.abstractoutput",
"fields": {
"widget": 240,
"name": "Summary",
"short_name": "txt",
"variable": "summary",
"uid": "64b1fc78-bd34-4fd1-8cbc-04fd17a94fbd",
"order": 1,
"description": "Summary"
}
},
{
"pk": 231,
"model": "workflows.abstractwidget",
......@@ -709,7 +880,7 @@
"interaction_view": "",
"image": "",
"package": "streaming",
"static_image": "",
"static_image": "triplets.png",
"post_interact_action": "",
"user": null,
"visualization_view": "",
......@@ -747,7 +918,7 @@
"fields": {
"widget": 239,
"name": "Triplets",
"short_name": "str",
"short_name": "tri",
"variable": "triplets",
"uid": "c9bffa1b-2a47-4353-a646-290b1a4640ad",
"order": 1,
......@@ -976,6 +1147,63 @@
"description": "A list of Tweets."
}
},
{
"pk": 244,
"model": "workflows.abstractwidget",
"fields": {
"category": 43,
"treeview_image": "",
"name": "WordNet lemmatizer on triplets",
"is_streaming": true,
"uid": "10957b62-2dcb-4461-8146-70eecf27fcff",
"interaction_view": "",
"image": "",
"package": "streaming",
"static_image": "wordnet.png",
"post_interact_action": "",
"user": null,
"visualization_view": "",
"streaming_visualization_view": "",
"action": "streaming_triplet_wordnet_lemmatizer",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"has_progress_bar": false,
"order": 1,
"description": ""
}
},
{
"pk": 523,
"model": "workflows.abstractinput",
"fields": {
"widget": 244,
"name": "Triplets",
"short_name": "tri",
"uid": "e9bc6945-54fb-4128-87ae-75aa1b7f9a79",
"default": "",
"required": false,
"multi": false,
"parameter_type": null,
"variable": "triplets",
"parameter": false,
"order": 1,
"description": ""
}
},
{
"pk": 252,
"model": "workflows.abstractoutput",
"fields": {
"widget": 244,
"name": "Triplets",
"short_name": "tri",
"variable": "triplets",
"uid": "0b0219b5-8b80-4e61-8cb1-f02123649d54",
"order": 1,
"description": "Triplets"
}
},
{
"pk": 44,
"model": "workflows.category",
......@@ -1120,6 +1348,50 @@
"description": "List of tweets (can be annotated or not)"
}
},
{
"pk": 245,
"model": "workflows.abstractwidget",
"fields": {
"category": 44,
"treeview_image": "",
"name": "Streaming triplet graph",
"is_streaming": true,
"uid": "cf3f6218-1b21-4864-9ee1-c22069abe03d",
"interaction_view": "",
"image": "",
"package": "streaming",
"static_image": "BiomineVisualizer.png",
"post_interact_action": "",
"user": null,
"visualization_view": "",
"streaming_visualization_view": "streaming_triplet_graph_visualization",
"action": "streaming_triplet_graph",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"has_progress_bar": false,
"order": 1,
"description": ""
}
},
{
"pk": 524,
"model": "workflows.abstractinput",
"fields": {
"widget": 245,
"name": "Triplets",
"short_name": "tri",
"uid": "e9c4bd5a-0ea4-4739-bc7c-d95bb40d7e57",
"default": "",
"required": false,
"multi": false,
"parameter_type": null,
"variable": "triplets",
"parameter": false,
"order": 1,
"description": "Triplets"
}
},
{
"pk": 237,
"model": "workflows.abstractwidget",
......
......@@ -189,6 +189,24 @@ def streaming_display_tweets(input_dict,widget,stream=None):
swd.save()
return {}
def streaming_triplet_graph(input_dict,widget,stream=None):
from streams.models import StreamWidgetData
if stream is None:
return {}
else:
try:
swd = StreamWidgetData.objects.get(stream=stream,widget=widget)
swd.value = input_dict['triplets']
swd.save()
except:
swd = StreamWidgetData()
swd.stream = stream
swd.widget = widget
data = input_dict['triplets']
swd.value = data
swd.save()
return {}
def streaming_collect_and_display_tweets(input_dict,widget,stream=None):
from streams.models import StreamWidgetData
if stream is None:
......@@ -245,6 +263,40 @@ def streaming_tweet_sentiment_service(input_dict,widget,stream=None):
return output_dict
def streaming_triplet_porter_stemmer(input_dict,widget,stream=None):
import nltk
triplets = input_dict['triplets']
new_triplets = []
porter_stemmer = nltk.stem.PorterStemmer()
for triplet in triplets:
new_triplet = []
for word in triplet:
try:
new_triplet.append(porter_stemmer.stem(word))
except:
new_triplet.append(word)
new_triplets.append(new_triplet)
output_dict = {}
output_dict['triplets']=new_triplets
return output_dict
def streaming_triplet_wordnet_lemmatizer(input_dict,widget,stream=None):
import nltk
triplets = input_dict['triplets']
new_triplets = []
lemmatizer = nltk.stem.WordNetLemmatizer()
for triplet in triplets:
new_triplet = []
for word in triplet:
try:
new_triplet.append(lemmatizer.lemmatize(word))
except:
new_triplet.append(word)
new_triplets.append(new_triplet)
output_dict = {}
output_dict['triplets']=new_triplets
return output_dict
def streaming_triplet_extraction(input_dict,widget,stream=None):
from pysimplesoap.client import SoapClient, SoapFault
import pysimplesoap
......@@ -261,9 +313,7 @@ def streaming_triplet_extraction(input_dict,widget,stream=None):
new_triplets = []
for triplet in triplets:
print triplet
t = re.sub(r'\([^)]*\)', "",triplet)
print t
triplet = []
words = t.strip().split(" ")
for word in words:
......@@ -285,6 +335,13 @@ def streaming_summarize_url(input_dict,widget,stream=None):
output_dict['summary']=" ".join(summaries)
return output_dict
def streaming_get_article_text(input_dict,widget,stream=None):
import pyteaser
text = pyteaser.grab_link(input_dict['url'])
output_dict = {}
output_dict['text']=text.cleaned_text
return output_dict
def streaming_active_sentiment_analysis(input_dict,widget,stream=None):
import pickle
from pysimplesoap.client import SoapClient, SoapFault
......
{% extends "streams/base.html" %}
{% block "container" %}
<div class="container">
<div class="col-xl-12 col-md-12 col-sm-12 col-sx-12">
<h1>Triplet graph</h1>
<div class="triplet_graph">
</div>
<script src="http://d3js.org/d3.v3.min.js"></script>
<style>
.link {
fill: none;
stroke: #666;
stroke-width: 1.5px;
}
.node circle {
fill: #ccc;
stroke: #fff;
stroke-width: 1.5px;
}
text {
font: 10px sans-serif;
pointer-events: none;
}
</style>
<script>
// http://blog.thomsonreuters.com/index.php/mobile-patent-suits-graphic-of-the-day/
var links = [
{% for triplet in triplets %}
{source: "{{triplet.0}}", target: "{{triplet.1}}", type: "link"},
{source: "{{triplet.1}}", target: "{{triplet.2}}", type: "link"},
{% endfor %}
];
var nodes = {};
// Compute the distinct nodes from the links.
links.forEach(function(link) {
link.source = nodes[link.source] || (nodes[link.source] = {name: link.source});
link.target = nodes[link.target] || (nodes[link.target] = {name: link.target});
});
var width = 1170,
height = 900;
var force = d3.layout.force()
.nodes(d3.values(nodes))
.links(links)
.size([width, height])
.linkDistance(30)
.charge(-80)
.on("tick", tick)
.start();
var svg = d3.select("div.triplet_graph").append("svg")
.attr("width", width)
.attr("height", height);
var link = svg.selectAll(".link")
.data(force.links())
.enter().append("line")
.attr("class", "link");
var node = svg.selectAll(".node")
.data(force.nodes())
.enter().append("g")
.attr("class", "node")
.on("mouseover", mouseover)
.on("mouseout", mouseout)
.call(force.drag);
node.append("circle")
.attr("r", 6);
node.append("text")
.attr("x", 12)
.attr("dy", ".35em")
.text(function(d) { return d.name; });
function tick() {
link
.attr("x1", function(d) { return d.source.x; })
.attr("y1", function(d) { return d.source.y; })
.attr("x2", function(d) { return d.target.x; })
.attr("y2", function(d) { return d.target.y; });
node
.attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; });
}
function mouseover() {
d3.select(this).select("circle").transition()
.duration(750)
.attr("r", 8);
}
function mouseout() {
d3.select(this).select("circle").transition()
.duration(750)
.attr("r", 6);
}
/*setTimeout(function() {
var a = {id: "a"}, b = {id: "b"}, c = {id: "c"};
node.push(a, b, c);
link.push({source: a, target: b}, {source: a, target: c}, {source: b, target: c});
start();
}, 0);
function start() {
link = link.data(force.links(), function(d) { return d.source.id + "-" + d.target.id; });
link.enter().insert("line", ".node").attr("class", "link");
link.exit().remove();
node = node.data(force.nodes(), function(d) { return d.id;});
node.enter().append("circle").attr("class", function(d) { return "node " + d.id; }).attr("r", 8);
node.exit().remove();
force.start();
}
*/
setTimeout(function() {
location.reload();
},2000*{% if stream.period > 5 %}{{stream.period}}{% else %}5{% endif %})
</script>
</div>
</div>
{% endblock %}
......@@ -109,6 +109,14 @@ def streaming_collect_and_display_visualization(request,widget,stream):
return render(request, 'streaming_vizualizations/streaming/display_tweets.html', {'tweets':tweets,'widget':widget,
'stream':stream,'paged':tweets})
def streaming_triplet_graph_visualization(request,widget,stream):
try:
triplets = StreamWidgetData.objects.get(widget=widget,stream=stream).value
except:
triplets = []
return render(request, 'streaming_vizualizations/streaming/triplet_graph.html', {'triplets':triplets,'widget':widget,'stream':stream})
def streaming_sentiment_graph(request,widget,stream):
zoomlevel = "day"
if request.GET.has_key('zoomlevel'):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment