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
This diff is collapsed.
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
from django.shortcuts import render
def conceptnet_display_summation(request,input_dict,output_dict,widget):
if sum(input_dict['intList']) == input_dict['sum']:
check = 'The calculation appears correct.'
else:
check = 'The calculation appears incorrect!'
return render(request, 'visualizations/conceptnet_display_integers.html',{'widget':widget,'input_dict':input_dict, 'output_dict':output_dict, 'check':check})
......@@ -750,109 +750,15 @@ def example_distance_post(postdata, input_dict, output_dict):
return{}
def createBlaString():
return "bla";
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 = {}
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;
def create_search_query(input_dict):
print "create_conceptnet_query"
input_limit = input_dict['limit']
input_offset = input_dict['offset']
input_text= input_dict['text']
input_minweight = input_dict['minweight']
query = "c/en/search?"
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) + '&'
if input_text != None and input_text != '':
query = query + 'text=' + str(input_text) + '&'
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;
return output_dict;
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["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
\ No newline at end of file
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