%META:TOPICPARENT{name="VirtTipsAndTricksGuide"}%
---+How Do I use Transitivity via Inference Rules and Transitivity for lists?
Two methods can be used for typical recursions, transitivity on inference and plain transitive patterns (or subqueries).
The advantage of inference is that queries are short and one inference rule set may be maintained for numerous queries.
If queries are about trees of classes or properties, or about equivalences of nodes, consider using inference rule sets.
Transitive patterns are inconvenient and may easily result in queries that runs too long or hard to debug, but they're unavoidable in traversing social networks or plain querying of RDF lists.
So consider a rule set, a handful of nodes with classes from the rule set and a couple of RDF Lisp-style lists defined on demo.openlinksw.com:
SQL> SPARQL CLEAR GRAPH ;
callret-0
VARCHAR
_______________________________________________________________________________
Clear -- done
1 Rows. -- 0 msec.
SQL> TTLP (' @prefix rdf: .
@prefix rdfs: .
@prefix owl: .
@prefix e: .
e:c1 rdfs:subClassOf e:c1or2 .
e:c2 rdfs:subClassOf e:c1or2 .
e:c1-10 rdfs:subClassOf e:c1 .
e:c1-20 rdfs:subClassOf e:c1 .
e:c2-30 rdfs:subClassOf e:c2 .
e:c2-40 rdfs:subClassOf e:c2 .
', 'http://example.com/2/owl', 'http://example.com/2/owl' );
Done. -- 0 msec.
You can also use the SPARUL equivalent variant:
SPARQL
PREFIX rdf:
PREFIX rdfs:
PREFIX owl:
PREFIX e:
INSERT IN GRAPH
{
e:c1 rdfs:subClassOf e:c1or2 .
e:c2 rdfs:subClassOf e:c1or2 .
e:c1-10 rdfs:subClassOf e:c1 .
e:c1-20 rdfs:subClassOf e:c1 .
e:c2-30 rdfs:subClassOf e:c2 .
e:c2-40 rdfs:subClassOf e:c2 .
} ;
Define the inference rule:
SQL> rdfs_rule_set ('http://example.com/2/owl', 'http://example.com/2/owl');
Done. -- 0 msec.
SQL> SPARQL CLEAR GRAPH ;
callret-0
VARCHAR
_______________________________________________________________________________
Clear -- done
1 Rows. -- 0 msec.
SQL> TTLP ('
@prefix e: .
@prefix rdf: .
@prefix owl: .
e:s1 a e:c1 ; e:p1 "Value of p1 for s1" .
e:s2 a e:c2 ; e:p1 "Value of p1 for s2" .
e:s1-10 a e:c1-10 ; e:p1 "Value of p1 for s1-10" .
e:s1-20 a e:c1-20 ; e:p1 "Value of p1 for s1-20" .
e:s2-30 a e:c2-30 ; e:p1 "Value of p1 for s2-30" .
e:s2-40 a e:c2-40 ; e:p1 "Value of p1 for s2-40" .
e:lists
rdf:_1 ( e:list1-item1 e:list1-item2 e:list1-item3 ) ;
rdf:_2 (
[ e:p2 "Value of p2 of item1 of list2" ; e:p3 "Value of p3 of item1 of list2" ]
[ e:p2 "Value of p2 of item2 of list2" ; e:p3 "Value of p3 of item2 of list2" ]
[ e:p2 "Value of p2 of item3 of list2" ; e:p3 "Value of p3 of item3 of list2" ] ) .
', 'http://example.com/2/data', 'http://example.com/2/data' );
Done. -- 0 msec.
You can also use the SPARUL equivalent variant:
SPARQL
PREFIX e:
PREFIX rdf:
PREFIX owl:
INSERT IN GRAPH
{
e:s1 a e:c1 ; e:p1 "Value of p1 for s1" .
e:s2 a e:c2 ; e:p1 "Value of p1 for s2" .
e:s1-10 a e:c1-10 ; e:p1 "Value of p1 for s1-10" .
e:s1-20 a e:c1-20 ; e:p1 "Value of p1 for s1-20" .
e:s2-30 a e:c2-30 ; e:p1 "Value of p1 for s2-30" .
e:s2-40 a e:c2-40 ; e:p1 "Value of p1 for s2-40" .
e:lists
rdf:_1 ( e:list1-item1 e:list1-item2 e:list1-item3 ) ;
rdf:_2 (
[ e:p2 "Value of p2 of item1 of list2" ; e:p3 "Value of p3 of item1 of list2" ]
[ e:p2 "Value of p2 of item2 of list2" ; e:p3 "Value of p3 of item2 of list2" ]
[ e:p2 "Value of p2 of item3 of list2" ; e:p3 "Value of p3 of item3 of list2" ] )
};
SPARQL DESCRIBE works fine with inference, deriving additional type information:
DEFINE input:inference
DESCRIBE
FROM
fmtaggret-
LONG VARCHAR
_______________________________________________________________________________
@prefix rdf: .
@prefix ns1: .
ns1:s1 rdf:type ns1:c1or2 ,
ns1:c1 ;
ns1:p1 "Value of p1 for s1" .
1 Rows. -- 0 msec.
Example links against [[http://demo.openlinksw.com/sparql][Virtuoso Demo Server SPARQL Endpoint]] with SPARQl Protocol URLs:
* [[http://demo.openlinksw.com/sparql?default-graph-uri=&query=DEFINE+input%3Ainference+%3Chttp%3A%2F%2Fexample.com%2F2%2Fowl%3E%0D%0ADESCRIBE+%3Chttp%3A%2F%2Fexample.com%2Fe%2Fs1%3E%0D%0AFROM+%3Chttp%3A%2F%2Fexample.com%2F2%2Fdata%3E&should-sponge=&format=application%2Frdf%2Bxml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=0&debug=on][View results page]]
* [[http://demo.openlinksw.com/sparql?default-graph-uri=&qtxt=DEFINE+input%3Ainference+%3Chttp%3A%2F%2Fexample.com%2F2%2Fowl%3E%0D%0ADESCRIBE+%3Chttp%3A%2F%2Fexample.com%2Fe%2Fs1%3E%0D%0AFROM+%3Chttp%3A%2F%2Fexample.com%2F2%2Fdata%3E&should-sponge=&format=application%2Frdf%2Bxml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=0&debug=on][View editor page]]
DEFINE input:inference
DESCRIBE
FROM
fmtaggret-
LONG VARCHAR
_______________________________________________________________________________
@prefix rdf: .
@prefix ns1: .
ns1:s2 rdf:type ns1:c1or2 ,
ns1:c2 ;
ns1:p1 "Value of p1 for s2" .
1 Rows. -- 0 msec.
Example links against [[http://demo.openlinksw.com/sparql][Virtuoso Demo Server SPARQL Endpoint]] with SPARQl Protocol URLs:
* [[http://demo.openlinksw.com/sparql?default-graph-uri=&query=DEFINE+input%3Ainference+%3Chttp%3A%2F%2Fexample.com%2F2%2Fowl%3E%0D%0ADESCRIBE+%3Chttp%3A%2F%2Fexample.com%2Fe%2Fs2%3E+%0D%0AFROM+%3Chttp%3A%2F%2Fexample.com%2F2%2Fdata%3E&should-sponge=&format=application%2Frdf%2Bxml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=0&debug=on][View results page]]
* [[http://demo.openlinksw.com/sparql?default-graph-uri=&qtxt=DEFINE+input%3Ainference+%3Chttp%3A%2F%2Fexample.com%2F2%2Fowl%3E%0D%0ADESCRIBE+%3Chttp%3A%2F%2Fexample.com%2Fe%2Fs2%3E+%0D%0AFROM+%3Chttp%3A%2F%2Fexample.com%2F2%2Fdata%3E&should-sponge=&format=application%2Frdf%2Bxml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=0&debug=on][View editor page]]
Querying is simple as well:
SQL>SPARQL DEFINE input:inference
PREFIX e:
SELECT *
FROM
WHERE
{
?s a e:c1or2 ;
e:p1 ?o
}
s o
VARCHAR VARCHAR
___________________________
http://example.com/e/s1 Value of p1 for s1
http://example.com/e/s1-10 Value of p1 for s1-10
http://example.com/e/s1-20 Value of p1 for s1-20
http://example.com/e/s2-30 Value of p1 for s2-30
http://example.com/e/s2-40 Value of p1 for s2-40
http://example.com/e/s2 Value of p1 for s2
6 Rows. -- 0 msec.
Example links against [[http://demo.openlinksw.com/sparql][Virtuoso Demo Server SPARQL Endpoint]] with SPARQl Protocol URLs:
* [[http://demo.openlinksw.com/sparql?default-graph-uri=&query=DEFINE+input%3Ainference+%3Chttp%3A%2F%2Fexample.com%2F2%2Fowl%3E++%0D%0APREFIX+e%3A%3Chttp%3A%2F%2Fexample.com%2Fe%2F%3E%0D%0ASELECT+*+%0D%0AFROM+%3Chttp%3A%2F%2Fexample.com%2F2%2Fdata%3E+%0D%0AWHERE+%0D%0A++%7B+%0D%0A++++%3Fs+a+e%3Ac1or2+%3B+%0D%0A++++++++++e%3Ap1+%3Fo+%0D%0A++%7D&should-sponge=&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=0&debug=on][View results page]]
* [[http://demo.openlinksw.com/sparql?default-graph-uri=&qtxt=DEFINE+input%3Ainference+%3Chttp%3A%2F%2Fexample.com%2F2%2Fowl%3E++%0D%0APREFIX+e%3A%3Chttp%3A%2F%2Fexample.com%2Fe%2F%3E%0D%0ASELECT+*+%0D%0AFROM+%3Chttp%3A%2F%2Fexample.com%2F2%2Fdata%3E+%0D%0AWHERE+%0D%0A++%7B+%0D%0A++++%3Fs+a+e%3Ac1or2+%3B+%0D%0A++++++++++e%3Ap1+%3Fo+%0D%0A++%7D&should-sponge=&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=0&debug=on][View editor page]]
SQL>SPARQL DEFINE input:inference
PREFIX e:
SELECT * FROM
WHERE
{
?s a e:c1 ;
e:p1 ?o
}
s o
VARCHAR VARCHAR
___________________________
http://example.com/e/s1 Value of p1 for s1
http://example.com/e/s1-10 Value of p1 for s1-10
http://example.com/e/s1-20 Value of p1 for s1-20
3 Rows. -- 0 msec.
Example links against [[http://demo.openlinksw.com/sparql][Virtuoso Demo Server SPARQL Endpoint]] with SPARQl Protocol URLs:
* [[http://demo.openlinksw.com/sparql?default-graph-uri=&query=DEFINE+input%3Ainference+%3Chttp%3A%2F%2Fexample.com%2F2%2Fowl%3E++%0D%0APREFIX+e%3A%3Chttp%3A%2F%2Fexample.com%2Fe%2F%3E%0D%0ASELECT+*+FROM+%3Chttp%3A%2F%2Fexample.com%2F2%2Fdata%3E++%0D%0AWHERE+%0D%0A++%7B+%0D%0A++++%3Fs+a+e%3Ac1+%3B+%0D%0A+++++++e%3Ap1+%3Fo+%0D%0A++%7D&should-sponge=&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=0&debug=on][View results page]]
* [[http://demo.openlinksw.com/sparql?default-graph-uri=&qtxt=DEFINE+input%3Ainference+%3Chttp%3A%2F%2Fexample.com%2F2%2Fowl%3E++%0D%0APREFIX+e%3A%3Chttp%3A%2F%2Fexample.com%2Fe%2F%3E%0D%0ASELECT+*+FROM+%3Chttp%3A%2F%2Fexample.com%2F2%2Fdata%3E++%0D%0AWHERE+%0D%0A++%7B+%0D%0A++++%3Fs+a+e%3Ac1+%3B+%0D%0A+++++++e%3Ap1+%3Fo+%0D%0A++%7D&should-sponge=&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=0&debug=on][View editor page]]
However you should care about duplicates if both types and properties are queried: the join will result in all combinations of types and property values.
SQL>SPARQL DEFINE input:inference
PREFIX e:
SELECT * FROM
WHERE
{
?s a ?t ;
e:p1 ?o
}
s t o
VARCHAR VARCHAR VARCHAR
___________________________
http://example.com/e/s1 http://example.com/e/c1 Value of p1 for s1
http://example.com/e/s1 http://example.com/e/c1or2 Value of p1 for s1
http://example.com/e/s1-10 http://example.com/e/c1-10 Value of p1 for s1-10
http://example.com/e/s1-10 http://example.com/e/c1 Value of p1 for s1-10
http://example.com/e/s1-10 http://example.com/e/c1or2 Value of p1 for s1-10
http://example.com/e/s1-20 http://example.com/e/c1-20 Value of p1 for s1-20
http://example.com/e/s1-20 http://example.com/e/c1 Value of p1 for s1-20
http://example.com/e/s1-20 http://example.com/e/c1or2 Value of p1 for s1-20
http://example.com/e/s2-30 http://example.com/e/c2-30 Value of p1 for s2-30
http://example.com/e/s2-30 http://example.com/e/c2 Value of p1 for s2-30
http://example.com/e/s2-30 http://example.com/e/c1or2 Value of p1 for s2-30
http://example.com/e/s2-40 http://example.com/e/c2-40 Value of p1 for s2-40
http://example.com/e/s2-40 http://example.com/e/c2 Value of p1 for s2-40
http://example.com/e/s2-40 http://example.com/e/c1or2 Value of p1 for s2-40
http://example.com/e/s2 http://example.com/e/c2 Value of p1 for s2
http://example.com/e/s2 http://example.com/e/c1or2 Value of p1 for s2
16 Rows. -- 0 msec.
Example links against [[http://demo.openlinksw.com/sparql][Virtuoso Demo Server SPARQL Endpoint]] with SPARQl Protocol URLs:
* [[http://demo.openlinksw.com/sparql?default-graph-uri=&query=DEFINE+input%3Ainference+%3Chttp%3A%2F%2Fexample.com%2F2%2Fowl%3E++%0D%0APREFIX+e%3A%3Chttp%3A%2F%2Fexample.com%2Fe%2F%3E%0D%0ASELECT+*+FROM+%3Chttp%3A%2F%2Fexample.com%2F2%2Fdata%3E++%0D%0AWHERE+%0D%0A++%7B+%0D%0A++++%3Fs+a+%3Ft+%3B+%0D%0A+++++e%3Ap1+%3Fo+%0D%0A++%7D&should-sponge=&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=0&debug=on][View results page]]
* [[http://demo.openlinksw.com/sparql?default-graph-uri=&qtxt=DEFINE+input%3Ainference+%3Chttp%3A%2F%2Fexample.com%2F2%2Fowl%3E++%0D%0APREFIX+e%3A%3Chttp%3A%2F%2Fexample.com%2Fe%2F%3E%0D%0ASELECT+*+FROM+%3Chttp%3A%2F%2Fexample.com%2F2%2Fdata%3E++%0D%0AWHERE+%0D%0A++%7B+%0D%0A++++%3Fs+a+%3Ft+%3B+%0D%0A+++++e%3Ap1+%3Fo+%0D%0A++%7D&should-sponge=&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=0&debug=on][View editor page]]
Transitive queries are convenient as SPARQL 1.1 "predicate+" equivalent. The equivalent of "predicate*" requires the use of a union:
SQL>SPARQL PREFIX e:
SELECT ?item
FROM
WHERE
{
{
?lists rdf:_1 ?node
}
UNION
{
?lists rdf:_1 ?l .
?l rdf:rest ?node option (transitive) .
}
?node rdf:first ?item
}
item
VARCHAR
_______________________________________________________________________________
http://example.com/e/list1-item1
http://example.com/e/list1-item2
http://example.com/e/list1-item3
3 Rows. -- 0 msec.
Example links against [[http://demo.openlinksw.com/sparql][Virtuoso Demo Server SPARQL Endpoint]] with SPARQl Protocol URLs:
* [[http://demo.openlinksw.com/sparql?default-graph-uri=&query=PREFIX+e%3A%3Chttp%3A%2F%2Fexample.com%2Fe%2F%3E%0D%0ASELECT+%3Fitem+%0D%0AFROM+%3Chttp%3A%2F%2Fexample.com%2F2%2Fdata%3E++%0D%0AWHERE+%0D%0A++%7B%0D%0A++++%7B+%0D%0A++++++%3Flists+rdf%3A_1+%3Fnode+%0D%0A++++%7D%0D%0A++++UNION%0D%0A++++%7B+%0D%0A++++++%3Flists+rdf%3A_1+%3Fl+.%0D%0A++++++%3Fl+rdf%3Arest+%3Fnode+option+%28transitive%29+.+%0D%0A++++%7D%0D%0A++++%3Fnode+rdf%3Afirst+%3Fitem+%0D%0A++%7D&should-sponge=&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=0&debug=on][View results page]]
* [[http://demo.openlinksw.com/sparql?default-graph-uri=&qtxt=PREFIX+e%3A%3Chttp%3A%2F%2Fexample.com%2Fe%2F%3E%0D%0ASELECT+%3Fitem+%0D%0AFROM+%3Chttp%3A%2F%2Fexample.com%2F2%2Fdata%3E++%0D%0AWHERE+%0D%0A++%7B%0D%0A++++%7B+%0D%0A++++++%3Flists+rdf%3A_1+%3Fnode+%0D%0A++++%7D%0D%0A++++UNION%0D%0A++++%7B+%0D%0A++++++%3Flists+rdf%3A_1+%3Fl+.%0D%0A++++++%3Fl+rdf%3Arest+%3Fnode+option+%28transitive%29+.+%0D%0A++++%7D%0D%0A++++%3Fnode+rdf%3Afirst+%3Fitem+%0D%0A++%7D&should-sponge=&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=0&debug=on][View editor page]]
SQL> SPARQL PREFIX e:
SELECT ?p ?o
FROM
WHERE
{
{
?lists rdf:_2 ?node
}
UNION
{
?lists rdf:_2 ?l .
?l rdf:rest ?node option (transitive) .
}
?node rdf:first ?item .
?item ?p ?o
}
p o
VARCHAR VARCHAR
________________________
http://example.com/e/p2 Value of p2 of item1 of list2
http://example.com/e/p3 Value of p3 of item1 of list2
http://example.com/e/p2 Value of p2 of item2 of list2
http://example.com/e/p3 Value of p3 of item2 of list2
http://example.com/e/p2 Value of p2 of item3 of list2
http://example.com/e/p3 Value of p3 of item3 of list2
6 Rows. -- 0 msec.
Example links against [[http://demo.openlinksw.com/sparql][Virtuoso Demo Server SPARQL Endpoint]] with SPARQl Protocol URLs:
* [[http://demo.openlinksw.com/sparql?default-graph-uri=&query=PREFIX+e%3A%3Chttp%3A%2F%2Fexample.com%2Fe%2F%3E%0D%0ASELECT+%3Fp+%3Fo+%0D%0AFROM+%3Chttp%3A%2F%2Fexample.com%2F2%2Fdata%3E++%0D%0AWHERE+%0D%0A++%7B%0D%0A++++%7B+%0D%0A++++++%3Flists+rdf%3A_2+%3Fnode+%0D%0A++++%7D%0D%0A++++UNION%0D%0A++++%7B+%0D%0A++++++%3Flists+rdf%3A_2+%3Fl+.%0D%0A++++++%3Fl+rdf%3Arest+%3Fnode+option+%28transitive%29+.+%0D%0A++++%7D%0D%0A++++%3Fnode+rdf%3Afirst+%3Fitem+.%0D%0A++++%3Fitem+%3Fp+%3Fo+%0D%0A++%7D&should-sponge=&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=0&debug=on][View results page]]
* [[http://demo.openlinksw.com/sparql?default-graph-uri=&qtxt=PREFIX+e%3A%3Chttp%3A%2F%2Fexample.com%2Fe%2F%3E%0D%0ASELECT+%3Fp+%3Fo+%0D%0AFROM+%3Chttp%3A%2F%2Fexample.com%2F2%2Fdata%3E++%0D%0AWHERE+%0D%0A++%7B%0D%0A++++%7B+%0D%0A++++++%3Flists+rdf%3A_2+%3Fnode+%0D%0A++++%7D%0D%0A++++UNION%0D%0A++++%7B+%0D%0A++++++%3Flists+rdf%3A_2+%3Fl+.%0D%0A++++++%3Fl+rdf%3Arest+%3Fnode+option+%28transitive%29+.+%0D%0A++++%7D%0D%0A++++%3Fnode+rdf%3Afirst+%3Fitem+.%0D%0A++++%3Fitem+%3Fp+%3Fo+%0D%0A++%7D&should-sponge=&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=0&debug=on][View editor page]]
Note that the result set can be in order of items in the list, but it don't have to. If the order should be preserved, then fix the direction of transitive scan, get step number as a variable, order by that variable.
SQL> SPARQL PREFIX e:
SELECT ?p ?o bif:coalesce(?step_no, 0)
FROM
WHERE
{
{
?lists rdf:_2 ?node
}
UNION
{
?lists rdf:_2 ?l .
?l rdf:rest ?node OPTION (transitive, t_direction 1, t_step("step_no") as ?step_no) .
}
?node rdf:first ?item .
?item ?p ?o
}
ORDER BY ASC (?step_no)
p o callret-2
VARCHAR VARCHAR VARCHAR
________________________
http://example.com/e/p2 Value of p2 of item1 of list2 0
http://example.com/e/p3 Value of p3 of item1 of list2 0
http://example.com/e/p2 Value of p2 of item2 of list2 1
http://example.com/e/p3 Value of p3 of item2 of list2 1
http://example.com/e/p2 Value of p2 of item3 of list2 2
http://example.com/e/p3 Value of p3 of item3 of list2 2
6 Rows. -- 7 msec.
Example links against [[http://demo.openlinksw.com/sparql][Virtuoso Demo Server SPARQL Endpoint]] with SPARQl Protocol URLs:
* [[http://demo.openlinksw.com/sparql?default-graph-uri=&query=PREFIX+e%3A%3Chttp%3A%2F%2Fexample.com%2Fe%2F%3E%0D%0ASELECT+%3Fp+%3Fo+bif%3Acoalesce%28%3Fstep_no%2C+0%29+%0D%0AFROM+%3Chttp%3A%2F%2Fexample.com%2F2%2Fdata%3E++%0D%0AWHERE+%0D%0A++%7B%0D%0A++++%7B+%0D%0A++++++%3Flists+rdf%3A_2+%3Fnode+%0D%0A++++%7D%0D%0A++++UNION%0D%0A++++%7B+%0D%0A++++++%3Flists+rdf%3A_2+%3Fl+.%0D%0A++++++%3Fl+rdf%3Arest+%3Fnode+OPTION+%28transitive%2C+t_direction+1%2C+t_step%28%22step_no%22%29+as+%3Fstep_no%29+.+%0D%0A++++%7D%0D%0A++++%3Fnode+rdf%3Afirst+%3Fitem+.%0D%0A++++%3Fitem+%3Fp+%3Fo+%0D%0A++%7D+%0D%0AORDER+BY+ASC+%28%3Fstep_no%29%0D%0A&should-sponge=&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=0&debug=on][View results page]]
* [[http://demo.openlinksw.com/sparql?default-graph-uri=&qtxt=PREFIX+e%3A%3Chttp%3A%2F%2Fexample.com%2Fe%2F%3E%0D%0ASELECT+%3Fp+%3Fo+bif%3Acoalesce%28%3Fstep_no%2C+0%29+%0D%0AFROM+%3Chttp%3A%2F%2Fexample.com%2F2%2Fdata%3E++%0D%0AWHERE+%0D%0A++%7B%0D%0A++++%7B+%0D%0A++++++%3Flists+rdf%3A_2+%3Fnode+%0D%0A++++%7D%0D%0A++++UNION%0D%0A++++%7B+%0D%0A++++++%3Flists+rdf%3A_2+%3Fl+.%0D%0A++++++%3Fl+rdf%3Arest+%3Fnode+OPTION+%28transitive%2C+t_direction+1%2C+t_step%28%22step_no%22%29+as+%3Fstep_no%29+.+%0D%0A++++%7D%0D%0A++++%3Fnode+rdf%3Afirst+%3Fitem+.%0D%0A++++%3Fitem+%3Fp+%3Fo+%0D%0A++%7D+%0D%0AORDER+BY+ASC+%28%3Fstep_no%29%0D%0A&should-sponge=&format=text%2Fhtml&CXML_redir_for_subjs=121&CXML_redir_for_hrefs=&timeout=0&debug=on][View editor page]]
---++Related
* [[VirtTipsAndTricksGuide][Virtuoso Tips and Tricks Collection]]
* [[http://docs.openlinksw.com/virtuoso/rdfsparqlrule.html#rdfsparqlrulesubclassandsubprop][Virtuoso Documentation: Subclasses and Subproperties]]
* [[VirtsubClassOfOrientedSubsumptionTransitiveOptions][Transitive SPARQL query options and Exploit Inference Rules Examples]]