Skip to content

Instantly share code, notes, and snippets.

@kordless
Created September 28, 2018 16:51
Show Gist options
  • Save kordless/e1401e6a8dd120a16da4adef9df55732 to your computer and use it in GitHub Desktop.
Save kordless/e1401e6a8dd120a16da4adef9df55732 to your computer and use it in GitHub Desktop.
SKG Query for Fusion
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']:
print
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