Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > 71d40963b505df4524269198e237b3e3 > files > 854

virtuoso-opensource-doc-6.1.4-2.fc14.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
 <head profile="http://internetalchemy.org/2003/02/profile">
  <link rel="foaf" type="application/rdf+xml" title="FOAF" href="http://www.openlinksw.com/dataspace/uda/about.rdf" />
  <link rel="schema.dc" href="http://purl.org/dc/elements/1.1/" />
  <meta name="dc.title" content="14. RDF Data Access and Data Management" />
  <meta name="dc.subject" content="14. RDF Data Access and Data Management" />
  <meta name="dc.creator" content="OpenLink Software Documentation Team ;&#10;" />
  <meta name="dc.copyright" content="OpenLink Software, 1999 - 2009" />
  <link rel="top" href="index.html" title="OpenLink Virtuoso Universal Server: Documentation" />
  <link rel="search" href="/doc/adv_search.vspx" title="Search OpenLink Virtuoso Universal Server: Documentation" />
  <link rel="parent" href="rdfandsparql.html" title="Chapter Contents" />
  <link rel="prev" href="rdfiridereferencing.html" title="Linked Data" />
  <link rel="next" href="rdfsparqlgeospat.html" title="RDF and Geometry" />
  <link rel="shortcut icon" href="../images/misc/favicon.ico" type="image/x-icon" />
  <link rel="stylesheet" type="text/css" href="doc.css" />
  <link rel="stylesheet" type="text/css" href="/doc/translation.css" />
  <title>14. RDF Data Access and Data Management</title>
  <meta http-equiv="Content-Type" content="text/xhtml; charset=UTF-8" />
  <meta name="author" content="OpenLink Software Documentation Team ;&#10;" />
  <meta name="copyright" content="OpenLink Software, 1999 - 2009" />
  <meta name="keywords" content="" />
  <meta name="GENERATOR" content="OpenLink XSLT Team" />
 </head>
 <body>
  <div id="header">
    <a name="rdfsparqlrule" />
    <img src="../images/misc/logo.jpg" alt="" />
    <h1>14. RDF Data Access and Data Management</h1>
  </div>
  <div id="navbartop">
   <div>
      <a class="link" href="rdfandsparql.html">Chapter Contents</a> | <a class="link" href="rdfiridereferencing.html" title="Linked Data">Prev</a> | <a class="link" href="rdfsparqlgeospat.html" title="RDF and Geometry">Next</a>
   </div>
  </div>
  <div id="currenttoc">
   <form method="post" action="/doc/adv_search.vspx">
    <div class="search">Keyword Search: <br />
        <input type="text" name="q" /> <input type="submit" name="go" value="Go" />
    </div>
   </form>
   <div>
      <a href="http://www.openlinksw.com/">www.openlinksw.com</a>
   </div>
   <div>
      <a href="http://docs.openlinksw.com/">docs.openlinksw.com</a>
   </div>
    <br />
   <div>
      <a href="index.html">Book Home</a>
   </div>
    <br />
   <div>
      <a href="contents.html">Contents</a>
   </div>
   <div>
      <a href="preface.html">Preface</a>
   </div>
    <br />
   <div class="selected">
      <a href="rdfandsparql.html">RDF Data Access and Data Management</a>
   </div>
    <br />
   <div>
      <a href="rdfdatarepresentation.html">Data Representation</a>
   </div>
   <div>
      <a href="rdfsparql.html">SPARQL</a>
   </div>
   <div>
      <a href="sparqlextensions.html">Extensions</a>
   </div>
   <div>
      <a href="rdfgraphsecurity.html">RDF Graphs Security</a>
   </div>
   <div>
      <a href="rdfviews.html">Linked Data Views over RDBMS Data Source</a>
   </div>
   <div>
      <a href="rdfrdfviewgnr.html">Automated Generation of RDF Views over Relational Data Sources</a>
   </div>
   <div>
      <a href="rdfviewsenterpr.html">Examples of Linked Data Views</a>
   </div>
   <div>
      <a href="rdfinsertmethods.html">RDF Insert Methods in Virtuoso</a>
   </div>
   <div>
      <a href="virtuososponger.html">RDFizer Middleware (Sponger)</a>
   </div>
   <div>
      <a href="virtuosospongerfacetinstall.html">Virtuoso Faceted Browser Installation and configuration</a>
   </div>
   <div>
      <a href="virtuosospongerfacent.html">Virtuoso Faceted Web Service</a>
   </div>
   <div>
      <a href="rdfiridereferencing.html">Linked Data</a>
   </div>
   <div class="selected">
      <a href="rdfsparqlrule.html">Inference Rules &amp; Reasoning</a>
    <div>
        <a href="#rdfsparqlruleintro" title="Introduction">Introduction</a>
        <a href="#rdfsparqlrulemake" title="Making Rule Sets">Making Rule Sets</a>
        <a href="#rdfsparqlrulechange" title="Changing Rule Sets">Changing Rule Sets</a>
        <a href="#rdfsparqlrulesubclassandsubprop" title="Subclasses and Subproperties">Subclasses and Subproperties</a>
        <a href="#rdfsameas" title="OWL sameAs Support">OWL sameAs Support</a>
        <a href="#rdfsparqlruleintro" title="Implementation">Implementation</a>
        <a href="#rdfsparqlruleintro" title="Enabling Inferencing">Enabling Inferencing</a>
        <a href="#rdfsparqlruleexamples" title="Examples">Examples</a>
        <a href="#rdfsparqlruleinversefunc" title="Identity With Inverse Functional Properties ">Identity With Inverse Functional Properties </a>
        <a href="#rdfsparqlruletransoption" title="Inference Rules and SPARQL with Transitivity Option">Inference Rules and SPARQL with Transitivity Option</a>
        <a href="#rdfsparqlruleowlrelation" title="Inference Rules, OWL Support and Relationship Ontology">Inference Rules, OWL Support and Relationship Ontology</a>
    </div>
   </div>
   <div>
      <a href="rdfsparqlgeospat.html">RDF and Geometry</a>
   </div>
   <div>
      <a href="rdfperformancetuning.html">RDF Performance Tuning</a>
   </div>
   <div>
      <a href="rdfnativestorageproviders.html">RDF Data Access Providers (Drivers)</a>
   </div>
   <div>
      <a href="rdfgraphreplication.html">RDF Graph Replication</a>
   </div>
    <br />
  </div>
  <div id="text">
    <a name="rdfsparqlrule" />
    <h2>14.13. Inference Rules &amp; Reasoning</h2>
<a name="rdfsparqlruleintro" />
    <h3>14.13.1. Introduction</h3>
<p>Virtuoso SPARQL can use an inference context for inferring triples that are not physically stored.
This functionality applies to physically stored quads and not to virtual triples generated from relational data with RDF views.
Such an inference context can be built from one or more graphs containing RDF Schema triples. The supported
RDF Schema or OWL constraints are imported from these graphs and are grouped together into rule bases.
A rule base is a persistent entity that can be referenced by a SPARQL query or end point. Queries running
with a given rule base work as if the triples asserted by this rule base were included in the graph or graphs accessed by the query.
</p>
<p>As of version 5.0, Virtuoso recognizes <strong>rdfs:subClassOf</strong> and <strong>rdfs:subPropertyOf</strong>.
owl:sameAs is considered for arbitrary subjects and objects if specially enabled by a pragma in the query.
As of 5.00.3031, owl:sameAs, owl:equivalentClass and owl:equivalentProperty are also considered when determining subclass or subproperty relations.  If two  classes are equivalent, they share all instances, subclasses and superclasses directly or indirectly stated in the data for either class.
Other RDF Schema or OWL information is not taken into account.
</p>
<br />
<a name="rdfsparqlrulemake" />
    <h3>14.13.2. Making Rule Sets</h3>
<p>Since RDF Schema and OWL schemas are RDF graphs, these can be loaded into the triple store. Thus, in order to use
such a schema as query context, one first loads the corresponding document into the triple store using <strong>ttlp</strong> or
<strong>rdf_load_rdfxml</strong> or related functions. After the schema document is loaded, one can add the assertions therein
into an inference context with the <strong>rdfs_rule_set</strong> function. This function specifies a logical name for the rule
set plus a graph URI. It is possible to combine multiple schema graphs into a single rule set. A single schema
graph may also independently participate in multiple rule sets.
</p>
<div>
      <pre class="programlisting">
rdfs_rule_set (in name varchar, in uri varchar, in remove int := 0)
</pre>
    </div>
<p>This function adds the applicable facts of the graph into a rule set. The graph URI must correspond
to the graph IRI of a graph stored in the triple store of the Virtuoso instance. If the remove argument
is true, the specified graph is removed from the rule set instead.
</p>
<br />
<a name="rdfsparqlrulechange" />
    <h3>14.13.3. Changing Rule Sets</h3>
<p>Changing a rule set affects queries made after the change. Some queries may have been previously
compiled and will not be changed as a result of modifying the rule set. When a rule set is changed, i.e.
when <strong>rdfs_rule_set</strong> is called with the first argument set to a pre-existing rule set&#39;s name, all the graphs
associated with this name are read and the relevant facts are added to a new empty rule set. Thus, if
triples are deleted from or added to the graphs comprising the rule set, calling <strong>rdfs_rule_set</strong> will refresh
the rule set to correspond to the state of the stored graphs.
</p>
<br />
<a name="rdfsparqlrulesubclassandsubprop" />
    <h3>14.13.4. Subclasses and Subproperties</h3>
<p>Virtuoso SPARQL supports RDF Schema subclasses and subproperties.
</p>
<p>The predicates <strong>rdfs:subClassOf</strong> and <strong>rdfs:subPropertyOf</strong> are
recognized when they appear in graphs included in a rule set. When such a rule set is specified as a context
for a SPARQL query, the following extra triples are generated as needed.
</p>
<p>For every <strong>?s rdf:type ?class</strong>, a triple <strong>?s rdf:type ?superclass</strong> is considered to exist,
such that <strong>?superclass</strong> is a direct or indirect superclass of <strong>?class</strong>. Direct superclasses are
declared with the <strong>rdfs:subClassOf</strong> predicate in the rule set graph. Transitivity of superclasses
is automatically taken into account, meaning that if a is a superclass of b and b a superclass of c,
then a is a superclass of c also. Cyclic superclass relations are not allowed. If such occur in the rule set data,
the behavior is undefined but will not involve unterminating recursion.
</p>
<p>For every <strong>?s ?subpredicate ?o</strong>, a triple <strong>?s ?superpredicate ?o</strong>
is considered to exist if the rule context declares <strong>?superpredicate</strong> to be a superpredicate
of <strong>?predicate</strong>. This is done by having the triple <strong>?subpredicate rdfs:subPropertyOf ?superpredicate</strong>
as part of the graphs making up the rule context. Transitivity is observed, thus if a is a subpredicate of b and b
a subpredicate of c, then a is also a subpredicate of c.
</p>
<br />
<a name="rdfsameas" />
    <h3>14.13.5. OWL sameAs Support</h3>
<p>
Virtuoso has limited support for the OWL sameAs predicate.
</p>
<p>
If sameAs traversal is enabled and a triple pattern with a given
subject or object is being matched, all the synonyms of the S and O
will be tried and results generated for all the tried bindings of S
and O. The set of synonyms is generated at run time by following all
owl:sameAs triples where the IRI in question is either the subject or
the object. These are followed recursively from object to subject and
subject to object until the complete transitive closure is generated.
All sameAs triples from all the graphs applicable to instantiating
the triple pattern at hand are considered.
</p>
<p>
Thus for example:
</p>
<p>The inital SPARQL query:</p>
<div>
      <pre class="programlisting">
SQL&gt;SPARQL
prefix foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
prefix owl: &lt;http://www.w3.org/2002/07/owl#&gt;
prefix sioc: &lt;http://rdfs.org/sioc/ns#&gt;
SELECT *
from &lt;http://myopenlink.net/dataspace&gt;
where
 {
    ?person a foaf:Person FILTER REGEX(?person ,&quot;http://myopenlink.net/dataspace/person/kidehen#this&quot;).
    ?person foaf:name ?name .
    ?person owl:sameAs ?sameas .
  }
limit 10;
person                                               name             sameas
VARCHAR                                              VARCHAR          VARCHAR
_______________________________________________________________________________

http://myopenlink.net/dataspace/person/kidehen#this  Kingsley Idehen  http://www.openlinksw.com/dataspace/person/kidehen@openlinksw.com#this
http://myopenlink.net/dataspace/person/kidehen#this  Kingsley Idehen  http://my.openlinksw.com/dataspace/person/kidehen@openlinksw.com#this
http://myopenlink.net/dataspace/person/kidehen#this  Kingsley Idehen  http://kidehen.idehen.net/dataspace/person/kidehen#this
http://myopenlink.net/dataspace/person/kidehen#this  Kingsley Idehen  http://qdos.com/user/e922b748a2eb667bf37b188018002dec
http://myopenlink.net/dataspace/person/kidehen#this  Kingsley Idehen  http://knowee.net/kidehen/ids/id3684976382
http://myopenlink.net/dataspace/person/kidehen#this  Kingsley Idehen  http://dbpedia.org/resource/Kingsley_Idehen
http://myopenlink.net/dataspace/person/kidehen#this  Kingsley Idehen  http://dbtune.org/last-fm/kidehen
http://myopenlink.net/dataspace/person/kidehen#this  Kingsley Idehen  http://revyu.com/people/kidehen
http://myopenlink.net/dataspace/person/kidehen#this  Kingsley Idehen  http://identi.ca/user/14092
http://myopenlink.net/dataspace/person/kidehen#this  Kingsley Idehen  http://myopenlink.net/proxy?url=http%3A%2F%2Fwww.facebook.com%2Fpeople%2FKingsley_Idehen%2F605980750&amp;force=rdf&amp;login=kidehen

10 Rows. -- 181 msec.
</pre>
    </div>
<p>So if we have:</p>
<div>
      <pre class="programlisting">
&lt;http://myopenlink.net/dataspace/person/kidehen#this&gt;  	&lt;http://www.w3.org/2002/07/owl#sameAs&gt; &lt;http://www.openlinksw.com/dataspace/person/kidehen@openlinksw.com#this&gt; .
&lt;http://myopenlink.net/dataspace/person/kidehen#this&gt;  	&lt;http://xmlns.com/foaf/0.1/name&gt;  	Kingsley Idehen
</pre>
    </div>
<p>
and we instantiate <strong>?s &lt;http://xmlns.com/foaf/0.1/name&gt; &quot;Kingsley Idehen&quot;</strong>
we get <strong>?s</strong> bound to <strong>&lt;http://myopenlink.net/dataspace/person/kidehen#this&gt;</strong>.
</p>
<p>
If we instantiate <strong>&lt;http://www.openlinksw.com/dataspace/person/kidehen@openlinksw.com#this&gt;
&lt;http://xmlns.com/foaf/0.1/name&gt; ?l</strong>
we get <strong>?l</strong> bound to <strong>&quot;Kingsley Idehen&quot;</strong> because the subject was given and it was expanded to its synonyms.
</p>




<p>
If binding a variable in a pattern where the variable was free, we do not expand the value to the complete set of its synonyms.
</p>
<p>
Same-as expansion is enabled in a query by <strong>define input:same-as &quot;yes&quot;</strong> in the beginning of the SPARQL query.
This has a significant run time cost but is in some cases useful when joining data between sets which are mapped to each other with same-as.
</p>
<p>
We note that the number of same-as expansions will depend on the join order used for the SPARQL query.
The compiler does not know the number of synonyms and cannot set the join order accordingly.
Regardless of the join order we will however get at least one IRI of the each synonym set as answer.
Also when interactively navigating a graph with a browser, the same-as expansion will take all synonyms into account.
</p>
<p>
For getting the complete entailment of same-as, a forward
chaining approach should be used, effectively asserting all the
implied triples.
</p>
<a name="rdfsameasexmp" />
    <h4>14.13.5.1. OWL sameAs Example</h4>
<div>
      <pre class="programlisting">
SQL&gt;SPARQL
DEFINE input:same-as &quot;yes&quot;
SELECT *
WHERE
 {
   ?s &lt;http://xmlns.com/foaf/0.1/name&gt; &quot;Kingsley Idehen&quot; .
 }
LIMIT 10;

s
VARCHAR
___________________________________________________
http://myopenlink.net/dataspace/person/kidehen#this
http://myopenlink.net/dataspace/person/kidehen#this
http://myopenlink.net/dataspace/person/kidehen#this
http://myopenlink.net/dataspace/person/kidehen#this
http://myopenlink.net/dataspace/person/kidehen#this
http://myopenlink.net/dataspace/person/kidehen#this
http://demo.openlinksw.com/dataspace/kingsley#person
http://myopenlink.net/dataspace/person/kidehen#this
http://myopenlink.net/dataspace/person/kidehen#this
http://myopenlink.net/dataspace/person/kidehen#this
No. of rows in result: 10
</pre>
    </div>
<br />
<br />
<a name="rdfsparqlruleintro" />
    <h3>14.13.6. Implementation</h3>
<p>Triples entailed by subclass or subproperty statements in an inference context are not physically stored.
Such triples are added to the result set by the query run time as needed. Also queries involving subclass or subproperty
rules are not rewritten into unions of all the possible triple patterns that might imply the pattern that is requested.
Instead, the SQL compiler adds special nodes that iterate over subclasses or subproperties at run time. The cost model
also takes subclasses and subproperties into account when determining the approximate cardinality of triple patterns.
</p>
<p>In essence, Virtuoso&#39;s support for subclasses and subproperties is backward chaining, i.e. it does not materialize
all implied triples but rather looks for the basic facts implying these triples at query evaluation time.
</p>
<br />
<a name="rdfsparqlruleintro" />
    <h3>14.13.7. Enabling Inferencing</h3>
<p>In a SPARQL query, the define input:inference clause is used to instruct the compiler to use the rules in the named rule set. For example:
</p>
<div>
      <pre class="programlisting">
SQL&gt; rdfs_rule_set (&#39;sample&#39;, &#39;rule_graph&#39;);

SQL&gt; SPARQL
define input:inference &quot;sample&quot;
SELECT *
FROM &lt;g&gt;
WHERE {?s ?p ?o};
</pre>
    </div>
<p>will include all the implied triples in the result set, using the rules in the sample rule set.
</p>
<p>Inference can be enabled triple pattern by triple pattern. This is done with the option
(inference &#39;rule_set&#39;) clause after the triple pattern concerned. Specifying option (inference none)
will disable inference for the pattern concerned while the default inference context applies to the
rest of the patterns. Note that the keyword is input:inference in the query header and simply inference
in the option clause. See the examples section below for examples.
</p>
<p>In SQL, if RDF_QUAD occurs in a select from clause, inference can be added with the table option <strong>WITH</strong>, as follows:
</p>
<div>
      <pre class="programlisting">
SPARQL
SELECT *
FROM rdf_quad table OPTION (with &#39;sample&#39;)
WHERE g = iri_to_id (&#39;xx&#39;, 0);
</pre>
    </div>
<p>This is about the same as:
</p>
<div>
      <pre class="programlisting">
SPARQL
define input:inference &quot;sample&quot;
SELECT *
FROM &lt;xx&gt;
WHERE {?s ?p ?o}
</pre>
    </div>
<br />
<a name="rdfsparqlruleexamples" />
    <h3>14.13.8. Examples</h3>
<a name="rdfsparqlruleexamples1" />
    <h4>14.13.8.1. Example for loading data space instance data Triples
into a Named Graph for schema/ontology data</h4>
<p>The following example shows how to load data space instance data Triples
into a Named Graph: &lt;http://localhost:8890/test&gt;, for schema/ontology data called:
&lt;http://localhost:8890/schema/test&gt; that expresses assertions about subclasses and
subproperties.</p>
<div>
      <pre class="programlisting">
ttlp (&#39;
   &lt;http://localhost:8890/dataspace&gt;  	                        &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#type&gt;  &lt;http://rdfs.org/sioc/ns#Space&gt;.
   &lt;http://localhost:8890/dataspace/test2/weblog/test2tWeblog&gt;  &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#type&gt;  &lt;http://rdfs.org/sioc/types#Weblog&gt; .
   &lt;http://localhost:8890/dataspace/discussion/oWiki-test1Wiki&gt; &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#type&gt;  &lt;http://rdfs.org/sioc/types#MessageBoard&gt;.
   &lt;http://localhost:8890/dataspace&gt;                            &lt;http://rdfs.org/sioc/ns#link&gt;                     &lt;http://localhost:8890/ods&gt; .
   &lt;http://localhost:8890/dataspace/test2/weblog/test2tWeblog&gt;  &lt;http://rdfs.org/sioc/ns#link&gt;                     &lt;http://localhost:8890/dataspace/test2/weblog/test2tWeblog&gt;.
   &lt;http://localhost:8890/dataspace/discussion/oWiki-test1Wiki&gt; &lt;http://rdfs.org/sioc/ns#link&gt;                     &lt;http://localhost:8890/dataspace/discussion/oWiki-test1Wiki&gt; .
   &#39;, &#39;&#39;, &#39;http://localhost:8890/test&#39;);
</pre>
    </div>
<div>
      <pre class="programlisting">
ttlp (&#39; @prefix rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt; .
  &lt;http://rdfs.org/sioc/ns#Space&gt; rdfs:subClassOf &lt;http://www.w3.org/2000/01/rdf-schema#Resource&gt; .
  &lt;http://rdfs.org/sioc/ns#Container&gt; rdfs:subClassOf &lt;http://rdfs.org/sioc/ns#Space&gt; .
  &lt;http://rdfs.org/sioc/ns#Forum&gt; rdfs:subClassOf &lt;http://rdfs.org/sioc/ns#Container&gt; .
  &lt;http://rdfs.org/sioc/types#Weblog&gt; rdfs:subClassOf &lt;http://rdfs.org/sioc/ns#Forum&gt; .
  &lt;http://rdfs.org/sioc/types#MessageBoard&gt; rdfs:subClassOf &lt;http://rdfs.org/sioc/ns#Forum&gt; .
  &lt;http://rdfs.org/sioc/ns#link&gt; rdfs:subPropertyOf &lt;http://rdfs.org/sioc/ns&gt; .
  &#39;, &#39;&#39;, &#39;http://localhost:8890/schema/test&#39;);
</pre>
    </div>
<div>
      <pre class="programlisting">
rdfs_rule_set (&#39;http://localhost:8890/schema/property_rules1&#39;, &#39;http://localhost:8890/schema/test&#39;);
</pre>
    </div>
<p>This defines the rule context http://localhost:8890/schema/property_rules1 that is initialized
from the contents of graph http://localhost:8890/schema/test.
</p>
<div>
      <pre class="programlisting">
SQL&gt;SPARQL
define input:inference &quot;http://localhost:8890/schema/property_rules1&quot;
SELECT ?s
FROM &lt;http://localhost:8890/test&gt;
WHERE {?s &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#type&gt;  &lt;http://rdfs.org/sioc/ns#Space&gt; };
s
VARCHAR
_______________________________________________________________________________

http://localhost:8890/dataspace/test2/weblog/test2tWeblog
http://localhost:8890/dataspace/discussion/oWiki-test1Wiki
http://localhost:8890/dataspace

3 Rows. -- 0 msec.
</pre>
    </div>
<p>This returns the instances of http://rdfs.org/sioc/ns#Space. Since http://rdfs.org/sioc/types#Weblog
and http://rdfs.org/sioc/types#MessageBoard are subclasses of http://rdfs.org/sioc/ns#Space,
instances of http://rdfs.org/sioc/ns#Space, http://rdfs.org/sioc/types#Weblog and
http://rdfs.org/sioc/types#MessageBoard are all returned. This results in the subjects
http://localhost:8890/dataspace, http://localhost:8890/dataspace/test2/weblog/test2tWeblog and
http://localhost:8890/dataspace/discussion/oWiki-test1Wiki.
</p>
<div>
      <pre class="programlisting">
SQL&gt;SELECT id_to_iri (s)
FROM rdf_quad table option (with &#39;http://localhost:8890/schema/property_rules1&#39;)
WHERE g = iri_to_id (&#39;http://localhost:8890/test&#39;,0)
  AND p = iri_to_id (&#39;http://www.w3.org/1999/02/22-rdf-syntax-ns#type&#39;, 0)
  AND o = iri_to_id (&#39;http://rdfs.org/sioc/ns#Space&#39;, 0);
callret
VARCHAR
_______________________________________________________________________________

http://localhost:8890/dataspace/test2/weblog/test2tWeblog
http://localhost:8890/dataspace/discussion/oWiki-test1Wiki
http://localhost:8890/dataspace

3 Rows. -- 10 msec.
</pre>
    </div>
<p>This is the corresponding SQL query, internally generated by the SPARQL query.</p>
<p>Below we first look for all instances of http://rdfs.org/sioc/ns#Space with some
property set to http://localhost:8890/dataspace/test2/weblog/test2tWeblog.
We get the subject http://localhost:8890/dataspace/test2/weblog/test2tWeblog and the
properties http://rdfs.org/sioc/ns#link and http://rdfs.org/sioc/ns.
The join involves both subclass and subproperty inference. Then we turn off the inference
for the second pattern and only get the property http://rdfs.org/sioc/ns#link. Then we do
the same but now specify that inference should apply only to the first triple pattern.
</p>
<div>
      <pre class="programlisting">

SQL&gt;SPARQL
define input:inference  &quot;http://localhost:8890/schema/property_rules1&quot;
SELECT *
FROM &lt;http://localhost:8890/test&gt;
WHERE
  {
    ?s ?p &lt;http://rdfs.org/sioc/ns#Space&gt; .
    ?s ?p1 &lt;http://localhost:8890/dataspace/test2/weblog/test2tWeblog&gt; .
  };

s             p              p1
VARCHAR       VARCHAR       VARCHAR
_______________________________________________________________________________

http://localhost:8890/dataspace/test2/weblog/test2tWeblog  http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://rdfs.org/sioc/ns#link
http://localhost:8890/dataspace/test2/weblog/test2tWeblog  http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://rdfs.org/sioc/ns

2 Rows. -- 0 msec.


SQL&gt;SPARQL
SELECT *
FROM &lt;http://localhost:8890/test&gt;
WHERE
  {
    ?s ?p &lt;http://rdfs.org/sioc/ns#Space&gt; OPTION (inference &#39;http://localhost:8890/schema/property_rules1&#39;) .
    ?s ?p1 &lt;http://localhost:8890/dataspace/test2/weblog/test2tWeblog&gt; .
  };

s             p              p1
VARCHAR       VARCHAR        VARCHAR
_______________________________________________________________________________

http://localhost:8890/dataspace/test2/weblog/test2tWeblog  http://www.w3.org/1999/02/22-rdf-syntax-ns#type http://rdfs.org/sioc/ns#link

1 Rows. -- 10 msec.

</pre>
    </div>
<br />
<a name="rdfsparqlruleexamples2" />
    <h4>14.13.8.2. DBpedia example</h4>
<div>
      <pre class="programlisting">
ttlp (&#39;
 prefix rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt; .
 &lt;http://dbpedia.org/property/birthcity&gt; rdfs:subPropertyOf &lt;http://dbpedia.org/property/birthPlace&gt; .
 &lt;http://dbpedia.org/property/birthcountry&gt; rdfs:subPropertyOf  &lt;http://dbpedia.org/property/birthPlace&gt; .
 &lt;http://dbpedia.org/property/cityofbirth&gt; rdfs:subPropertyOf &lt;http://dbpedia.org/property/birthPlace&gt; .
 &lt;http://dbpedia.org/property/countryofbirth&gt; rdfs:subPropertyOf &lt;http://dbpedia.org/property/birthPlace&gt; .
 &lt;http://dbpedia.org/property/countyofbirth&gt; rdfs:subPropertyOf &lt;http://dbpedia.org/property/birthPlace&gt; .
 &lt;http://dbpedia.org/property/cityofdeath&gt; rdfs:subPropertyOf &lt;http://dbpedia.org/property/deathPlace&gt; .
 &lt;http://dbpedia.org/property/countryofdeath&gt; rdfs:subPropertyOf &lt;http://dbpedia.org/property/deathPlace&gt; . &#39;, &#39;&#39;,
 &#39;http://dbpedia.org/inference/rules#&#39;) ;

rdfs_rule_set (&#39;http://dbpedia.org/schema/property_rules1&#39;, &#39;http://dbpedia.org/inference/rules#&#39;);
</pre>
    </div>
<div>
      <pre class="programlisting">
SQL&gt;SPARQL
define input:inference &quot;http://dbpedia.org/schema/property_rules1&quot;
prefix p: &lt;http://dbpedia.org/property/&gt;
SELECT ?s
FROM &lt;http://dbpedia.org&gt;
WHERE {?s p:birthcity ?o }
LIMIT 50
s
VARCHAR
_______________________________________________________________________________

http://dbpedia.org/resource/Britt_Janyk
http://dbpedia.org/resource/Chiara_Costazza
http://dbpedia.org/resource/Christoph_Gruber
http://dbpedia.org/resource/Daron_Rahlves
http://dbpedia.org/resource/Finlay_Mickel
http://dbpedia.org/resource/Genevi%C3%A8ve_Simard
http://dbpedia.org/resource/Johann_Grugger
http://dbpedia.org/resource/Kalle_Palander
http://dbpedia.org/resource/Marc_Gini
http://dbpedia.org/resource/Mario_Scheiber
http://dbpedia.org/resource/Prince_Hubertus_of_Hohenlohe-Langenburg
http://dbpedia.org/resource/Resi_Stiegler
http://dbpedia.org/resource/Steven_Nyman
http://dbpedia.org/resource/Hannes_Reichelt
http://dbpedia.org/resource/Jeremy_Transue

15 Rows. -- 167 msec.

SQL&gt;SPARQL
define input:inference &quot;http://dbpedia.org/schema/property_rules1&quot;
prefix p: &lt;http://dbpedia.org/property/&gt;
SELECT ?s
FROM &lt;http://dbpedia.org&gt;
WHERE {?s p:countryofbirth ?o }
LIMIT 50
s
VARCHAR
_______________________________________________________________________________

http://dbpedia.org/resource/A._J._Wood
http://dbpedia.org/resource/A._J._Godbolt
http://dbpedia.org/resource/Ac%C3%A1cio_Casimiro
http://dbpedia.org/resource/Adam_Fry
http://dbpedia.org/resource/Adam_Gilchrist
http://dbpedia.org/resource/Adam_Griffin
http://dbpedia.org/resource/Adam_Gross
...

50 Rows. -- 324 msec.

SQL&gt;SPARQL
define input:inference &quot;http://dbpedia.org/schema/property_rules1&quot;
prefix p: &lt;http://dbpedia.org/property/&gt;
SELECT ?s
FROM &lt;http://dbpedia.org&gt;
WHERE {?s p:countyofbirth ?o }
LIMIT 50

s
VARCHAR
_______________________________________________________________________________

http://dbpedia.org/resource/Eddie_Colman

1 Rows. -- 163 msec.

SQL&gt;SPARQL
define input:inference &quot;http://dbpedia.org/schema/property_rules1&quot;
prefix p: &lt;http://dbpedia.org/property/&gt;
SELECT ?s
FROM &lt;http://dbpedia.org&gt;
WHERE {?s p:birthPlace ?o }

s
VARCHAR
_______________________________________________________________________________

http://dbpedia.org/resource/Eddie_Colman
http://dbpedia.org/resource/Jeremy_Transue
http://dbpedia.org/resource/Finlay_Mickel
http://dbpedia.org/resource/Prince_Hubertus_of_Hohenlohe-Langenburg
http://dbpedia.org/resource/Hannes_Reichelt
http://dbpedia.org/resource/Johann_Grugger
http://dbpedia.org/resource/Chiara_Costazza
...
155287 Rows. -- 342179 msec.

</pre>
    </div>
<br />
<a name="rdfsparqlruleexamples3" />
    <h4>14.13.8.3. Example for loading script of the Yago Class hierarchy as inference rules</h4>
<div>
      <pre class="programlisting">
--- Load Class Hierarchy into a Named Graph
SELECT ttlp_mt (file_to_string_output (&#39;yago-class-hierarchy_en.nt&#39;),
&#39;&#39;, &#39;http://dbpedia.org/resource/classes/yago#&#39;);

-- Create an  Inference Rule that references the Yago Class Hierarchy
Named Graph

SQL&gt;rdfs_rule_set (&#39;http://dbpedia.org/resource/inference/rules/yago#&#39;,
&#39;http://dbpedia.org/resource/classes/yago#&#39;);

-- Query for the &quot;The Lord of the Rings&quot; which is a &quot;Fantasy Novel&quot; as explicitly
-- claimed in the DBpedia data set (instance data)

SQL&gt;SPARQL
PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;
PREFIX dbpedia: &lt;http://dbpedia.org/property/&gt;
PREFIX yago: &lt;http://dbpedia.org/class/yago/&gt;
SELECT ?s
FROM &lt;http://dbpedia.org&gt;
WHERE
{
  ?s a &lt;http://dbpedia.org/class/yago/FantasyNovels&gt; .
  ?s dbpedia:name &quot;The Lord of the Rings&quot;@en .
};

s
VARCHAR
_______________________________________________________________________________

http://dbpedia.org/resource/The_Lord_of_the_Rings

1 Rows. -- 241 msec.

-- Query aimed at Novel via query scoped to the &quot;Fiction&quot; class of
-- which it is a subclass in the Yago Hierarchy
SQL&gt;SPARQL
define input:inference &quot;http://dbpedia.org/resource/inference/rules/yago#&quot;
PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;
PREFIX dbpedia: &lt;http://dbpedia.org/property/&gt;
PREFIX yago: &lt;http://dbpedia.org/class/yago/&gt;

SELECT ?s
FROM &lt;http://dbpedia.org&gt;
WHERE {
?s a &lt;http://dbpedia.org/class/yago/Fiction106367107&gt; .
?s dbpedia:name &quot;The Lord of the Rings&quot;@en .
};

s
VARCHAR
_______________________________________________________________________________


http://dbpedia.org/resource/The_Lord_of_the_Rings
http://dbpedia.org/resource/The_Lord_of_the_Rings
http://dbpedia.org/resource/The_Lord_of_the_Rings
http://dbpedia.org/resource/The_Lord_of_the_Rings

4 Rows. -- 4767 msec.


-- # Variant of query with Virtuoso&#39;s Full Text Index extension: bif:contains
SQL&gt;SPARQL
define input:inference &quot;http://dbpedia.org/resource/inference/rules/yago#&quot;
PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;
PREFIX dbpedia: &lt;http://dbpedia.org/property/&gt;
PREFIX yago: &lt;http://dbpedia.org/class/yago/&gt;

SELECT ?s ?n
FROM &lt;http://dbpedia.org&gt;
WHERE {
?s a &lt;http://dbpedia.org/class/yago/Fiction106367107&gt; .
?s dbpedia:name ?n .
?n bif:contains &#39;Lord and Rings&#39;
};

s                                                                                 n
VARCHAR                                                                           VARCHAR
_______________________________________________________________________________

http://dbpedia.org/resource/The_Lord_of_the_Rings                                 The Lord of the Rings
http://dbpedia.org/resource/The_Lord_of_the_Rings    The Lord of the Rings
http://dbpedia.org/resource/The_Lord_of_the_Rings    The Lord of the Rings
http://dbpedia.org/resource/The_Lord_of_the_Rings    The Lord of the Rings

4 Rows. -- 5538 msec.

-- Retrieve all individuals instances of the FantasyNovels Class
SQL&gt;SPARQL
PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;
PREFIX dbpedia: &lt;http://dbpedia.org/property/&gt;
PREFIX yago: &lt;http://dbpedia.org/class/yago/&gt;

SELECT ?s ?n
FROM &lt;http://dbpedia.org&gt;
WHERE
{
  ?s a &lt;http://dbpedia.org/class/yago/FantasyNovels&gt; .
  ?s dbpedia:name ?n .
}
limit 10;
s                                                                                 n
VARCHAR                                                                           VARCHAR
_______________________________________________________________________________

http://dbpedia.org/resource/ATLA_-_A_Story_of_the_Lost_Island                     Atla
http://dbpedia.org/resource/A_Crown_of_Swords                                     A Crown of Swords
http://dbpedia.org/resource/A_Game_of_Thrones                                     A Game of Thrones
http://dbpedia.org/resource/A_Secret_Atlas                                        A Secret Atlas
http://dbpedia.org/resource/A_Storm_of_Swords                                     A Storm of Swords
http://dbpedia.org/resource/A_Voyage_to_Arcturus                                  A Voyage to Arcturus
http://dbpedia.org/resource/A_Wizard_Alone                                        A Wizard Alone
http://dbpedia.org/resource/Above_the_Veil                                        Above the Veil
http://dbpedia.org/resource/Black_Easter                                          Black Easter
http://dbpedia.org/resource/Lord_of_Chaos                                         Lord of Chaos

10 Rows. -- 781 msec.

-- Retrieve all individuals instances of Fiction Class which should
-- include all Novels.
SQL&gt;SPARQL
define input:inference &quot;http://dbpedia.org/resource/inference/rules/yago#&quot;
PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;
PREFIX dbpedia: &lt;http://dbpedia.org/property/&gt;
PREFIX yago: &lt;http://dbpedia.org/class/yago/&gt;

SELECT ?s ?n
FROM &lt;http://dbpedia.org&gt;
WHERE {
?s a &lt;http://dbpedia.org/class/yago/Fiction106367107&gt; .
?s dbpedia:name ?n .
};
s                                                                                 n
VARCHAR                                                                           VARCHAR
_______________________________________________________________________________

http://dbpedia.org/resource/Last_Son_of_Krypton                                   Last Son of Krypton
http://dbpedia.org/resource/Tuvaluan_language                                     Tuvaluan
http://dbpedia.org/resource/Card_Walker                                           E. Cardon Walker
http://dbpedia.org/resource/Les_Clark                                             Les Clark
http://dbpedia.org/resource/Marc_Davis                                            Marc Davis
http://dbpedia.org/resource/Eric_Larson                                           Eric Larson
http://dbpedia.org/resource/Marty_Sklar                                           Marty Sklar
http://dbpedia.org/resource/Peter_Ellenshaw                                       Peter Ellenshaw
http://dbpedia.org/resource/Adriana_Caselotti                                     Adriana Caselotti
http://dbpedia.org/resource/Jimmie_Dodd                                           Jimmie Dodd
...
15296 Rows.
</pre>
    </div>
<br />
<a name="rdfsparqlruleexamples4" />
    <h4>14.13.8.4. Pure SPARQL Example</h4>
<div>
      <pre class="programlisting">
-- Query aimed at Fantasy Novel via query scoped to the &quot;Fiction&quot; class of
-- which it is a subclass in the Yago Hierarchy

SQL&gt;SPARQL
define input:inference &quot;http://dbpedia.org/resource/inference/rules/yago#&quot;
PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;
PREFIX dbpedia: &lt;http://dbpedia.org/property/&gt;
PREFIX yago: &lt;http://dbpedia.org/class/yago/&gt;
SELECT ?s
FROM &lt;http://dbpedia.org&gt;
WHERE {
?s a &lt;http://dbpedia.org/class/yago/Fiction106367107&gt; .
?s dbpedia:name &quot;The Lord of the Rings&quot;@en .
};
s
VARCHAR
_______________________________________________________________________________

http://dbpedia.org/resource/The_Lord_of_the_Rings
http://dbpedia.org/resource/The_Lord_of_the_Rings
http://dbpedia.org/resource/The_Lord_of_the_Rings
http://dbpedia.org/resource/The_Lord_of_the_Rings

4 Rows. -- 150 msec.
</pre>
    </div>
<br />
<a name="rdfsparqlruleexamples5" />
    <h4>14.13.8.5. Example for equivalence between classes</h4>
<p>This example is based on <a href="http://umbel.org/documentation.html">UMBEL</a> and
DBpedia integration:</p>
<div>
      <pre class="programlisting">
-- Load UMBEL &amp; DBpedia Instance Level Cross-Links (owl:sameAs) Triples
SELECT ttlp_mt (file_to_string_output (&#39;umbel_dbpedia_linkage_v071.n3&#39;), &#39;&#39;, &#39;http://dbpedia.org&#39;);

-- Load UMBEL and DBpedia Type (rdf:type) association Triples
SELECT ttlp_mt (file_to_string_output (&#39;umbel_dbpedia_types_v071.n3&#39;), &#39;&#39;, &#39;http://dbpedia.org&#39;);

--- Load UMBEL Subject Concept Class Hierarchy into a Named Graph
SELECT ttlp_mt (file_to_string_output (&#39;umbel_class_hierarchy_v071.n3&#39;), &#39;&#39;, &#39;http://dbpedia.org/resource/classes/umbel#&#39;);

--- load UMBEL Subject Concepts Instance Data
SELECT ttlp_mt (file_to_string_output (&#39;umbel_subject_concepts.n3&#39;), &#39;&#39;, &#39;http://dbpedia.org/resource/classes/umbel#&#39;);

--- Load UMBEL Abstract Concepts Instance Data
SELECT ttlp_mt (file_to_string_output (&#39;umbel_abstract_concepts.n3&#39;), &#39;&#39;, &#39;http://dbpedia.org/resource/classes/umbel#&#39;);


-- Load UMBEL External Ontology Mapping into a Named Graph
SELECT ttlp_mt (file_to_string_output (&#39;umbel_external_ontologies_linkage.n3&#39;), &#39;&#39;, &#39;http://dbpedia.org/resource/classes/umbel#&#39;);

-- Create UMBEL Inference Rules

rdfs_rule_set (&#39;http://dbpedia.org/resource/inference/rules/umbel#&#39;, &#39;http://dbpedia.org/resource/classes/umbel#&#39;);
</pre>
    </div>
<p>Now let&#39;s execute the following queries:</p>
<div>
      <pre class="programlisting">
SQL&gt;SPARQL define input:inference &quot;http://dbpedia.org/resource/inference/rules/umbel#&quot;
prefix umbel: &lt;http://umbel.org/umbel/sc/&gt;
PREFIX dbpedia: &lt;http://dbpedia.org/property/&gt;
prefix opencyc: &lt;http://sw.opencyc.org/2008/06/10/concept/en/&gt;
SELECT ?s
where
{
 ?s a opencyc:Motorcycle.
 ?s dbpedia:name ?n.
 ?n bif:contains &quot;BMW&quot;.
};

s
____________________________________________
http://dbpedia.org/resource/BMW_K1200GT
http://dbpedia.org/resource/BMW_F650CS
http://dbpedia.org/resource/BMW_C1
http://dbpedia.org/resource/BMW_R75
4 Rows. -- 26 msec.
</pre>
    </div>
<div>
      <pre class="programlisting">
SQL&gt;SPARQL define input:inference &quot;http://dbpedia.org/resource/inference/rules/umbel#&quot;
prefix umbel: &lt;http://umbel.org/umbel/sc/&gt;
PREFIX dbpedia: &lt;http://dbpedia.org/property/&gt;
prefix opencyc: &lt;http://sw.opencyc.org/2008/06/10/concept/en/&gt;
SELECT ?s
where
{
 ?s a umbel:Motorcycle.
 ?s dbpedia:name ?n.
 ?n bif:contains &quot;BMW&quot;.
};

s
____________________________________________
http://dbpedia.org/resource/BMW_K1200GT
http://dbpedia.org/resource/BMW_F650CS
http://dbpedia.org/resource/BMW_C1
http://dbpedia.org/resource/BMW_R75
4 Rows. -- 26 msec.
</pre>
    </div>
<br />
<a name="rdfsparqlruleexamples6" />
    <h4>14.13.8.6. Example for finding celebrities which are not fans of their own fans</h4>
<div>
      <pre class="programlisting">
SQL&gt;SPARQL
PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;
PREFIX rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt;
PREFIX sioc: &lt;http://rdfs.org/sioc/ns#&gt;
INSERT INTO GRAPH &lt;urn:rules.skos&gt; { foaf:knows rdfs:subPropertyOf sioc:follows . };

callret-0
VARCHAR
Insert into &lt;urn:rules.skos&gt;, 1 triples -- done
No. of rows in result: 1

SQL&gt;rdfs_rule_set (&#39;foaf-trans&#39;, &#39;urn:rules.skos&#39;);

Done.

SPARQL&gt;SPARQL
DEFINE input:inference &quot;foaf-trans&quot;
PREFIX sioc: &lt;http://rdfs.org/sioc/ns#&gt;
SELECT ?celeb COUNT (*)
WHERE
  {
    ?claimant sioc:follows ?celeb .
    FILTER
      (
        !bif:exists
         (
           ( SELECT (1)
             WHERE
               {
                 ?celeb sioc:follows ?claimant
               }
           )
         )
      )
  }
GROUP BY ?celeb
ORDER BY DESC 2
LIMIT 10

celeb                                                                            callret-1
ANY 	                                                                         ANY
__________________________________________________________________________________________
http://localhost.localdomain/about/id/entity/http/twitter.com/kidehen	         100
http://localhost.localdomain/about/id/entity/http/twitter.com/shawnafennell	 77
http://localhost.localdomain/about/id/entity/http/twitter.com/thines01	         71
http://localhost.localdomain/about/id/entity/http/twitter.com/mhausenblas	 50
http://localhost.localdomain/about/id/entity/http/twitter.com/DirDigEng	         2
http://localhost.localdomain/about/id/entity/http/twitter.com/SarahPalinUSA	 1
http://localhost.localdomain/about/id/entity/http/twitter.com/zbrox	         1
http://localhost.localdomain/about/id/entity/http/twitter.com/LamarLee	         1
http://localhost.localdomain/about/id/entity/http/twitter.com/HackerChick	 1
http://localhost.localdomain/about/id/entity/http/twitter.com/programmingfeed	 1
No. of rows in result: 10
</pre>
    </div>
<br />
<br />

  <a name="rdfsparqlruleinversefunc" />
    <h3>14.13.9. Identity With Inverse Functional Properties </h3>
  <p>A graph used used with rdfs_rule_set may declare certain properties to
  be inversely functional. If one or more inverse functional properties (IFP&#39;s)
  are declared in the inference context used with the query, enabled
  with define input:inference = &quot;context_name&quot;, then the following
  semantics apply:</p>
  <ol>
      <li>If a literal is compared with an IRI, then the literal is substituted by all the subject IRI&#39;s where this literal occurs as a value of an IFP.</li>
      <li>If two IRI&#39;s are compared for equality, they will be considered the same if there is an IFP P such that the same P has the same value on both subjects.</li>
      <li>If an IRI is processed for distinctness in either distinct or group by, the IRI is first translated to be the IRI with the lowest ID among all IRI&#39;s that share an IFP value with this IRI.</li>
    </ol>
  <p>Thus, if two IRI&#39;s are compared for distinctness, they will count as one if there is an IFP P with the same value with both IRI&#39;s. Literal data types are not translated into IRI&#39;s even if these literals occurred as IFP values of some subject.</p>
  <p>It is possible to declare that specific values, even if they occur as values of an IFP in more than onme subject do not constitute identity between the subjects.
  For example, if two subjects were inferred to be the same because they had the same foaf:mbox_sha1sum, the SHA1 hash of mailto:// would be excluded. Two individuals have an email address that has a common default value are not the same.
  </p>
  <p>In an ontology graph, a property IRI is declared to be inversely
  functional by making it an instance of the
  owl:InverseFunctionalProperty class. A value of an IFP can be
  declared null, i.e. sharing the value does not imply identity by by
  giving the IFP IRI a
  &lt;http://www.openlinksw.com/schemas/virtrdf#nullIFPValue&gt; property with
  the value to be ignored as the object.
  </p>
  <strong>Example</strong>
  <div>
      <pre class="programlisting">
  SQL&gt;ttlp (&#39;
  &lt;john1&gt; a &lt;person&gt; .
  &lt;john2&gt; a &lt;person&gt; .
  &lt;mary&gt; a &lt;person&gt; .
  &lt;mike&gt; a &lt;person&gt; .
  &lt;john1&gt; &lt;name&gt; &quot;John&quot; .
  &lt;john2&gt; &lt;name&gt; &quot;John&quot; .
  &lt;john1&gt; &lt;address&gt; &quot;101 A street&quot; .
  &lt;john2&gt; &lt;address&gt; &quot;102 B street&quot; .
  &lt;john2&gt; &lt;knows&gt; &lt;mike&gt; .
  &lt;john1&gt; &lt;http://www.w3.org/2002/07/owl#sameAs&gt; &lt;john2&gt; .
  &lt;mary&gt; &lt;knows&gt; &quot;John&quot; .
  &lt;mike&gt; &lt;knows&gt; &lt;john1&gt; .
  &lt;mike&gt; &lt;knows&gt; &lt;john2&gt; .
  &lt;john1&gt; &lt;name&gt; &quot;Tarzan&quot; .
  &lt;mike&gt; &lt;nam&gt; &quot;Tarzan&quot; .
  &#39;, &#39;&#39;, &#39;ifps&#39;);


  SQL&gt;ttlp (&#39;
  &lt;name&gt; a &lt;http://www.w3.org/2002/07/owl#InverseFunctionalProperty&gt; .
  &lt;name&gt; &lt;http://www.openlinksw.com/schemas/virtrdf#nullIFPValue&gt; &quot;Tarzan&quot; .
  &#39;, &#39;&#39;, &#39;ifp_list&#39;);

  SQL&gt;rdfs_rule_set (&#39;ifps&#39;, &#39;ifp_list&#39;);

  SQL&gt;SPARQL define input:inference &quot;ifps&quot;  SELECT * FROM &lt;ifps&gt; WHERE {&lt;john1&gt; ?p ?o};

  p                                                                                 o
  VARCHAR                                                                           VARCHAR
  _______________________________________________________________________________

  address                                                                           101 A street
  name                                                                              John
  http://www.w3.org/2002/07/owl#sameAs                                              john2
  http://www.w3.org/1999/02/22-rdf-syntax-ns#type                                   person
  name                                                                              Tarzan
  name                                                                              John
  knows                                                                             mike
  http://www.w3.org/1999/02/22-rdf-syntax-ns#type                                   person
  address                                                                           102 B street
  </pre>
    </div>
  <p>We see that we get the properties of &lt;john2&gt; also.</p>
  <div>
      <pre class="programlisting">
  SQL&gt;SPARQL define input:inference &quot;ifps&quot; SELECT distinct ?p FROM &lt;ifps&gt; WHERE { ?p a &lt;person&gt;};

  john2
  mike
  mary
  </pre>
    </div>
  <p>We see that we get only one John. But John is not the same as Mike
  because they share the name Tarzan which is not considered as implying
  identity. Which John we get is a matter of which gets the lowest
  internal ID. This is variable and arbitrary at load time but once
  loaded this is permanent as long as the set of subjects with the name
  John does not change.</p>
  <br />
  <a name="rdfsparqlruletransoption" />
    <h3>14.13.10. Inference Rules and SPARQL with Transitivity Option</h3>
<ul>
  <li>See <a href="rdfsparql.html#rdfsparqlimplementatiotransexamples7">example</a> with an
inference rule to cater data being skos:broader based, which is no longer transitive.</li>
  <li>See <a href="rdfsparql.html#rdfsparqlimplementatiotransexamples8">example</a> with an
inference rule to find entities that are subcategories of Protestant Churches, no deeper
than 3 levels within the concept scheme hierarchy, filtered by a specific subcategory.</li>
</ul>
  <br />
  <a name="rdfsparqlruleowlrelation" />
    <h3>14.13.11. Inference Rules, OWL Support and Relationship Ontology</h3>
    <p>This section provides queries usage for inference rules, owl support and Relationship Vocabulary.</p>
    <a name="rdfsparqlruleowlrelationexample1" />
    <h4>14.13.11.1. Example 1</h4>
<p>Example based on Relationship Vocab:</p>
<div>
      <pre class="programlisting">
## Verify Ontology Data is in Quad Store
## Ontology: &lt;http://vocab.org/relationship/&gt; (Relationship Ontology)
## Use pragma to put latest in Quad store.

DEFINE get:soft &quot;replace&quot;
SELECT *
FROM &lt;http://vocab.org/relationship/&gt;
WHERE {?s ?p ?o}

## Clean up

CLEAR GRAPH &lt;urn:owl.tests&gt;

## Create Instance Data for Relationship Ontology
PREFIX rel: &lt;http://purl.org/vocab/relationship/&gt;

INSERT into GRAPH &lt;urn:owl.tests&gt;
  {
    &lt;http://dbpedia.org/resource/Prince_William_of_Wales&gt; rel:siblingOf &lt;http://dbpedia.org/resource/Prince_Harry_of_Wales&gt;.
    &lt;http://dbpedia.org/resource/Elizabeth_Bowes-Lyon&gt; rel:ancestorOf &lt;http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom&gt;.
    &lt;http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom&gt; rel:ancestorOf
    &lt;http://dbpedia.org/resource/Charles%2C_Prince_of_Wales&gt;.
    &lt;http://dbpedia.org/resource/Charles%2C_Prince_of_Wales&gt; rel:ancestorOf &lt;http://dbpedia.org/resource/Prince_William_of_Wales&gt;.
  };

## Verify

SELECT *
FROM  &lt;urn:owl.tests&gt;
WHERE
  {
    ?s ?p ?o
  }

## Create an  Inference Rule that references the Relationship Ontology Named Graph

rdfs_rule_set (&#39;urn:owl.tests&#39;, &#39;http://vocab.org/relationship&#39;) ;

## Verify Rule&#39;s existence

SELECT * FROM sys_rdf_schema ;
</pre>
    </div>
    <br />
    <a name="rdfsparqlruleowlrelationexample2" />
    <h4>14.13.11.2. Example 2</h4>
<div>
      <pre class="programlisting">
## Test owl:TransitiveProperty Reasoning
## Start with a specific URI
## Goal: See inferred Triples
## In this case, relationship between: &lt;http://dbpedia.org/resource/Elizabeth_Bowes-Lyon&gt;
## and her descendants: Queen Elizabeth, Prince Charles, Prince William, and Prince Harry)


DEFINE input:inference &#39;urn:owl.tests&#39;
PREFIX rel: &lt;http://purl.org/vocab/relationship/&gt;
SELECT *
FROM &lt;urn:owl.tests&gt;
WHERE
  {
    &lt;http://dbpedia.org/resource/Elizabeth_Bowes-Lyon&gt; rel:ancestorOf ?o
  }
</pre>
    </div>
    <br />
    <a name="rdfsparqlruleowlrelationexample3" />
    <h4>14.13.11.3. Example 3</h4>
<div>
      <pre class="programlisting">
## Test owl:SymmetricalProperty Reasoning
## Should show same result irrespective of rel:siblingOf URI in Subject or Object slots of Triple

DEFINE input:inference &#39;urn:owl.tests&#39;
PREFIX rel: &lt;http://purl.org/vocab/relationship/&gt;
PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;

SELECT *
FROM &lt;urn:owl.tests&gt;
WHERE
  {
    &lt;http://dbpedia.org/resource/Prince_William_of_Wales&gt; rel:siblingOf ?o
  }

## OR

DEFINE input:inference &#39;urn:owl.tests&#39;
PREFIX rel: &lt;http://purl.org/vocab/relationship/&gt;
PREFIX foaf: &lt;http://xmlns.com/foaf/0.1/&gt;

SELECT *
FROM &lt;urn:owl.tests&gt;
WHERE
  {
    ?s rel:siblingOf &lt;http://dbpedia.org/resource/Prince_William_of_Wales&gt;
  }
</pre>
    </div>
    <br />
    <a name="rdfsparqlruleowlrelationexample4" />
    <h4>14.13.11.4. Example 4</h4>
<div>
      <pre class="programlisting">
## Test owl:inverseOf Reasoning
## Should show triples exposing the inverseOf relation.
## In this case rel:ancestorOf instance data triples exist,so the system must infer rel:descendant Of triples

DEFINE input:inference &#39;urn:owl.tests&#39;
PREFIX rel: &lt;http://purl.org/vocab/relationship/&gt;

SELECT *
FROM &lt;urn:owl.tests&gt;
WHERE
  {
    &lt;http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom&gt; rel:descendantOf ?o
  }

## OR with Transitivity Option applied

DEFINE input:inference &#39;urn:owl.tests&#39;
PREFIX rel: &lt;http://purl.org/vocab/relationship/&gt;

SELECT *
FROM &lt;urn:owl.tests&gt;
WHERE
  {
    &lt;http://dbpedia.org/resource/Prince_William_of_Wales&gt; rel:descendantOf ?o
    OPTION (T_DISTINCT)
  }
</pre>
    </div>
    <br />
    <a name="rdfsparqlruleowlrelationexample5" />
    <h4>14.13.11.5. Example 5</h4>
<div>
      <pre class="programlisting">
## Test owl:inverseOf Reasoning
## Should show triples exposing the inverseOf relation.
## In this case rel:employedBy instance data triples exist,
## the system must infer rel:employerOf triples.

DEFINE input:inference &#39;urn:owl.tests&#39;
PREFIX rel: &lt;http://purl.org/vocab/relationship/&gt;

SELECT *
FROM &lt;urn:owl.tests&gt;
WHERE
  {
    ?s rel:employerOf ?o
  }
</pre>
    </div>
    <br />
    <a name="rdfsparqlruleowlrelationexample6" />
    <h4>14.13.11.6. Example 6</h4>
<p>Example based on Relationship Vocab and SKOS</p>
<div>
      <pre class="programlisting">
## Graph Cleanup
CLEAR GRAPH &lt;urn:owl.test2.tbox&gt;
CLEAR GRAPH &lt;http://turnguard.com/virtuoso/test10.rdf&gt;

## Load Instance Data into Quad Store
## PL Procedure

## SQL realm
DB.DBA.RDF_LOAD_RDFXML
  (
    http_get(&#39;http://www.w3.org/2009/08/skos-reference/skos-owl1-dl.rdf&#39;),
    &#39;no&#39;,
    &#39;urn:owl.test2.tbox&#39;
  );
DB.DBA.RDF_LOAD_RDFXML
  (
    http_get (&#39;http://www.w3.org/2002/07/owl.rdf&#39;),
    &#39;no&#39;,
    &#39;urn:owl.test2.tbox&#39;
  );
DB.DBA.RDF_LOAD_RDFXML
  (
    http_get (&#39;http://turnguard.com/virtuoso/test10.rdf&#39;),
    &#39;no&#39;,
    &#39;http://turnguard.com/virtuoso/test10.rdf&#39;
  );



SELECT *
FROM &lt;http://www.w3.org/2004/02/skos/core&gt;
WHERE
  {
    {
      &lt;http://www.w3.org/2004/02/skos/core#related&gt; ?p ?o
    }
    UNION
    {
      ?s ?p &lt;http://www.w3.org/2004/02/skos/core#related&gt;
    }
  }


## Create Rules
## SQL Realm

rdfs_rule_set (&#39;urn:owl.test2.rules&#39;, &#39;urn:owl.test2.tbox&#39;);


## Transitivity Query re. SKOS concept hierarchy

DEFINE input:inference &quot;urn:owl.test2.rules&quot;
PREFIX skos: &lt;http://www.w3.org/2004/02/skos/core#&gt;

SELECT *
FROM &lt;http://turnguard.com/virtuoso/test10.rdf&gt;
WHERE
  {
    &lt;http://www.turnguard.com/ElectroPop&gt; skos:broaderTransitive ?o
    OPTION  (T_DISTINCT).
  }
</pre>
    </div>
    <br />
  <br />
<table border="0" width="90%" id="navbarbottom">
    <tr>
        <td align="left" width="33%">
          <a href="rdfiridereferencing.html" title="Linked Data">Previous</a>
          <br />Linked Data</td>
     <td align="center" width="34%">
          <a href="rdfandsparql.html">Chapter Contents</a>
     </td>
        <td align="right" width="33%">
          <a href="rdfsparqlgeospat.html" title="RDF and Geometry">Next</a>
          <br />RDF and Geometry</td>
    </tr>
    </table>
  </div>
  <div id="footer">
    <div>Copyright© 1999 - 2009 OpenLink Software All rights reserved.</div>
   <div id="validation">
    <a href="http://validator.w3.org/check/referer">
        <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" />
    </a>
    <a href="http://jigsaw.w3.org/css-validator/">
        <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" height="31" width="88" />
    </a>
   </div>
  </div>
 </body>
</html>