w3c / sparql-dev

SPARQL dev Community Group
https://w3c.github.io/sparql-dev/
Other
124 stars 19 forks source link

LOAD with WHERE block #202

Open chiarcos opened 8 months ago

chiarcos commented 8 months ago

In order to call external web services from a SPARQL query, it would be helpful to be able to LOAD their results.

The example below shows how such a query could work. The WHERE block generates an access URL dynamically (based on the content in the current graph). The access URL contains a string (text=...) that is analysed by a web service (https://api.dbpedia-spotlight.org/en/annotate?...) and returns dynamically generated RDF data (try this url)

PREFIX nif: <http://persistence.uni-leipzig.org/nlp2rdf/ontologies/nif-core#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
LOAD ?access_uri
WHERE { 
  ?s  a nif:Sentence; rdfs:comment ?comments.
  BIND(replace(?comments,".*text\\s*=\\s*([^\n]*).*","$1") as ?text)
  BIND(URI(
      CONCAT(
         "https://api.dbpedia-spotlight.org/en/annotate?text=",
         ENCODE_FOR_URI(?text), 
         "&url=",str(?s))) as ?access_uri)
}

Notes:

PS: I know this is not in the core interest of the RDF-Star proposal, but it could be something to be considered in the process of developing SPARQL 1.2.

rubensworks commented 2 months ago

I suspect this won't be in-scope for the current WG. But you could consider opening this as an issue here, for consideration for a future WG: https://github.com/w3c/sparql-dev

afs commented 2 months ago

Yes, as @rubensworks suggest, this is for sparql-dev. The area of "scripting for federated query" is quite a large area that could have its own community of interest. Its going to have to handle errors and partial errors carefully to given an understandable and controllable outcome.

See also https://jena.apache.org/documentation/query/service_enhancer.html (a contribution from @AKSW).

afs commented 2 months ago

Hi @chiarcos,

The working group looked at this issue. Given it is not core to RDF Star, the WG asked that it be moved to sparql-dev CG to get wider input and discussion. All content is transferred.