0

Using a string as an URI works using:

SELECT DISTINCT ?db_uri ?uri ?db_uri_var ?prop ?val

{
BIND(URI("http://dbpedia.org/resource/Delta_Air_Lines") as ?db_uri)
      
      SERVICE <http://DBpedia.org/sparql>
{
?db_uri ?prop ?val .
}
}

However, as the value for the string comes "from somewhere else", I would need to use a variable inside the URI-call. This seems not to work.

SELECT DISTINCT ?db_uri ?uri ?db_uri_var ?prop ?val

{
BIND("http://dbpedia.org/resource/Delta_Air_Lines" as ?uri)
BIND(URI(?uri) as ?db_uri)
      
      SERVICE <http://DBpedia.org/sparql>
{
?db_uri ?prop ?val .
}
}
UninformedUser
  • 8,397
  • 1
  • 14
  • 23
Oliver
  • 441
  • 6
  • 14
  • which SPARQL engine do you use? sounds like the `db_uri` isn't passed into the SERVICE clause which might just be some inefficiency of the query optimizer – UninformedUser Aug 09 '21 at 15:47
  • 1
    I am using Stardog 7.7.1 – Oliver Aug 09 '21 at 16:15
  • Have you tried putting the BIND (I'd probably use a VALUES instead) *inside* the SERVICE block? E.g., something like `... SERVICE { VALUES (?db_uri) { } ?db_uri ?prop ?val } ...` ? – Joshua Taylor Aug 10 '21 at 02:10
  • That said, if you're using a fixed value like that, do you really need to bind it to a variable at all? You can just do `... SERVICE <...> { ?prop ?val } ...` after all. – Joshua Taylor Aug 10 '21 at 02:11
  • Moving the BIND did not do the trick either; I have used the workaround to change the type from string to URI within the DB; however, I keep investigating solving the original problem; and yes, unfortunately the values come from another query, hence I have to use a variable – Oliver Aug 10 '21 at 06:49
  • putting the `BIND` part inside the `SERVICE` clause has to work in my point of view because the whole graph pattern is simply evaluated remotely on the DBpedia (backed by Virtuoso) endpoint – UninformedUser Aug 10 '21 at 07:35
  • what can fail is indeed to inline previously bound data because this is also the issue with the rather unspecified evaluation of `SERVICE` clauses in combination with inline data (`VALUES` and `BIND`) - this is more non-normative but informative: https://www.w3.org/TR/sparql11-federated-query/#values – UninformedUser Aug 10 '21 at 07:38
  • my suggestion is to ask on the Stardog mailing list, the developers are very kind and helpful – UninformedUser Aug 10 '21 at 07:39
  • I also tried the query with binding inside the `SERVICE` clause: `SELECT DISTINCT ?db_uri ?uri ?db_uri_var ?prop ?val { SERVICE { BIND("http://dbpedia.org/resource/Delta_Air_Lines" as ?uri) BIND(URI(?uri) as ?db_uri) ?db_uri ?prop ?val . } }` - it works as expected with Jena - indeed it doesn't solve your issue when getting variables from outside the query, but there are engines that can optimize and inline rather efficient. – UninformedUser Aug 10 '21 at 07:43
  • well, I can see you're already in touch with the Stardog devs on the mailing list – UninformedUser Aug 10 '21 at 08:08
  • yes, let's see what the Stardog team comes back with. thx! – Oliver Aug 10 '21 at 16:29
  • I see this is old but the function for creating an IRI is `IRI()`: https://www.w3.org/TR/sparql11-query/#func-iri – Paul Jackson Nov 25 '22 at 18:17

0 Answers0