Commit 219d2b3a authored by Janez K's avatar Janez K

dodal triplet graf vizualizacijo

parent 6cd446fa
......@@ -10,4 +10,5 @@ httplib2==0.7.5
wsgiref==0.1.2
unidecode==0.04.13
django-jsonview==0.3.0
feedparser==5.1.3
pyteaser==1.0
This diff is collapsed.
......@@ -145,6 +145,9 @@ def base_ravel_list(input_dict):
def base_wordcloud(input_dict):
return {}
def base_triplet_graph(input_dict):
return {}
def split_documents(input_dict):
output_dict = {}
documents = input_dict['string'].splitlines()
......
{% if iframe %}
<!DOCTYPE html>
<meta charset="utf-8">
<script src="http://d3js.org/d3.v2.js?2.9.1"></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>
<body>
<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 = 630,
height = 500;
var force = d3.layout.force()
.nodes(d3.values(nodes))
.links(links)
.size([width, height])
.linkDistance(60)
.charge(-300)
.on("tick", tick)
.start();
var svg = d3.select("body").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", 8);
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", 16);
}
function mouseout() {
d3.select(this).select("circle").transition()
.duration(750)
.attr("r", 8);
}
</script>
{% else %}
<div id="widgetvisualization-{{widget.pk}}" rel="{{widget.pk}}" class="widgetvisualizationdialog" title="{{widget.name}} visualization" width="750px" height="700px">
<iframe src="./widget-iframe/{{widget.pk}}/" width="700px" height="550px">
</div>
{% endif %}
\ No newline at end of file
......@@ -3,4 +3,9 @@ from django.shortcuts import render
def base_wordcloud(request,input_dict,output_dict,widget,iframe=False):
if request.GET.get('raw',None)=="1":
return render(request, 'visualizations/base_wordcloud_raw.html',{'string':input_dict['string']})
return render(request, 'visualizations/base_wordcloud.html',{'widget':widget,'input_dict':input_dict,'output_dict':output_dict,'iframe':iframe})
\ No newline at end of file
return render(request, 'visualizations/base_wordcloud.html',{'widget':widget,'input_dict':input_dict,'output_dict':output_dict,'iframe':iframe})
def base_triplet_graph(request,input_dict,output_dict,widget,iframe=False):
if request.GET.get('raw',None)=="1":
return render(request, 'visualizations/base_triplet_graph_raw.html',{'string':input_dict['string']})
return render(request, 'visualizations/base_triplet_graph.html',{'widget':widget,'triplets':input_dict['triplets'],'iframe':iframe})
......@@ -248,17 +248,42 @@ def streaming_tweet_sentiment_service(input_dict,widget,stream=None):
def streaming_triplet_extraction(input_dict,widget,stream=None):
from pysimplesoap.client import SoapClient, SoapFault
import pysimplesoap
import re
client = SoapClient(location = "http://95.87.154.167:8008/",action = 'http://95.87.154.167:8008/',namespace = "http://example.com/tweetsentiment.wsdl",soap_ns='soap',trace = False,ns = False)
pysimplesoap.client.TIMEOUT = 36000
text = input_dict['text']
response = client.TripletExtraction(text=text)
triplets = str(response.TripletExtractionResult)
triplets = triplets.split("\n")
new_triplets = []
for triplet in triplets:
print triplet
t = re.sub(r'\([^)]*\)', "",triplet)
print t
triplet = []
words = t.strip().split(" ")
for word in words:
if len(word)>0:
triplet.append(word.lower())
if len(triplet)>0:
new_triplets.append(triplet)
output_dict = {}
output_dict['triplets'] = str(response.TripletExtractionResult)
output_dict['triplets'] = new_triplets
return output_dict
def streaming_summarize_url(input_dict,widget,stream=None):
import pyteaser
summaries = pyteaser.SummarizeUrl(input_dict['url'])
output_dict = {}
output_dict['summary']=" ".join(summaries)
return output_dict
def streaming_active_sentiment_analysis(input_dict,widget,stream=None):
import pickle
......
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