我使用 SPARQLWrapper 创建 SPARQL 查询,但我不知道如何调试以下错误消息:
Warning (from warnings module):
File "D:\Python27\lib\site-packages\sparqlwrapper-1.5.2-py2.7.egg\SPARQLWrapper\Wrapper.py", line 550
RuntimeWarning: unknown response content type, returning raw response...
Traceback (most recent call last):
File "D:\Python27\testwrapper.py", line 31, in <module>
if (len(results["results"]["bindings"]) == 0):
AttributeError: addinfourl instance has no attribute '__getitem__'
这是我的代码:
from SPARQLWrapper import SPARQLWrapper,JSON
sparql = SPARQLWrapper('http://thedatahub.org/dataset/semanticquran');
queryString = """
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX olia-ar: <http://purl.org/olia/arabic_khoja.owl#>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX lexvo: <http://lexvo.org/id/iso639-3/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX gold: <http://purl.org/linguistics/gold/>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX qvoc: <http://www.nlp2rdf.org/quranvocab#>
SELECT DISTINCT ?wordText ?pos
WHERE
{ ?wordPart rdf:type qvoc:LexicalItem .
?wordPart gold:Root "smw" .
?wordPart dcterms:isPartOf ?word .
?wordPart gold:PartOfSpeechProperty ?pos .
?word rdf:type qvoc:Word .
?word skos:prefLabel ?wordText
}
"""
sparql.setQuery(queryString)
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
if (len(results["results"]["bindings"]) == 0):
print "No results found."
else:
for result in results["results"]["bindings"]:
print result["wordText"]["value"]
有什么帮助吗?