-
Notifications
You must be signed in to change notification settings - Fork 0
/
SparqlResults.py
28 lines (22 loc) · 1.03 KB
/
SparqlResults.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class SparqlResults:
@staticmethod
def getEntitySetFromBindings(results):
"""
:param results: {'head': {'vars': ['x']}, 'results':
{'bindings': [{'x': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q155'}},
{'x': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q159'}},
{'x': {'type': 'uri', 'value': 'http://www.wikidata.org/entity/Q183'}}]}}
:return: {'x': [Q155, Q159, Q183]}
:param results: {'head': {}, 'boolean': False}
:return: {'boolean': False}
"""
if 'boolean' in results.keys():
return {'boolean': results['boolean']}
else:
varBindings = {}
for var in results['head']['vars']: # we expect to find one variable...!?
varBindings[var] = []
for bin in results['results']['bindings']:
if var in bin.keys():
varBindings[var].append(bin[var]['value'].split('/')[-1])
return varBindings