I had a quick look at the SPARQL 1.1 Federated Query W3C specification document and understand that the only way to use in the remote SPARLQ services, variables that are bound in the local SPARQL query Is to use a VALUES clause (https://www.w3.org/TR/sparql11-federated-query/#values). Unfortunately, there is no example in that document on how to use it, and in the examples I found on the net, the VALUE clause is used to bind variables to fully instantiated IRI or literals in the query, whereas in my case, these variables will be instantiated by processing local subqueries (as my "target" query in my previous mail suggests). Any workaround?
Orange Restricted -----Message d'origine----- De : RAMPARANY Fano INNOV/IT-S Envoyé : mardi 29 août 2023 10:58 À : [email protected] Objet : RE: Problem with federated queries Thank you for pointing us reason of the issue. However, it seems that introducing the subquery first doesn't seem to work either. I slightly modified the query you suggested to: PREFIX wd: <http://www.wikidata.org/entity/> PREFIX owl: <http://www.w3.org/2002/07/owl#> PREFIX ex: <http://example/> PREFIX wdt: <http://www.wikidata.org/prop/direct/> PREFIX geof: <http://www.opengis.net/def/geosparql/function/> SELECT * WHERE { { SELECT ?ParisWDID ?BordeauxWDID WHERE { BIND (wd:Q90 AS ?ParisWDID) BIND (wd:Q1479 AS ?BordeauxWDID) } } SERVICE <https://query.wikidata.org/sparql> { ?ParisWDID wdt:P625 ?ParisLoc . ?BordeauxWDID wdt:P625 ?BordeauxLoc . BIND(geof:distance(?ParisLoc,?BordeauxLoc) AS ?dist) } } Because the variables ?ParisWDID and ?BordeauxWDID should hold the Wikidata identifiers. But the target query should be: PREFIX wd: <http://www.wikidata.org/entity/> PREFIX owl: <http://www.w3.org/2002/07/owl#> PREFIX ex: <http://example/> PREFIX wdt: <http://www.wikidata.org/prop/direct/> PREFIX geof: <http://www.opengis.net/def/geosparql/function/> SELECT * WHERE { { SELECT ?ParisWDID ?BordeauxWDID WHERE { ?ParisWDID owl:sameAs ex:Paris . ?BordeauxWDID owl:sameAs ex:Bordeaux . } } SERVICE <https://query.wikidata.org/sparql> { ?ParisWDID wdt:P625 ?ParisLoc . ?BordeauxWDID wdt:P625 ?BordeauxLoc . BIND(geof:distance(?ParisLoc,?BordeauxLoc) AS ?dist) } } As these identifiers are defined in the RDF graph and are not supposed to be known when building the query. Unfortunately, although they use subqueries, none of the two queries work. The error persists ☹ Fano Orange Restricted -----Message d'origine----- De : Thomas Francart <[email protected]> Envoyé : lundi 28 août 2023 18:26 À : [email protected] Objet : Re: Problem with federated queries One typical problem is that the federated query might be executed *before* the rest of the query. So when you write SERVICE https://query.wikidata.org/sparql { ?ParisWDID wdt:P625 ?ParisLoc . ?BordeauxWDID wdt:P625 ?BordeauxLoc . BIND(geof:distance(?ParisLoc,?BordeauxLoc) AS ?dist) } Then that part is sent to Wikidata *without any bindings of the variables*, which is basically asking wikidata to return the distance between *all* pairs of entities in the database, resulting in a timeout. And this is why your second query works. If you want to guarantee ordering of execution, use a subquery, which is logically executed first : PREFIX wd: http://www.wikidata.org/entity/ PREFIX owl: http://www.w3.org/2002/07/owl# PREFIX ex: http://example/ PREFIX wdt: http://www.wikidata.org/prop/direct/ PREFIX geof: http://www.opengis.net/def/geosparql/function/ SELECT * WHERE { { SELECT ?ParisWDID ?BordeauxWDID WHERE { BIND(ex:Paris AS ?ParisWDID ) BIND(ex:Bordeaux AS ?BordeauxWDID ) } } ?ParisWDID owl:sameAs ex:Paris . ?BordeauxWDID owl:sameAs ex:Bordeaux . SERVICE https://query.wikidata.org/sparql { ?ParisWDID wdt:P625 ?ParisLoc . ?BordeauxWDID wdt:P625 ?BordeauxLoc . BIND(geof:distance(?ParisLoc,?BordeauxLoc) AS ?dist) } } (note : that typical query pattern is supported in Sparnatural SPARQL query builder, see http://docs.sparnatural.eu/Federated-querying.html#additionnal-experimental-config--executedafter ) Le lun. 28 août 2023 à 18:08, <[email protected]> a écrit : > > Hello, > > I've got a problem running this query on fuseki 4.9.0 (basically, I'd > like to delegate to Wikidata, the computation of the distance between > two > cities) : > > PREFIX wd: http://www.wikidata.org/entity/ PREFIX owl: > http://www.w3.org/2002/07/owl# PREFIX ex: http://example/ PREFIX wdt: > http://www.wikidata.org/prop/direct/ > PREFIX geof: http://www.opengis.net/def/geosparql/function/ > SELECT * > WHERE { > ?ParisWDID owl:sameAs ex:Paris . > ?BordeauxWDID owl:sameAs ex:Bordeaux . > SERVICE https://query.wikidata.org/sparql { > ?ParisWDID wdt:P625 ?ParisLoc . > ?BordeauxWDID wdt:P625 ?BordeauxLoc . > BIND(geof:distance(?ParisLoc,?BordeauxLoc) AS ?dist) > } > } > ____________ > Here is the content of my rdf graph: > > @prefix wd: http://www.wikidata.org/entity/ . > @prefix owl: http://www.w3.org/2002/07/owl# . > @prefix wdt: http://www.wikidata.org/prop/direct/ . > @prefix ex: http://example/ . > > wd:Q90 owl:sameAs ex:Paris . > > wd:Q1479 owl:sameAs ex:Bordeaux . > > ____________ > Here is the trace on the standard output: > > 17:44:59 INFO Fuseki :: [8] POST > http://localhost:3030/sparql/sparql > 17:44:59 INFO Fuseki :: [8] Query = PREFIX wd: > http://www.wikidata.org/entity/ PREFIX owl: > http://www.w3.org/2002/07/owl# PREFIX ex: http://example/ PREFIX wdt: > http://www.wikidata.org/prop/direct/ PREFIX geof: > http://www.opengis.net/def/geosparql/function/ SELECT * WHERE { > ?ParisWDID owl:sameAs ex:Paris . ?BordeauxWDID owl:sameAs ex:Bordeaux . > SERVICE https://query.wikidata.org/sparql { ?ParisWDID wdt:P625 > ?ParisLoc . ?BordeauxWDID wdt:P625 ?BordeauxLoc . > BIND(geof:distance(?ParisLoc,?BordeauxLoc) AS ?dist) } } > 17:46:08 WARN Fuseki :: [8] RC = 500 : > com.google.gson.stream.MalformedJsonException: Unterminated string at > line > 19922828 column 49 path $.results.bindings[855041].ParisLoc.value > org.apache.jena.sparql.resultset.ResultSetException: > com.google.gson.stream.MalformedJsonException: Unterminated string at > line > 19922828 column 49 path $.results.bindings[855041].ParisLoc.value > at > org.apache.jena.riot.rowset.rw.rs_json.RowSetJSONStreaming.moveToNext( > RowSetJSONStreaming.java:214) > ~[fuseki-server.jar:4.9.0] > at > org.apache.jena.riot.rowset.rw.rs_json.RowSetJSONStreaming.moveToNext( > RowSetJSONStreaming.java:66) > ~[fuseki-server.jar:4.9.0] > ... > at > org.apache.jena.riot.rowset.rw.rs_json.IteratorRsJSON.computeNextActua > l(IteratorRsJSON.java:136) > ~[fuseki-server.jar:4.9.0] > at > org.apache.jena.riot.rowset.rw.rs_json.IteratorRsJSON.moveToNext(Itera > torRsJSON.java:72) > ~[fuseki-server.jar:4.9.0] > at > org.apache.jena.atlas.iterator.IteratorSlotted.hasNext(IteratorSlotted > .java:63) > ~[fuseki-server.jar:4.9.0] > at > org.apache.jena.riot.rowset.rw.rs_json.RowSetJSONStreaming.computeNext > Actual(RowSetJSONStreaming.java:225) > ~[fuseki-server.jar:4.9.0] > at > org.apache.jena.riot.rowset.rw.rs_json.RowSetJSONStreaming.moveToNext( > RowSetJSONStreaming.java:210) > ~[fuseki-server.jar:4.9.0] > ... 112 more > 17:46:08 INFO Fuseki :: [8] 500 Server Error (68,499 s) > > ____________ > I verified that when replacing the variables ?ParisWDID and > ?BordeauxWDID with their values, the query is processed correctly. Thus this > query works: > > PREFIX wd: http://www.wikidata.org/entity/ PREFIX owl: > http://www.w3.org/2002/07/owl# PREFIX ex: http://example/ PREFIX wdt: > http://www.wikidata.org/prop/direct/ > PREFIX geof: http://www.opengis.net/def/geosparql/function/ > SELECT * > WHERE { > SERVICE https://query.wikidata.org/sparql { > wd:Q90 wdt:P625 ?ParisLoc . > wd:Q1479 wdt:P625 ?BordeauxLoc . > BIND(geof:distance(?ParisLoc,?BordeauxLoc) AS ?dist) } } > > ____________ > Thank you for any hint on what I did wrong > > Kind regards, > > Fano > > > > > Orange Restricted > > ______________________________________________________________________ > ______________________________________ > Ce message et ses pieces jointes peuvent contenir des informations > confidentielles ou privilegiees et ne doivent donc pas etre diffuses, > exploites ou copies sans autorisation. Si vous avez recu ce message > par erreur, veuillez le signaler a l'expediteur et le detruire ainsi > que les pieces jointes. Les messages electroniques etant susceptibles > d'alteration, Orange decline toute responsabilite si ce message a ete > altere, deforme ou falsifie. Merci. > > This message and its attachments may contain confidential or > privileged information that may be protected by law; they should not > be distributed, used or copied without authorisation. > If you have received this email in error, please notify the sender and > delete this message and its attachments. > As emails may be altered, Orange is not liable for messages that have > been modified, changed or falsified. > Thank you. > -- *Thomas Francart* -* SPARNA* Web de *données* | Architecture de l'*information* | Accès aux *connaissances* blog : blog.sparna.fr, site : sparna.fr, linkedin : fr.linkedin.com/in/thomasfrancart tel : +33 (0)6.71.11.25.97, skype : francartthomas ____________________________________________________________________________________________________________ Ce message et ses pieces jointes peuvent contenir des informations confidentielles ou privilegiees et ne doivent donc pas etre diffuses, exploites ou copies sans autorisation. Si vous avez recu ce message par erreur, veuillez le signaler a l'expediteur et le detruire ainsi que les pieces jointes. Les messages electroniques etant susceptibles d'alteration, Orange decline toute responsabilite si ce message a ete altere, deforme ou falsifie. Merci. This message and its attachments may contain confidential or privileged information that may be protected by law; they should not be distributed, used or copied without authorisation. If you have received this email in error, please notify the sender and delete this message and its attachments. As emails may be altered, Orange is not liable for messages that have been modified, changed or falsified. Thank you.
