1

我有以下 SPARQL 查询:

SELECT ?s ?p ?o
WHERE {
?sbj ?p ?obj .
?sbj (<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>/<http://www.w3.org/2000/01/rdf-schema#subClassOf>+) <http://www.my.org/ontology.owl#Place> .
?sbj rdfs:label ?s .
?obj rdfs:label ?o .
}

它利用了为 SPARQL 1.1 定义的属性路径。

我正在尝试使用 rdflib 3.4.0 处理此查询,但收到以下异常消息:

rayman@hal9100 ~/projects/scripts $ python places_owl2json.py 
Traceback (most recent call last):
  File "places_owl2json.py", line 107, in <module>
    """)
  File "/usr/local/lib/python2.7/dist-packages/rdflib/graph.py", line 1007, in query
    query_object, initBindings, initNs, **kwargs))
  File "/usr/local/lib/python2.7/dist-packages/rdfextras/sparql/processor.py", line 49, in query
    loadContexts=loadContexts)
  File "/usr/local/lib/python2.7/dist-packages/rdfextras/sparql/algebra.py", line 406, in TopEvaluate
    assert isinstance(expr,AlgebraExpression), repr(expr)
AssertionError: None

有什么问题?谢谢,

里卡多

4

1 回答 1

0

这似乎是 rdflib 3.4.0 中的一个错误:我尝试在 rdflib 4.2.1-dev(当前版本)上重现该错误,它似乎可以使用以下代码:

In [1]: from rdflib import *
INFO:rdflib:RDFLib Version: 4.2.1-dev

In [2]: g = Graph()

In [3]: g.query('''
   ...: SELECT ?s ?p ?o
   ...: WHERE {
   ...: ?sbj ?p ?obj .
   ...: ?sbj (<http://www.w3.org/1999/02/22-rdf-syntax-ns#type>/<http://www.w3.org/2000/01/rdf-schema#subClassOf>+) <http://www.my.org/ontology.owl#Place> .
   ...: ?sbj rdfs:label ?s .
   ...: ?obj rdfs:label ?o .
   ...: }
   ...: ''')
Out[3]: <rdflib.plugins.sparql.processor.SPARQLResult at 0x1111dc410>
于 2015-03-25T13:32:31.567 回答