This is What I wrote after importing rdflib and my owl data. I wrote 3 query part, and I couldnt take any answer from all.
*
PREFIX : "<http://xmlns.com/foaf/0.1/>"
g = Graph()
g.bind("foaf", FOAF)
First one:
qres = g.query(
"""SELECT DISTINCT ?Name ?Microsoft
WHERE {
?a foaf:subclassof ?Microsoft .
?a foaf:Name ?Name .
?b foaf:Microsoft ?Microsoft .
}""")
for row in qres:
print("%s subclassof %s" % row)
from rdflib.namespace import FOAF
Second One:
qres = g.query('SELECT * WHERE { ?p a foaf:Engineers}', initNs={ 'foaf': FOAF })
for row in qres:
print("%s" % row)
Third One:
qres = g.query(
"""SELECT DISTINCT ?aName ?bOracle
WHERE {
?a foaf:individual_of ?b .
?a foaf:Name ?aName.
?b foaf:Oracle ?bOracle .
}""")
for row in qres:
print("%s individual_of %s" % row)
question from:
https://stackoverflow.com/questions/65874749/i-am-trying-to-query-my-ontology-which-i-created-on-protege-by-sparql-i-am-2-we 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…