我有以下代码用于打印整个本体.但是,我如何用它执行一些sparql,查询然后打印生成的图形?
g = Graph()
g.parse('PLAYERS3.owl')
for s,p,o in g:
print s
谢谢
解决方法:
这段代码可以解决这个问题:
import rdflib
from rdflib import Graph
rdflib.plugin.register('sparql', rdflib.query.Processor,
'rdfextras.sparql.processor', 'Processor')
rdflib.plugin.register('sparql', rdflib.query.Result,
'rdfextras.sparql.query', 'SPARQLQueryResult')
g = Graph()
g.parse('PLAYERS3.owl')
query = """
SELECT * WHERE {
?s ?p ?o .
}
"""
for row in g.query(query):
print row