2

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

mkk
  • 879
  • 6
  • 19
  • 1
    hm, ok. at least I can say that getting the result as a single line per trip linage is not possible in SPARQL. You have to define the columns in advance, and aggregation via `group_concat` would also not work because the order is lost. all you can get is the pairs of related trips and then you could post-process it on the client side. – UninformedUser Sep 24 '20 at 06:41
  • Ok thanks, I suspected that something like this would be hard, at least on something limited to 1.1 like Virtuoso – mkk Sep 24 '20 at 06:43
  • 1
    what do you mean by limited to 1.1? SPARQL 1.1 is latest standard, people are working on SPARQL 1.2 but this will take years. Some triple stores do provide path extensions like Stardog which would help you and solve your task pretty well. Other than that, a proper graph traversal language like Cyper, Gremlin, etc. would be better suited to get all paths which is exatcly what you're asking for – UninformedUser Sep 24 '20 at 06:45
  • Yeah thats what I meant that SPARQL with search-like keywords, in particular Stardog "PATHS" is not part of the 1.1 standard – mkk Sep 24 '20 at 07:06

0 Answers0