SPARQL native engine: syntax error in SQL translation

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

SPARQL native engine: syntax error in SQL translation

Patzy
Hello,

I'm trying to use OWLReady2 with SPARQL queries but while some queries are properly translated to SQL but I have a problem with the following one:
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    PREFIX owl: <http://www.w3.org/2002/07/owl#>
    PREFIX domain: <http://diana/camrest.owl#>
    SELECT ?name ?address ?area ?food ?phone ?pricerange ?postcode ?signature ?description WHERE {
    VALUES ?name {<http://diana/camrest.owl#the%20nirala>}.
    OPTIONAL {<http://diana/camrest.owl#the%20nirala> domain:address ?address.}
    OPTIONAL {<http://diana/camrest.owl#the%20nirala> domain:area ?area.}
    OPTIONAL {<http://diana/camrest.owl#the%20nirala> domain:food ?food.}
    OPTIONAL {<http://diana/camrest.owl#the%20nirala> domain:phone ?phone.}
    OPTIONAL {<http://diana/camrest.owl#the%20nirala> domain:pricerange ?pricerange.}
    OPTIONAL {<http://diana/camrest.owl#the%20nirala> domain:postcode ?postcode.}
    OPTIONAL {<http://diana/camrest.owl#the%20nirala> domain:signature ?signature.}
    OPTIONAL {<http://diana/camrest.owl#the%20nirala> domain:description ?description.}
    }

It is apparently translated to this:
SELECT IN (360), q1.o, q1.d, q2.o, q3.o, q4.o, q4.d, q5.o, q6.o, q6.d, q7.o, q7.d, q8.o, q8.d FROM datas q1 ON (q1.s=360 AND q1.p=314) LEFT JOIN objs q2 ON (q2.s=360 AND q2.p=308) LEFT JOIN objs q3 ON (q3.s=360 AND q3.p=303) LEFT JOIN datas q4 ON (q4.s=360 AND q4.p=316) LEFT JOIN objs q5 ON (q5.s=360 AND q5.p=306) LEFT JOIN datas q6 ON (q6.s=360 AND q6.p=317) LEFT JOIN datas q7 ON (q7.s=360 AND q7.p=318) LEFT JOIN datas q8 ON (q8.s=360 AND q8.p=315)

Which generates the following error:
Traceback (most recent call last):
  File "test_owlready.py", line 88, in <module>
    print(list(r))
  File "/home/m0rg/orange/dialog-platform/poc-rdf/env/lib/python3.7/site-packages/owlready2/sparql/main.py", line 335, in execute
    for l in PreparedQuery.execute(self, params):
  File "/home/m0rg/orange/dialog-platform/poc-rdf/env/lib/python3.7/site-packages/owlready2/sparql/main.py", line 331, in execute
    return self.world.graph.execute(self.sql, sql_params)
sqlite3.OperationalError: near "IN": syntax error

Note that the concerned query is working with rdflib.
I'm using owlready 0.36 on python3.7, any idea of what may cause the problem ?
Reply | Threaded
Open this post in threaded view
|

Re: SPARQL native engine: syntax error in SQL translation

Jiba
Administrator
Hi,

I took a lot of time, but I finally solved the problem, which was related to the combined use of OPTIONAL with VALUES. It should now work well with the development version of Owlready!

Note that, in your query, you may prefer to use ?name instead of repeating <http://diana/camrest.owl#the%20nirala> in each OPTIONAL clause.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: SPARQL native engine: syntax error in SQL translation

Patzy
Thank you !

I'll test this.

I know about ?name but the query is auto-generated with some ugly code at the moment, sometimes ?name is not part of it.