Danny_Joris
Danny_Joris

Reputation: 399

SPARQL: combining variables with literals

Is it possible to create a subject in a SPARQL triple that is created by combining a variable and a literal?

My case is this:

OPTIONAL  
{
  $object dc:identifier $identifier .
  <info:fedora/abc:123/MODS> fedora-view:disseminationType $mods .
  <info:fedora/abc:123/TN> fedora-view:disseminationType $tn
}

$object looks like this: <info:fedora/abc:123> $identifier looks like this: abc:123 and what I need is this: <info:fedora/abc:123/MODS>

I can't use <info:fedora/$identifier/MODS> but is there another way to 'glue' variables and literals together?

Upvotes: 6

Views: 2882

Answers (1)

Gregory Williams
Gregory Williams

Reputation: 164

With SPARQL 1.1, you should be able to use a combination of BIND(), STR(), IRI(), and CONCAT() to do what you want. Something like:

SELECT * WHERE {
  $object dc:identifier $identifier .
  BIND(IRI(CONCAT(STR($object), "/MODS")) AS $new)
  $new fedora-view:disseminationType $mods .
  $new fedora-view:disseminationType $tn .
}

Upvotes: 8

Related Questions