Commit d8a8fcce authored by Anze Vavpetic's avatar Anze Vavpetic

Merge branch 'dev' of source.ijs.si:kt/mothra into dev

parents 045d4622 29c57675
language: python
python:
- 2.7
notifications:
email: false
install:
- pip install -r requirements.txt
before_script:
- cp mothra/__local_settings.py mothra/local_settings.py
script:
- python manage.py test
......@@ -173,10 +173,13 @@ INSTALLED_APPS_DEFAULT = (
#'rest_framework',
'djcelery',
#'kombu.transport.django',
'discover_runner',
)
INSTALLED_APPS_WORKFLOWS_SUB = ()
TEST_RUNNER = 'discover_runner.DiscoverRunner'
import djcelery
djcelery.setup_loader()
......
......@@ -12,3 +12,5 @@ unidecode==0.04.13
django-jsonview==0.3.0
django-celery==3.1.9
ladon==0.8.9
django-discover-runner==1.0
# naive bayes
# from sklearn import datasets
# iris = datasets.load_iris()
# from sklearn.naive_bayes import GaussianNB
# gnb = GaussianNB()
# y_pred = gnb.fit(iris.data, iris.target).predict(iris.data)
# print "Number of mislabeled points : %d" % (iris.target != y_pred).sum()
#print iris
#print iris.data
# print iris.target
# this code converts data from the csv file into scikit learn dataset and returns it as a tuple
def getDataFromCSV():
from numpy import genfromtxt
my_data = genfromtxt('iris.csv', delimiter=',')
n_sample = []
n_feature = []
attributes = []
for x in my_data:
n_feature.append(x[-1])
n_sample.append(x[:-1])
dataset = (n_sample, n_feature, attributes)
dictionary={"data":dataset}
return dictionary
def naiveBayes(dictionary):
dataset = dictionary["data"]
n_sample = dataset[0]
n_feature = dataset[1]
from sklearn.naive_bayes import GaussianNB
gnb = GaussianNB()
y_pred = gnb.fit(n_sample, n_feature).predict(n_sample)
print "Expected Classification"
print n_feature
print "Predicted Classification"
print y_pred
print "Number of mislabeled points : %d" % (n_feature != y_pred).sum()
#data = getDataFromCSV()
#print data
# ********************* ************************* ***********************
# GENERATE DECISION TREE PDF
# def decisionTreeJ48():
# from sklearn.datasets import load_iris
# from sklearn import tree
# iris = load_iris()
# clf = tree.DecisionTreeClassifier()
# clf = clf.fit(iris.data, iris.target)
# from StringIO import StringIO
# out = StringIO()
# out = tree.export_graphviz(clf, out_file=out)
# print out.getvalue()
# import StringIO, pydot
# dot_data = StringIO.StringIO()
# tree.export_graphviz(clf, out_file=dot_data)
# graph = pydot.graph_from_dot_data(dot_data.getvalue())
# graph.write_pdf("iris.pdf")
# #graph_from_dot_data(out.getvalue()).write_pdf("iris.pdf")
# decisionTreeJ48()
# GENERATE DECISION TREE PNG
def decisionTreeJ48(dictionary):
dataset = dictionary["data"]
n_sample = dataset[0]
n_feature = dataset[1]
from sklearn import tree
clf = tree.DecisionTreeClassifier()
clf = clf.fit(n_sample, n_feature)
from StringIO import StringIO
out = StringIO()
out = tree.export_graphviz(clf, out_file=out)
import StringIO, pydot
from os import system
dot_data = StringIO.StringIO()
dotfile = open("decisionTreeJ48-scikit.dot", 'w')
dotfile = tree.export_graphviz(clf, out_file=dotfile)
dotfile.close()
system("dot -Tpng decisionTreeJ48-scikit.dot -o decisionTreeJ48-scikit.png")
# data = getDataFromCSV()
# decisionTreeJ48(data)
def ScikitDatasetToCSV(dictionary):
dataset = dictionary["data"]
n_sample = dataset[0]
n_feature = dataset[1]
import numpy
csv=[]
count=0
for sample in n_sample:
csv.append(numpy.append(sample,n_feature[count])) #join n_sample and n_feature array
count+=1
numpy.savetxt("foo.csv", csv, delimiter=",")
#data = getDataFromCSV()
# def ScikitDatasetToTAB(dictionary):
# dataset = dictionary["data"]
# n_sample = dataset[0]
# n_feature = dataset[1]
# import numpy
# csv=[]
# count=0
# for sample in n_sample:
# csv.append(numpy.append(sample,n_feature[count])) #join n_sample and n_feature array
# count+=1
# numpy.savetxt("foo.csv", csv, delimiter=" ")
# my_data = genfromtxt("foo.csv", delimiter=" ")
# print my_data
# ScikitDatasetToTAB(data)
def NNK(input_dict):
dataset = input_dict["data"]
n_sample = dataset[0]
n_feature = dataset[1]
from sklearn.neighbors import KNeighborsClassifier
knn = KNeighborsClassifier().fit(n_sample,n_feature)
print knn
def SVC(input_dict):
dataset = input_dict["data"]
n_sample = dataset[0]
n_feature = dataset[1]
from sklearn.svm import SVC
clf = SVC().fit(n_sample,n_feature)
print clf
# SVC(data)
def nearestNeighbour():
import numpy as np
import pylab as pl
from matplotlib.colors import ListedColormap
from sklearn import datasets
from sklearn.neighbors import NearestCentroid
n_neighbors = 15
# import some data to play with
iris = datasets.load_iris()
X = iris.data[:, :2] # we only take the first two features. We could
# avoid this ugly slicing by using a two-dim dataset
y = iris.target
h = .02 # step size in the mesh
# Create color maps
cmap_light = ListedColormap(['#FFAAAA', '#AAFFAA', '#AAAAFF'])
cmap_bold = ListedColormap(['#FF0000', '#00FF00', '#0000FF'])
for shrinkage in [None, 0.1]:
# we create an instance of Neighbours Classifier and fit the data.
clf = NearestCentroid(shrink_threshold=shrinkage)
clf.fit(X, y)
y_pred = clf.predict(X)
print shrinkage, np.mean(y == y_pred)
# Plot the decision boundary. For that, we will asign a color to each
# point in the mesh [x_min, m_max]x[y_min, y_max].
x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1
y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
np.arange(y_min, y_max, h))
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
# Put the result into a color plot
Z = Z.reshape(xx.shape)
pl.figure()
pl.pcolormesh(xx, yy, Z, cmap=cmap_light)
# Plot also the training points
pl.scatter(X[:, 0], X[:, 1], c=y, cmap=cmap_bold)
pl.title("3-Class classification (shrink_threshold=%r)"
% shrinkage)
pl.axis('tight')
# pl.show()
#nearestNeighbour()
#
# REGRESSION EXAMPLES
#
#L2-regularized least squares linear model
def RidgeRegression(input_dict):
# from sklearn.datasets import load_iris
# from sklearn import tree
# iris = load_iris()
# clf = tree.DecisionTreeClassifier()
# clf = clf.fit(iris.data, iris.target)
from sklearn.datasets import load_diabetes
diabetes = load_diabetes()
n_sample = diabetes.data
n_feature = diabetes.target
print "*******SAMPLES********"
print n_sample
print "******FEARTURES*******"
print n_feature
from sklearn.linear_model import Ridge
rgs = Ridge().fit(n_sample, n_feature)
print rgs
print rgs.predict(n_sample)
# L1+L2-regularized least squares linear model trained using Coordinate Descent
def ElasticNetRegression(input_dict):
# from sklearn.datasets import load_iris
# from sklearn import tree
# iris = load_iris()
# clf = tree.DecisionTreeClassifier()
# clf = clf.fit(iris.data, iris.target)
from sklearn.datasets import load_diabetes
dta = load_diabetes()
n_sample = dta.data
n_feature = dta.target
print "*******SAMPLES********"
print n_sample
print "******FEARTURES*******"
print n_feature
from sklearn.linear_model import ElasticNet
rgs = ElasticNet().fit(n_sample, n_feature)
print rgs
print rgs.predict(n_sample)
# ElasticNetRegression(data)
def ClusteringKMeans():
from sklearn import cluster, datasets
iris = datasets.load_iris()
X_iris = iris.data
y_iris = iris.target
k_means = cluster.KMeans(k=3) #number of clusters
k_means.fit(X_iris)
print k_means.labels_
print y_iris
#ClusteringKMeans()
def ClusteringMS():
from sklearn import cluster, datasets
iris = datasets.load_iris()
X_iris = iris.data
y_iris = iris.target
k_means = cluster.SpectralClustering(3)
k_means.fit(X_iris)
print k_means.labels_
print y_iris
#ClusteringMS()
def test():
print(__doc__)
from sklearn import datasets, neighbors, linear_model
digits = datasets.load_digits()
X_digits = digits.data
y_digits = digits.target
n_samples = len(X_digits)
X_train = X_digits[:.9 * n_samples]
y_train = y_digits[:.9 * n_samples]
X_test = X_digits[.9 * n_samples:]
y_test = y_digits[.9 * n_samples:]
knn = neighbors.KNeighborsClassifier()
logistic = linear_model.LogisticRegression()
print('KNN score: %f' % knn.fit(X_train, y_train).score(X_test, y_test))
print('LogisticRegression score: %f'
% logistic.fit(X_train, y_train).score(X_test, y_test))
#test()
def scikitAlgorithms_UCIDataset(var):
from sklearn import datasets
allDSets = {"iris":datasets.load_iris(), "boston":datasets.load_diabetes(), "diabetes":datasets.load_boston()}
dataset = allDSets[var]
output_dict = dataset
return output_dict
#iris = scikitAlgorithms_UCIDataset("iris")
#print iris
def retrunRightType(value):
try:
a= float(value) if '.' in value else int(value) #return int or float
except ValueError:
a= value #return string
print "input par", a
print "is type of", type(a)
retrunRightType("ahas")
#print "input par", a
#print "is type of", type(a)
......@@ -86,6 +86,69 @@
"description": "A link to the Tuk Unity3D web app"
}
},
{
"pk": 428,
"model": "workflows.abstractwidget",
"fields": {
"category": 36,
"treeview_image": "",
"windows_queue": false,
"name": "Tuk the Hunter 3D demonstrator (local)",
"is_streaming": false,
"uid": "ac330214-79fe-497e-b7e3-c10ac0af1e1d",
"interaction_view": "",
"image": "",
"package": "MUSE",
"static_image": "",
"post_interact_action": "",
"user": null,
"visualization_view": "MUSE_virtual_environment_demonstrator_tuk_local",
"streaming_visualization_view": "",
"action": "MUSE_virtual_environment_demonstrator_tuk_local",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"has_progress_bar": false,
"order": 1,
"description": "Local copyt of the 3D demonstrator for the Tuk the Hunter children story"
}
},
{
"pk": 1071,
"model": "workflows.abstractinput",
"fields": {
"widget": 428,
"name": "mapping file URL",
"short_name": "lnk",
"uid": "a5036fb4-926d-4da1-8443-e5f960391b07",
"default": "",
"required": true,
"multi": false,
"parameter_type": null,
"variable": "mappingLink",
"parameter": false,
"order": 1,
"description": "A link to the XML file contating mapping to knowledge representation"
}
},
{
"pk": 1072,
"model": "workflows.abstractinput",
"fields": {
"widget": 428,
"name": "Unity3D app link",
"short_name": "lnk",
"uid": "102b6795-a255-4256-a407-643e45c3afaf",
"default": "Tuk-Text-Workflow-Web.html",
"required": true,
"multi": false,
"parameter_type": "text",
"variable": "unityLink",
"parameter": true,
"order": 1,
"description": "A link to the Tuk Unity3D web app"
}
},
{
"pk": 166,
"model": "workflows.abstractwidget",
......
......@@ -40,11 +40,11 @@ def MUSE_mapping_to_KR_latest(input_dict):
import socket
cli = JSONWSPClient(url)
socket.setdefaulttimeout(None)
result, xml = cli.mapping_to_KR_latest(SRL=data)
result = cli.mapping_to_KR_latest(SRL=data)
mapping, xml = result.response_dict['result']
return {'mapping': mapping, 'xml': xml}
def MUSE_mapping_to_KR_precomputed(input_dict):
url = input_dict['url']
data = input_dict['input_data']
......@@ -74,6 +74,9 @@ def MUSE_semantic_role_labeling(input_dict):
url = input_dict['url']
data = input_dict['xml']
import socket
socket.setdefaulttimeout(None)
cli = JSONWSPClient(url)
result = cli.semantic_role_labeling(xml=data)
srl, txt = result.response_dict['result']
......@@ -85,6 +88,9 @@ def MUSE_semantic_role_labeling_tuk(input_dict):
url = input_dict['url']
data = input_dict['xml']
import socket
socket.setdefaulttimeout(None)
cli = JSONWSPClient(url)
result = cli.semantic_role_labeling_tuk(xml=data)
srl, txt = result.response_dict['result']
......@@ -100,8 +106,17 @@ def MUSE_string_to_file_finished(postdata, input_dict, output_dict):
from socket import getfqdn
import sys
DEVSERVER = (sys.argv[1].startswith('runserver'))
fqdn = '127.0.0.1:8000' if DEVSERVER else getfqdn()
if len(sys.argv) > 1:
if len(sys.argv) > 2 and '.' in sys.argv[2] and ':' in sys.argv[2]:
port = sys.argv[2].split(':')[1]
else:
port = 8000
DEVSERVER = sys.argv[1].startswith('runserver')
else:
DEVSERVER = False
fqdn = '127.0.0.1:' + port if DEVSERVER else getfqdn()
fqdn = 'http://' + fqdn
fileURL = fqdn + postdata.get('fileURL')[0]
return {'fileURL': fileURL}
......@@ -117,3 +132,6 @@ def MUSE_virtual_environment_visualization(input_dict):
def MUSE_virtual_environment_demonstrator_tuk(input_dict):
return {'mappingLink': str(input_dict['mappingLink']), 'unityLink': input_dict['unityLink']}
def MUSE_virtual_environment_demonstrator_tuk_local(input_dict):
return {'mappingLink': str(input_dict['mappingLink']), 'unityLink': input_dict['unityLink']}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Unity Web Player | Tuk the Hunter - Text Parsing</title>
<script type='text/javascript' src='https://ssl-webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/jquery.min.js'></script>
<script type="text/javascript">
<!--
var unityObjectUrl = "http://webplayer.unity3d.com/download_webplayer-3.x/3.0/uo/UnityObject2.js";
if (document.location.protocol == 'https:')
unityObjectUrl = unityObjectUrl.replace("http://", "https://ssl-");
document.write('<script type="text\/javascript" src="' + unityObjectUrl + '"><\/script>');
-->
</script>
<script type="text/javascript">
<!--
var config = {
width: 960,
height: 600,
params: { enableDebugging:"0" }
};
var u = new UnityObject2(config);
jQuery(function() {
var $missingScreen = jQuery("#unityPlayer").find(".missing");
var $brokenScreen = jQuery("#unityPlayer").find(".broken");
$missingScreen.hide();
$brokenScreen.hide();
u.observeProgress(function (progress) {
switch(progress.pluginStatus) {
case "broken":
$brokenScreen.find("a").click(function (e) {
e.stopPropagation();
e.preventDefault();
u.installPlugin();
return false;
});
$brokenScreen.show();
break;
case "missing":
$missingScreen.find("a").click(function (e) {
e.stopPropagation();
e.preventDefault();
u.installPlugin();
return false;
});
$missingScreen.show();
break;
case "installed":
$missingScreen.remove();
break;
case "first":
break;
}
});
u.initPlugin(jQuery("#unityPlayer")[0], "Tuk-Text-Workflow-Web.unity3d");
});
-->
</script>
<style type="text/css">
<!--
body {
font-family: Helvetica, Verdana, Arial, sans-serif;
background-color: white;
color: black;
text-align: center;
}
a:link, a:visited {
color: #000;
}
a:active, a:hover {
color: #666;
}
p.header {
font-size: small;
}
p.header span {
font-weight: bold;
}
p.footer {
font-size: x-small;
}
div.content {
margin: auto;
width: 960px;
}
div.broken,
div.missing {
margin: auto;
position: relative;
top: 50%;
width: 193px;
}
div.broken a,
div.missing a {
height: 63px;
position: relative;
top: -31px;
}
div.broken img,
div.missing img {
border-width: 0px;
}
div.broken {
display: none;
}
div#unityPlayer {
cursor: default;
height: 600px;
width: 960px;
}
-->
</style>
</head>
<body>
<p class="header"><span>Unity Web Player | </span>Tuk the Hunter - Text Parsing</p>
<div class="content">
<div id="unityPlayer">
<div class="missing">
<a href="http://unity3d.com/webplayer/" title="Unity Web Player. Install now!">
<img alt="Unity Web Player. Install now!" src="http://webplayer.unity3d.com/installation/getunity.png" width="193" height="63" />
</a>
</div>
<div class="broken">
<a href="http://unity3d.com/webplayer/" title="Unity Web Player. Install now! Restart your browser after install.">
<img alt="Unity Web Player. Install now! Restart your browser after install." src="http://webplayer.unity3d.com/installation/getunityrestart.png" width="193" height="63" />
</a>
</div>
</div>
</div>
<p class="footer">&laquo; created with <a href="http://unity3d.com/unity/" title="Go to unity3d.com">Unity</a> &raquo;</p>
</body>
</html>
<div id="widgetvisualization-{{ widget.pk }}"
rel="{{ widget.pk }}"
class="widgetvisualizationdialog"
title="{{ widget.name }}"
width=1200 height=900>
<iframe src="{{STATIC_URL}}MUSE/{{ unityLink }}" width="98%" height="98%">
</iframe>
</div>