sparqlrdfknowledge-graphrdf-star

How bind values within RDF-star triples to variables?


Using RDF-star, say I have:

?couple :isA :Couple .

and ?couple takes values such as this one:

<< :Bill :marriedTo :Mary >> :isA :Couple .

Is there any way to extract :Bill and :Mary from the triples variable ?couple, and bind them to variables ?husband and ?wife?

I know I could do this:

<< ?husband :marriedTo ?wife >> :isA :Couple .

but I also want the variable ?couple and have this linked to ?husband and ?wife.


Solution

  • One option is to create ?couple from its constituents:

    << ?husband :marriedTo ?wife >> :isA :Couple .
    BIND(<< ?husband :marriedTo ?wife >> AS ?couple)
    

    There is no difference between a triple constructed in this way and the ?couple from your original example.

    Another possibility is to introduce a zero-length property path between ?couple and another node:

    ?couple :isA :Couple .
    ?couple <about:invalid>? << ?husband :marriedTo ?wife >> .
    

    Since there is most likely no triple using about:invalid as the predicate, the subject will have to match the object.