For some data in this sample schema, I want to find all possible "trip lineages".
For example: trips 2-4 form a lineage when the passenger of the previous trip is the driver of the next trip.
In this oversimplified example you could obviously add a tp:drove
property to a person such that we can use SPARQL 1.1 to do something like ?p1 tp:drove+/tp:person ?pn .
.
Unfortunately, in my application this is impossible.
Here is the ontology:
tp:trip a owl:Class ;
rdfs:label "trip"@en ;
rdfs:comment "an 'asymmetric encounter' where someone is driving another person."@en .
tp:driver a owl:ObjectProperty ;
rdfs:label "driver"@en ;
rdfs:comment "has keys."@en ;
rdfs:domain tp:trip ;
rdfs:range tp:person .
tp:passenger a owl:ObjectProperty ;
rdfs:label "passenger"@en ;
rdfs:comment "has drinks."@en ;
rdfs:domain tp:trip ;
rdfs:range tp:person .
Here is the data:
<alice> a tp:person .
<grace> a tp:person .
<tim> a tp:person .
<ruth> a tp:person .
<trip1> a tp:trip ;
tp:participants <alice> , <grace> ;
tp:driver <alice> ;
tp:passenger <grace> .
<trip2> a tp:trip ;
tp:participants <alice> , <tim> ;
tp:driver <alice> ;
tp:passenger <tim> .
<trip3> a tp:trip ;
tp:participants <tim> , <grace> ;
tp:driver <tim> ;
tp:passenger <grace> .
<trip4> a tp:trip ;
tp:participants <grace> , <ruth> ;
tp:driver <grace> ;
tp:passenger <ruth> .
<trip5> a tp:trip ;
tp:participants <grace> , <tim> ;
tp:driver <grace> ;
tp:passenger <tim> .
What I need:
Each unique sequence of trips (not including sub-sequences or loops) where the passenger of the previous trip is the driver of the next trip.
For the example above this solution would include the following five sequences:
trip1
trip1,trip4
trip1,trip5
trip2,trip3,trip4
trip2,trip3,trip5