1

I tried to query the super classes for a given class using python sparql-client 3.6. Using the following code snippet

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)

But it crashes as in the StackTrace below. I debugged the code and I found inside the lib (sparql.py) it converted the type from str to bytes then it crashes before sending the query. enter image description here

I tried the generated query directly at the endpoint and it retrieved the results correctly.

1
  • use SPARQLWrapper if this API doesn't work, or contact the devs Mar 24, 2020 at 15:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.