title: SPARQL paths where the subject and object are not of the same class
body: <p>For some data in this sample schema, I want to find all possible &quot;trip lineages&quot;.<br />
  For example: trips 2-4 form a lineage when the passenger of the previous trip is the driver of the next trip.</p>
  <p>In this oversimplified example you could obviously add a <code>tp:drove</code> property to a person such that we can use SPARQL 1.1 to do something like  <code>?p1 tp:drove+/tp:person ?pn .</code>.</p>
  <p>Unfortunately, in my application this is impossible.</p>
  <p>Here is the ontology:</p>
  <pre><code>tp:trip a owl:Class ;
      rdfs:label &quot;trip&quot;@en ;
      rdfs:comment &quot;an 'asymmetric encounter' where someone is driving another person.&quot;@en .
  
  tp:driver a owl:ObjectProperty ;
      rdfs:label &quot;driver&quot;@en ;
      rdfs:comment &quot;has keys.&quot;@en ;
      rdfs:domain tp:trip ;
      rdfs:range tp:person .
  
  tp:passenger a owl:ObjectProperty ;
      rdfs:label &quot;passenger&quot;@en ;
      rdfs:comment &quot;has drinks.&quot;@en ;
      rdfs:domain tp:trip ;
      rdfs:range tp:person .
  </code></pre>
  <p>Here is the data:</p>
  <pre><code>&lt;alice&gt; a tp:person .
  &lt;grace&gt; a tp:person .
  &lt;tim&gt; a tp:person .
  &lt;ruth&gt; a tp:person .
  
  &lt;trip1&gt; a tp:trip ;
      tp:participants   &lt;alice&gt; , &lt;grace&gt; ;
      tp:driver         &lt;alice&gt; ;
      tp:passenger         &lt;grace&gt; .
  
  &lt;trip2&gt; a tp:trip ;
      tp:participants   &lt;alice&gt; , &lt;tim&gt; ;
      tp:driver         &lt;alice&gt; ;
      tp:passenger         &lt;tim&gt; .
  
  &lt;trip3&gt; a tp:trip ;
      tp:participants   &lt;tim&gt; , &lt;grace&gt; ;
      tp:driver         &lt;tim&gt; ;
      tp:passenger         &lt;grace&gt; .
  
  &lt;trip4&gt; a tp:trip ;
      tp:participants   &lt;grace&gt; , &lt;ruth&gt; ;
      tp:driver         &lt;grace&gt; ;
      tp:passenger         &lt;ruth&gt; .
  
  &lt;trip5&gt; a tp:trip ;
      tp:participants   &lt;grace&gt; , &lt;tim&gt; ;
      tp:driver         &lt;grace&gt; ;
      tp:passenger         &lt;tim&gt; .
  </code></pre>
  <p>What I need:</p>
  <p>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.</p>
  <p>For the example above this solution would include the following five sequences:</p>
  <p>trip1</p>
  <p>trip1,trip4</p>
  <p>trip1,trip5</p>
  <p>trip2,trip3,trip4</p>
  <p>trip2,trip3,trip5</p>