我尝试使用python sparql-client 3.6查询给定类的超类。使用以下代码片段
dbo_prefix = 'http://dbpedia.org/ontology/'
_class = 'PoliticalParty'
s = sparql.Service('http://dbpedia.org/sparql', "utf-8", "GET")
statement = 'SELECT distinct ?superclass WHERE { dbo:%s rdfs:subClassOf* ?superclass. ' \
'FILTER (strstarts(str(?superclass), "%s"))}' % (_class, dbo_prefix)
print(statement)
result = s.query(statement)
for row in result.fetchone():
print(row)
但是它像下面的StackTrace一样崩溃。我调试了代码,发现在lib(sparql.py)内部,它将类型从str转换为字节,然后在发送查询之前崩溃。
我直接在endpoint处尝试了生成的查询,它正确地检索了结果。
我有完全相同的问题。
我尝试过v3.5和v3.4。 v3.5出现了同样的问题,而v3.4不支持python3,所以我没有感到那么遥远。
我已经在项目的GitHub上打开了一个问题。