-
Notifications
You must be signed in to change notification settings - Fork 0
/
QueryProcesser.py
48 lines (40 loc) · 1.51 KB
/
QueryProcesser.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import rdflib, json
def myQuery(q, onto_file):
g = rdflib.Graph()
g.load(onto_file)
rows = g.query(q)
j = rows.serialize(format="json")
JSON = json.loads(j)
columns = JSON['head']['vars']
columnLength = len(columns)
results = JSON['results']['bindings']
resultLength = len(results)
print 'Result Length:',resultLength
result=''
result += '\t\t'.join(columns)+'\n'+'------------------\n'
for i in range(resultLength):
for attribute in columns:
try:
result+=results[i][attribute]['value'].split('#')[1]+'\t\t'
except:
pass
result+='\n'
print 'Answer to Query : ',result
return result
# onto_file = "temp_ontology.owl"
# q = """ PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
# PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
# #PREFIX : <http://www.semanticweb.org/axat/ontologies/2016/9/skill#>
# PREFIX : <http://www.semanticweb.org/axat/ontologies/2016/9/untitled-ontology-37#>
# PREFIX owl: <http://www.w3.org/2002/07/owl#>
# select * where {
# ?class a owl:Class; rdfs:subClassOf ?superclass .
#
# # FILTER ( ?class in (:android,:java, :spring,:spring-mvc,:hibernate) )
# # FILTER ( ?superclass in (:android,:java, :spring,:spring-mvc,:hibernate) && ?superclass != ?class)
#
# FILTER ( ?class in (:android,:java, :spring,:spring-mvc,:hibernate) )
# FILTER ( ?superclass in (:android,:java, :spring,:spring-mvc,:hibernate) && ?superclass != ?class)
# }"""
#
# js = myQuery(q, onto_file)