0

I'm working with SPARQLWrapper and I'm following the documentation. Here is my code:

queryString = "SELECT * WHERE { ?s ?p ?o. }"

sparql = SPARQLWrapper("http://example.org/sparql")# I replaced this line with 
sparql = SPARQLWrapper("file:///thelocation of my file in my computer")

sparql.setQuery(queryString)

try :
   ret = sparql.query()
   # ret is a stream with the results in XML, see <http://www.w3.org/TR/rdf-sparql-XMLres/>
except :
   deal_with_the_exception()  

I'm getting these 2 errors: 1- The system cannot find the path specified 2- NameError: name 'deal_with_the_exception' is not defined

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
kamel berkani
  • 57
  • 1
  • 6
  • 1
    for a local file you should not use SPARQLWrapper but core `rdflib` SPARQL support, i.e. you load the file and then do https://rdflib.readthedocs.io/en/stable/intro_to_sparql.html – UninformedUser Jun 10 '20 at 07:16
  • thank you for your answer, I will try it. – kamel berkani Jun 10 '20 at 11:24
  • is it possible to use rdflib for an owl ontology ? – kamel berkani Jun 10 '20 at 12:13
  • 1
    why should it not? As long as you have the file in any serialization that rdflib can read and if you still want to use SPARQL (which is a query language for RDF), sure - yes. Another Python lib working on the OWL level (axioms, class expressions, etc. ) is `owlready2` – UninformedUser Jun 10 '20 at 12:53

1 Answers1

1

You need a SPARQL endpoint to make it work. Consider setting up Apache Fuseki in your local computer. See https://jena.apache.org/documentation/fuseki2/jena

Koenig Lear
  • 2,366
  • 1
  • 14
  • 29
  • 1
    well, or just use the in-memory SPARQL support of `rdflib`: https://rdflib.readthedocs.io/en/stable/intro_to_sparql.html - I mean, SPARQLWrapper is nothing more than remote SPARQL endpoint support for `rdflib` – UninformedUser Jun 10 '20 at 06:44