Created
September 28, 2018 16:51
-
-
Save kordless/e1401e6a8dd120a16da4adef9df55732 to your computer and use it in GitHub Desktop.
SKG Query for Fusion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import urllib2 | |
import sys | |
try: | |
ip = "35.xxx.xxx.xxx" | |
except: | |
print "need an IP" | |
print "usage: python skg-query.py <ip> '<query>'" | |
sys.exit() | |
try: | |
query = "%s" % sys.argv[1] | |
except: | |
query = "consciousness" | |
print "usage: python skg-query.py <ip> '<query>'" | |
qf = "body_t" | |
jsondata = """ | |
{ | |
"queries" : ["%s"], | |
"compare" : [ | |
{ | |
"type": "%s", | |
"sort": "relatedness", | |
"limit": 160, | |
"compare" : [ | |
{ | |
"type": "%s", | |
"sort": "relatedness", | |
"limit": 80 | |
} | |
] | |
} | |
] | |
} | |
""" % (query, qf, qf) | |
req = urllib2.Request('http://%s:8983/solr/Semantic_Knowledge_Graph/skg?qf=%s' % (ip, qf)) | |
req.add_header('Content-Type', 'application/json') | |
response = urllib2.urlopen(req,jsondata) | |
x = response.read() | |
x = json.loads(x) | |
oldone = 0.0 | |
for y in x['data']: | |
print "---------------" | |
print y['type'] | |
print "---------------" | |
for z in y['values']: | |
try: | |
print z['name'] | |
except: | |
print 'name threw error*********' | |
print "---------------" | |
for a in z['compare']: | |
for b in a['values']: | |
if b['relatedness'] > 0.0: | |
try: | |
foo = int(b['name'][0]) | |
except: | |
if oldone != b['relatedness']: | |
print "--" | |
try: | |
oldone = b['relatedness'] | |
print b['name'], b['relatedness'] | |
except: | |
print 'name threw error*********' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment