0

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.

gaspanic
  • 249
  • 1
  • 12

2 Answers2

3

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.

IS4
  • 11,945
  • 2
  • 47
  • 86
  • 1
    Thanks! The first example is most intuitive to me, and I had no idea one could use empty property paths like in your second example! So two learnings in one. – gaspanic Jul 29 '22 at 19:31
2

There are functions to access the components of a quoted triple:

  ?couple :isA :Couple .
  BIND(subject(?couple) AS ?husband)
  BIND(object(?couple) AS ?wife)

gives

--------------------------------------------------
| couple                       | husband | wife  |
==================================================
| << :Bill :marriedTo :Mary >> | :Bill   | :Mary |
--------------------------------------------------
AndyS
  • 16,345
  • 17
  • 21
  • Thanks, wish I could accept both answers. – gaspanic Jul 30 '22 at 02:39
  • Could it be that these functions are not supported by Ontotext's GraphDB? – gaspanic Jul 31 '22 at 12:21
  • 1
    They are in the Community Report - I'm not sure what the status of RDF-star in GraphDB is. https://stackoverflow.com/questions/67835525/does-graphdb-support-rdf-star-syntax – AndyS Aug 01 '22 at 12:40
  • Thanks, this explains why my earlier attempts to use ```{|..|}``` syntax didn't work. – gaspanic Aug 01 '22 at 12:46
  • Looks like what was missing here was the prefix for the functions. At least in GraphDB the functions are called as rdf:subject and rdf:object. – gaspanic Aug 01 '22 at 15:12
  • Thanks for the information. They are keywords in SPARQL-star report https://www.w3.org/2021/12/rdf-star.html but things take time to get through the technology pipeline. – AndyS Aug 01 '22 at 17:02
  • I may note that I'm using GraphDB 9.11. Perhaps this has already been fixed in GraphDB 10, which was released a couple of months ago. – gaspanic Aug 01 '22 at 17:06