Commit 12b57a77 authored by Janez K's avatar Janez K

added active learning

parent 245a5d6f
......@@ -239,7 +239,7 @@ class Workflow(models.Model):
class AbstractWidget(models.Model):
name = models.CharField(max_length=200,help_text='Name is the name that will be displayed in the widget repository and under the actual widget itself.')
action = models.CharField(max_length=200,help_text='Action is the name of a python function that will be called when the widget is executed.')
wsdl = models.URLField(verify_exists=False,max_length=200,blank=True,help_text='WSDL and WSDL method are used if the widget is a call of a Web Service. Web Service widgets are usually not entered in the admin panel, but in the application itself by importing a Web Service.')
wsdl = models.URLField(max_length=200,blank=True,help_text='WSDL and WSDL method are used if the widget is a call of a Web Service. Web Service widgets are usually not entered in the admin panel, but in the application itself by importing a Web Service.')
wsdl_method = models.CharField(max_length=200,blank=True,default='')
description = models.TextField(blank=True,help_text='Description is used for a human readable description of what a widget does. A user will see this when he right clicks the widget and clicks help.')
category = models.ForeignKey(Category,related_name="widgets",help_text='Category determines to which category this widget belongs. Categories can be nested.')
......
......@@ -245,6 +245,43 @@ def streaming_tweet_sentiment_service(input_dict,widget,stream=None):
return output_dict
def streaming_active_sentiment_analysis(input_dict,widget,stream=None):
import pickle
from pysimplesoap.client import SoapClient, SoapFault
import pysimplesoap
client = SoapClient(location = "http://batman.ijs.si:8008/",action = 'http://batman.ijs.si:8008/',namespace = "http://example.com/tweetsentiment.wsdl",soap_ns='soap',trace = False,ns = False)
pysimplesoap.client.TIMEOUT = 600
list_of_tweets = input_dict['ltw']
new_list_of_tweets = []
for tweet in list_of_tweets:
new_list_of_tweets.append(tweet['text'])
workflow_id = widget.id
service_input = pickle.dumps((str(workflow_id),new_list_of_tweets))
#print service_input
response = client.ActiveClassifyMultiple(workflowtweets=service_input)
i=0
new_ltw = pickle.loads(str(response.ActiveClassifyMultipleResult))
for new_tweet in new_ltw:
if new_tweet[0]=="True":
list_of_tweets[i]['sentiment']="Positive"
elif new_tweet[0]=="False":
list_of_tweets[i]['sentiment']="Negative"
list_of_tweets[i]['reliability']=new_tweet[1]
i=i+1
output_dict = {}
output_dict['ltw'] = list_of_tweets
return output_dict
def streaming_sentiment_analysis(input_dict,widget,stream=None):
import pickle
from pysimplesoap.client import SoapClient, SoapFault
......
{% extends "streams/base.html" %}
{% block 'container' %}
{% load paginator %}
<h1>Tweet Annotation</h1>
{% if tweets_available %}
<form id="annotationform" method="post">{%csrf_token%}
<table class="table table-striped table-bordered">
<thead>
<tr>
<th style="width:80%">Text</th>
<th>Sentiment</th>
</tr>
</thead>
<tbody>
{% for tweet in tweets %}
<tr>
<td><textarea style="width:98%;" name="tweet{{forloop.counter}}">{{tweet}}</textarea></td>
<td>
<label class="radio">
<input type="radio" name="sentiment{{forloop.counter}}" value="+">
Positive
</label>
<label class="radio">
<input type="radio" name="sentiment{{forloop.counter}}" value="0" checked>
Neutral
</label>
<label class="radio">
<input type="radio" name="sentiment{{forloop.counter}}" value="-">
Negative
</label>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</form>
<button onclick="$('#annotationform').submit();" class="btn btn-large btn-block btn-primary" type="button">Submit annotations</button>
{% else %}
There are currently no tweets to annotate. Please refresh this page or try again later.
{% endif %}
{% endblock %}
......@@ -46,6 +46,24 @@ def streaming_tweet_cloud(request,widget,stream):
return render(request, 'streaming_vizualizations/streaming/tweet_cloud.html', {'tweets':tweets,'widget':widget,
'stream':stream})
def streaming_active_annotation(request,widget,stream):
import pickle
from pysimplesoap.client import SoapClient, SoapFault
import pysimplesoap
client = SoapClient(location = "http://batman.ijs.si:8008/",action = 'http://batman.ijs.si:8008/',namespace = "http://example.com/tweetsentiment.wsdl",soap_ns='soap',trace = False,ns = False)
pysimplesoap.client.TIMEOUT = 600
tweets = []
pickled = pickle.dumps(str(widget.id))
response = client.ActiveGetTweets(workflowid=pickled)
returned_tweets = pickle.loads(str(response.ActiveGetTweetsResult))
for tw in returned_tweets:
if tw!='':
tweets.append(tw)
tweets_available = False
if len(tweets)>0:
tweets_available = True
return render(request, 'streaming_vizualizations/streaming/active_learning.html', {'tweets':tweets,'widget':widget,'stream':stream,'tweets_available':tweets_available})
def streaming_display_tweets_visualization(request,widget,stream):
try:
tweet_data = StreamWidgetData.objects.get(widget=widget,stream=stream).value
......@@ -110,6 +128,7 @@ def streaming_sentiment_graph(request,widget,stream):
negative[tweet['created_at'].date()] = (tweet['created_at'].date(),0)
difference[tweet['created_at'].date()] = (tweet['created_at'].date(),0)
aggregated_data[tweet['created_at'].date()] = (tweet['created_at'].date(),1)
try:
if tweet['reliability'] != -1.0:
if tweet['sentiment'] == "Positive":
positive[tweet['created_at'].date()] = (tweet['created_at'].date(),positive[tweet['created_at'].date()][1]+1)
......@@ -117,6 +136,8 @@ def streaming_sentiment_graph(request,widget,stream):
if tweet['sentiment'] == "Negative":
negative[tweet['created_at'].date()] = (tweet['created_at'].date(),negative[tweet['created_at'].date()][1]+1)
difference[tweet['created_at'].date()] = (tweet['created_at'].date(),difference[tweet['created_at'].date()][1]-1)
except:
pass
volumes = aggregated_data.values()
volumes.sort()
positive = positive.values()
......@@ -143,6 +164,7 @@ def streaming_sentiment_graph(request,widget,stream):
negative[datetime.datetime(d.year,d.month,d.day,d.hour)] = (datetime.datetime(d.year,d.month,d.day,d.hour),0)
difference[datetime.datetime(d.year,d.month,d.day,d.hour)] = (datetime.datetime(d.year,d.month,d.day,d.hour),0)
aggregated_data[datetime.datetime(d.year,d.month,d.day,d.hour)] = (datetime.datetime(d.year,d.month,d.day,d.hour),1)
try:
if tweet['reliability'] != -1.0:
if tweet['sentiment'] == "Positive":
positive[datetime.datetime(d.year,d.month,d.day,d.hour)] = (datetime.datetime(d.year,d.month,d.day,d.hour),positive[datetime.datetime(d.year,d.month,d.day,d.hour)][1]+1)
......@@ -150,6 +172,8 @@ def streaming_sentiment_graph(request,widget,stream):
if tweet['sentiment'] == "Negative":
negative[datetime.datetime(d.year,d.month,d.day,d.hour)] = (datetime.datetime(d.year,d.month,d.day,d.hour),negative[datetime.datetime(d.year,d.month,d.day,d.hour)][1]+1)
difference[datetime.datetime(d.year,d.month,d.day,d.hour)] = (datetime.datetime(d.year,d.month,d.day,d.hour),difference[datetime.datetime(d.year,d.month,d.day,d.hour)][1]-1)
except:
pass
volumes = aggregated_data.values()
volumes.sort()
positive = positive.values()
......@@ -176,6 +200,7 @@ def streaming_sentiment_graph(request,widget,stream):
negative[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)] = (datetime.datetime(d.year,d.month,d.day,d.hour,d.minute),0)
difference[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)] = (datetime.datetime(d.year,d.month,d.day,d.hour,d.minute),0)
aggregated_data[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)] = (datetime.datetime(d.year,d.month,d.day,d.hour,d.minute),1)
try:
if tweet['reliability'] != -1.0:
if tweet['sentiment'] == "Positive":
positive[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)] = (datetime.datetime(d.year,d.month,d.day,d.hour,d.minute),positive[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)][1]+1)
......@@ -183,6 +208,8 @@ def streaming_sentiment_graph(request,widget,stream):
if tweet['sentiment'] == "Negative":
negative[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)] = (datetime.datetime(d.year,d.month,d.day,d.hour,d.minute),negative[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)][1]+1)
difference[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)] = (datetime.datetime(d.year,d.month,d.day,d.hour,d.minute),difference[datetime.datetime(d.year,d.month,d.day,d.hour,d.minute)][1]-1)
except:
pass
volumes = aggregated_data.values()
volumes.sort()
positive = positive.values()
......
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