Commit ced06745 authored by Anze Vavpetic's avatar Anze Vavpetic

cleaned up the conceptnet package: removed dead code; added a widget for...

cleaned up the conceptnet package: removed dead code; added a widget for parsing triplets out of the conceptnet json response; general cleaning up
parent c9cedbe0
[
{
"pk": 40,
"pk": 63,
"model": "workflows.category",
"fields": {
"uid": "aa1a52a7-66ee-483d-b24a-e543140fc476",
......@@ -12,15 +12,15 @@
}
},
{
"pk": 200,
"pk": 341,
"model": "workflows.abstractwidget",
"fields": {
"category": 40,
"category": 63,
"treeview_image": "",
"windows_queue": false,
"name": "Create Conceptnet Query",
"name": "Conceptnet Create Search Query",
"is_streaming": false,
"uid": "388e290b-f2db-4906-b1ed-ba75feefbf9a",
"uid": "e2359c29-f2bc-4cc5-92b2-5d32f9a26de3",
"interaction_view": "",
"image": "",
"package": "conceptnet",
......@@ -29,168 +29,110 @@
"user": null,
"visualization_view": "",
"streaming_visualization_view": "",
"action": "create_conceptnet_query",
"action": "conceptnet_create_search_query",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"has_progress_bar": false,
"order": 1,
"description": "The widget returns a query for the method \"Query to Json\"."
}
},
{
"pk": 368,
"model": "workflows.abstractinput",
"fields": {
"widget": 200,
"name": "Command",
"short_name": "cmd",
"uid": "63b9a445-168e-42fc-aa75-0a6a1727d946",
"default": "0",
"required": false,
"multi": false,
"parameter_type": "select",
"variable": "command",
"parameter": true,
"order": 1,
"description": "Select what kind of command should this widget produce. "
"description": ""
}
},
{
"pk": 369,
"pk": 856,
"model": "workflows.abstractinput",
"fields": {
"widget": 200,
"widget": 341,
"name": "Limit",
"short_name": "lmt",
"uid": "f2f57d32-f073-45f0-8ae5-4af444b3baa2",
"uid": "594b1488-dadb-4c9e-9a73-4c2ebed10a9d",
"default": "",
"required": false,
"multi": false,
"parameter_type": "text",
"variable": "limit",
"parameter": true,
"order": 2,
"description": "This input influences how much results we want returned."
"order": 1,
"description": "Input must be a number. This input influences how much results we want returned."
}
},
{
"pk": 370,
"pk": 857,
"model": "workflows.abstractinput",
"fields": {
"widget": 200,
"widget": 341,
"name": "Offset",
"short_name": "off",
"uid": "0fc7dac3-4953-4b21-82e5-b43e81ed2c1e",
"uid": "6fef5306-e341-4794-a1c0-57c6a74c15e0",
"default": "",
"required": false,
"multi": false,
"parameter_type": "text",
"variable": "offset",
"parameter": true,
"order": 3,
"description": "This input influences how many inputs we should skip in the beginning."
}
},
{
"pk": 208,
"model": "workflows.abstractoutput",
"fields": {
"widget": 200,
"name": "Query",
"short_name": "que",
"variable": "query",
"uid": "b16f8846-f296-4400-9bbe-670679dd6ff3",
"order": 1,
"description": "Query that you can input in widget \"Query to JSON\""
}
},
{
"pk": 201,
"model": "workflows.abstractwidget",
"fields": {
"category": 40,
"treeview_image": "",
"windows_queue": false,
"name": "Create Lookup Query",
"is_streaming": false,
"uid": "003fb477-4a50-4083-a7f6-f8dcdfb726dc",
"interaction_view": "",
"image": "",
"package": "conceptnet",
"static_image": "",
"post_interact_action": "",
"user": null,
"visualization_view": "",
"streaming_visualization_view": "",
"action": "create_lookup_query",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
"has_progress_bar": false,
"order": 1,
"description": ""
"order": 2,
"description": "Input must be a number. This input influences how many inputs we should skip in the beginning."
}
},
{
"pk": 371,
"pk": 858,
"model": "workflows.abstractinput",
"fields": {
"widget": 201,
"name": "Limit",
"short_name": "lmt",
"uid": "ab419ad5-bdd8-46e5-ae4f-be26a94a5cc7",
"widget": 341,
"name": "Text",
"short_name": "txt",
"uid": "29a4d41b-1361-4b20-b3b2-9ecbab156ca4",
"default": "",
"required": false,
"multi": false,
"parameter_type": "text",
"variable": "limit",
"variable": "text",
"parameter": true,
"order": 1,
"description": "This input influences how much results we want returned."
"order": 3,
"description": "Searches for data that contain this word in this field. Do not use sentences, write only a single word."
}
},
{
"pk": 372,
"pk": 859,
"model": "workflows.abstractinput",
"fields": {
"widget": 201,
"name": "Offset",
"short_name": "off",
"uid": "c8fcd7e0-f4bf-4b85-84ea-4914ce95b411",
"widget": 341,
"name": "MinWeight",
"short_name": "wgt",
"uid": "2d591bb7-6838-4f0b-8cdc-1d6ed5bfd0d7",
"default": "",
"required": false,
"multi": false,
"parameter_type": "text",
"variable": "offset",
"variable": "minweight",
"parameter": true,
"order": 2,
"description": "This input influences how many inputs we should skip in the beginning."
"order": 4,
"description": "Input must be an integer or double. Filters for edges whose weight is at least weight."
}
},
{
"pk": 209,
"pk": 368,
"model": "workflows.abstractoutput",
"fields": {
"widget": 201,
"widget": 341,
"name": "Query",
"short_name": "que",
"variable": "query",
"uid": "8356b05d-cca7-41db-a0b2-432b4cd0f515",
"uid": "7f4009fb-96c5-498c-9604-3c91a75e1322",
"order": 1,
"description": "Query that you can input in widget \"Query to JSON\""
}
},
{
"pk": 202,
"pk": 342,
"model": "workflows.abstractwidget",
"fields": {
"category": 40,
"category": 63,
"treeview_image": "",
"windows_queue": false,
"name": "Create Search Query",
"name": "Conceptnet Execute Query",
"is_streaming": false,
"uid": "e2359c29-f2bc-4cc5-92b2-5d32f9a26de3",
"uid": "1baeaa93-6b32-4fbb-89c0-98a04c381328",
"interaction_view": "",
"image": "",
"package": "conceptnet",
......@@ -199,7 +141,7 @@
"user": null,
"visualization_view": "",
"streaming_visualization_view": "",
"action": "create_search_query",
"action": "conceptnet_execute_query",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
......@@ -209,100 +151,46 @@
}
},
{
"pk": 373,
"pk": 860,
"model": "workflows.abstractinput",
"fields": {
"widget": 202,
"name": "Limit",
"short_name": "lmt",
"uid": "594b1488-dadb-4c9e-9a73-4c2ebed10a9d",
"widget": 342,
"name": "query",
"short_name": "str",
"uid": "c7f7da84-266c-4fe2-8e08-84ffe7e7a126",
"default": "",
"required": false,
"required": true,
"multi": false,
"parameter_type": "text",
"variable": "limit",
"parameter": true,
"parameter_type": null,
"variable": "query",
"parameter": false,
"order": 1,
"description": "Input must be a number. This input influences how much results we want returned."
}
},
{
"pk": 374,
"model": "workflows.abstractinput",
"fields": {
"widget": 202,
"name": "Offset",
"short_name": "off",
"uid": "6fef5306-e341-4794-a1c0-57c6a74c15e0",
"default": "",
"required": false,
"multi": false,
"parameter_type": "text",
"variable": "offset",
"parameter": true,
"order": 2,
"description": "Input must be a number. This input influences how many inputs we should skip in the beginning."
}
},
{
"pk": 375,
"model": "workflows.abstractinput",
"fields": {
"widget": 202,
"name": "Text",
"short_name": "txt",
"uid": "29a4d41b-1361-4b20-b3b2-9ecbab156ca4",
"default": "",
"required": false,
"multi": false,
"parameter_type": "text",
"variable": "text",
"parameter": true,
"order": 3,
"description": "Searches for data that contain this word in this field. Do not use sentences, write only a single word."
}
},
{
"pk": 376,
"model": "workflows.abstractinput",
"fields": {
"widget": 202,
"name": "MinWeight",
"short_name": "wgt",
"uid": "2d591bb7-6838-4f0b-8cdc-1d6ed5bfd0d7",
"default": "",
"required": false,
"multi": false,
"parameter_type": "text",
"variable": "minweight",
"parameter": true,
"order": 4,
"description": "Input must be an integer or double. Filters for edges whose weight is at least weight."
"description": ""
}
},
{
"pk": 210,
"pk": 369,
"model": "workflows.abstractoutput",
"fields": {
"widget": 202,
"name": "Query",
"short_name": "que",
"variable": "query",
"uid": "7f4009fb-96c5-498c-9604-3c91a75e1322",
"widget": 342,
"name": "json",
"short_name": "str",
"variable": "json",
"uid": "b62150ba-c796-46cd-988b-d4bfd3b1d0a2",
"order": 1,
"description": "Query that you can input in widget \"Query to JSON\""
"description": ""
}
},
{
"pk": 38,
"pk": 343,
"model": "workflows.abstractwidget",
"fields": {
"category": 40,
"category": 63,
"treeview_image": "",
"windows_queue": false,
"name": "Query to JSON",
"name": "Conceptnet Get Triplets",
"is_streaming": false,
"uid": "1baeaa93-6b32-4fbb-89c0-98a04c381328",
"uid": "bec0c1ac-59d4-4b1d-95d3-5e826f896b0e",
"interaction_view": "",
"image": "",
"package": "conceptnet",
......@@ -311,7 +199,7 @@
"user": null,
"visualization_view": "",
"streaming_visualization_view": "",
"action": "query_to_json",
"action": "concept_net_triplets",
"wsdl_method": "",
"wsdl": "",
"interactive": false,
......@@ -321,34 +209,47 @@
}
},
{
"pk": 55,
"pk": 861,
"model": "workflows.abstractinput",
"fields": {
"widget": 38,
"name": "query",
"short_name": "str",
"uid": "c7f7da84-266c-4fe2-8e08-84ffe7e7a126",
"widget": 343,
"name": "concept_net_json_response",
"short_name": "jsn",
"uid": "fc379a4b-e1d7-4a71-9d5d-7d7879ba6fc8",
"default": "",
"required": true,
"multi": false,
"parameter_type": null,
"variable": "query",
"variable": "concept_net_json_response",
"parameter": false,
"order": 1,
"description": ""
"description": "Conceptnet JSON response"
}
},
{
"pk": 34,
"pk": 370,
"model": "workflows.abstractoutput",
"fields": {
"widget": 38,
"name": "json",
"short_name": "str",
"variable": "json",
"uid": "b62150ba-c796-46cd-988b-d4bfd3b1d0a2",
"widget": 343,
"name": "triplets",
"short_name": "tri",
"variable": "triplets",
"uid": "6fbf2ad3-8c9e-4b99-baa4-1a8519533454",
"order": 1,
"description": ""
"description": "Triplets: subject, predicate, object"
}
},
{
"pk": 371,
"model": "workflows.abstractoutput",
"fields": {
"widget": 343,
"name": "triplets without prefixes",
"short_name": "trc",
"variable": "basename_triplets",
"uid": "f62999b0-9420-4fe6-a1dd-8e18c9ac4aed",
"order": 1,
"description": "Triplets: subject, predicate, object without conceptnet prefixes"
}
}
]
\ No newline at end of file
from django.shortcuts import render
def conceptnet_filter_integers(request,input_dict,output_dict,widget):
return render(request, 'interactions/conceptnet_filter_integers.html',{'widget':widget,'intList':input_dict['intList']})
\ No newline at end of file
......@@ -2,104 +2,30 @@ import re
import json
import sys
def conceptnet_create_integers(input_dict):
intStr = input_dict['intStr']
intList = []
for i in re.findall(r'\w+', intStr):
try:
intList.append(int(i))
except:
pass
if input_dict['sort'].lower() == "true":
intList.sort()
return {'intList':intList}
def conceptnet_sum_integers(input_dict):
intList = input_dict['intList']
return {'sum':sum(intList)}
def conceptnet_pre_filter_integers(input_dict):
return input_dict
def conceptnet_post_filter_integers(postdata,input_dict,output_dict):
intListOut = postdata['intListOut']
intList = []
for i in intListOut:
try:
intList.append(int(i))
except:
pass
return {'intList': intList}
def conceptnet_pre_display_summation(input_dict):
return {}
def createBlaString():
return "bla";
import hashlib
def hash_it(input_dict):
output_dict = {}
output_dict["output1"] = hashlib.sha256(input_dict["input1"]).hexdigest()
output_dict["numLoop"] = input_dict["numLoop"]
for i in range(1,input_dict["numLoop"]):
output_dict["output1"] = hashlib.sha256(output_dict["output1"]).hexdigest();
return output_dict
def query_to_json(input_dict):
import urllib2, json
site = "http://conceptnet5.media.mit.edu/data/5.2/"+input_dict["query"];
output_dict = {}
def conceptnet_execute_query(input_dict):
"""
Executes the input Conceptnet query.
"""
import urllib2
site = "http://conceptnet5.media.mit.edu/data/5.2/" + input_dict["query"]
response = urllib2.urlopen(site)
json_file = response.read();
js = json.loads(json_file);
output_dict["json"] = js;
return output_dict;
def create_conceptnet_query(input_dict):
print "create_conceptnet_query"
input_command = input_dict['command']
input_limit = input_dict['limit']
input_offset = input_dict['offset']
query = "c/en/"+ input_command +"?offset="+str(input_limit)+"&limit="+str(input_offset)
output_dict["query"] = query;
return output_dict;
def create_lookup_query(input_dict):
print "create_lookup_query"
input_limit = input_dict['limit']
input_offset = input_dict['offset']
query = "c/en/toast?"
if input_limit != None and input_limit != '':
query = query + 'limit=' + str(input_limit) + '&'
if input_offset != None and input_offset != '':
query = query + 'offset=' + str(input_offset) + '&'
output_dict = {}
output_dict["query"] = query[0:len(query)-1]
return output_dict;
output_dict["json"] = response.read()
return output_dict
def create_search_query(input_dict):
print "create_conceptnet_query"
def conceptnet_create_search_query(input_dict):
"""
Constructs a Conceptnet search query.
"""
input_limit = input_dict['limit']
input_offset = input_dict['offset']
input_text= input_dict['text']
input_text = input_dict['text']
input_minweight = input_dict['minweight']
query = "c/en/search?"
query = "search?"
if input_limit != None and input_limit != '':
query = query + 'limit=' + str(input_limit) + '&'
......@@ -110,34 +36,31 @@ def create_search_query(input_dict):
if input_minweight != None and input_minweight != '':
query = query + 'minWeight=' + str(input_minweight) + '&'
output_dict = {}
#query = "5.2/c/en/search?offset="+str(input_limit)+"&limit="+str(input_offset)
output_dict["query"] = query[0:len(query)-1];
return output_dict;
def create_association_query(input_dict):
print "create_conceptnet_query"
input_command = input_dict['command']
input_limit = input_dict['limit']
input_offset = input_dict['offset']
query = "c/en/"+ input_command +"?offset="+str(input_limit)+"&limit="+str(input_offset)
output_dict["query"] = query;
output_dict["query"] = query[0:len(query)-1]
return output_dict
return output_dict;
def concept_net_triplets(input_dict):
"""
Extracts Subject, Predicate, Object triplets from the Conceptnet response JSON.
"""
json_response = input_dict['concept_net_json_response']
try:
data = json.loads(json_response)
triplets = [[e['start'], e['rel'], e['end']] for e in data['edges']]
except:
raise Exception("Cannot parse this JSON string. Is it a proper Conceptnet API response JSON?")
# Make a separate triplet list without conceptnet prefixes
basename_triplets = []
for start, rel, end in triplets:
start = start.split('/')[-1]
rel = rel.split('/')[-1]
end = end.split('/')[-1]
basename_triplets.append([start, rel, end])
def create_integer_list(input_dict):
import re
intStr = input_dict['intStr']
intList = []
for i in re.findall(r'\w+', intStr):
try:
intList.append(int(i))
except:
pass
if input_dict['sort'].lower() == "true":
intList.sort()
return {'intList':intList}
\ No newline at end of file
output_dict = {}
output_dict['triplets'] = json.dumps(triplets, indent=2)
output_dict['basename_triplets'] = json.dumps(basename_triplets, indent=2)
return output_dict