debugging - RDflib results printing error on windows7 -


i use sparqlwrapper create sparql queries, don't know how debug following error message:

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__' 

this code:

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  { ?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:   result in results["results"]["bindings"]:      print result["wordtext"]["value"] 

any help?

the return format not json, setreturnformat call not working expected:

encode return value depending on return format:

  • in case of xml, dom top element returned;
  • in case of json, simplejson conversion return dictionary;
  • in case of rdf/xml, value converted via rdflib graph instance.

in other cases input returned.


Comments