<!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 ; " /> <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 ; " /> <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 & 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 & 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'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>SPARQL prefix foaf: <http://xmlns.com/foaf/0.1/> prefix owl: <http://www.w3.org/2002/07/owl#> prefix sioc: <http://rdfs.org/sioc/ns#> SELECT * from <http://myopenlink.net/dataspace> where { ?person a foaf:Person FILTER REGEX(?person ,"http://myopenlink.net/dataspace/person/kidehen#this"). ?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&force=rdf&login=kidehen 10 Rows. -- 181 msec. </pre> </div> <p>So if we have:</p> <div> <pre class="programlisting"> <http://myopenlink.net/dataspace/person/kidehen#this> <http://www.w3.org/2002/07/owl#sameAs> <http://www.openlinksw.com/dataspace/person/kidehen@openlinksw.com#this> . <http://myopenlink.net/dataspace/person/kidehen#this> <http://xmlns.com/foaf/0.1/name> Kingsley Idehen </pre> </div> <p> and we instantiate <strong>?s <http://xmlns.com/foaf/0.1/name> "Kingsley Idehen"</strong> we get <strong>?s</strong> bound to <strong><http://myopenlink.net/dataspace/person/kidehen#this></strong>. </p> <p> If we instantiate <strong><http://www.openlinksw.com/dataspace/person/kidehen@openlinksw.com#this> <http://xmlns.com/foaf/0.1/name> ?l</strong> we get <strong>?l</strong> bound to <strong>"Kingsley Idehen"</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 "yes"</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>SPARQL DEFINE input:same-as "yes" SELECT * WHERE { ?s <http://xmlns.com/foaf/0.1/name> "Kingsley Idehen" . } 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'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> rdfs_rule_set ('sample', 'rule_graph'); SQL> SPARQL define input:inference "sample" SELECT * FROM <g> 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 'rule_set') 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 'sample') WHERE g = iri_to_id ('xx', 0); </pre> </div> <p>This is about the same as: </p> <div> <pre class="programlisting"> SPARQL define input:inference "sample" SELECT * FROM <xx> 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: <http://localhost:8890/test>, for schema/ontology data called: <http://localhost:8890/schema/test> that expresses assertions about subclasses and subproperties.</p> <div> <pre class="programlisting"> ttlp (' <http://localhost:8890/dataspace> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdfs.org/sioc/ns#Space>. <http://localhost:8890/dataspace/test2/weblog/test2tWeblog> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdfs.org/sioc/types#Weblog> . <http://localhost:8890/dataspace/discussion/oWiki-test1Wiki> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdfs.org/sioc/types#MessageBoard>. <http://localhost:8890/dataspace> <http://rdfs.org/sioc/ns#link> <http://localhost:8890/ods> . <http://localhost:8890/dataspace/test2/weblog/test2tWeblog> <http://rdfs.org/sioc/ns#link> <http://localhost:8890/dataspace/test2/weblog/test2tWeblog>. <http://localhost:8890/dataspace/discussion/oWiki-test1Wiki> <http://rdfs.org/sioc/ns#link> <http://localhost:8890/dataspace/discussion/oWiki-test1Wiki> . ', '', 'http://localhost:8890/test'); </pre> </div> <div> <pre class="programlisting"> ttlp (' @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . <http://rdfs.org/sioc/ns#Space> rdfs:subClassOf <http://www.w3.org/2000/01/rdf-schema#Resource> . <http://rdfs.org/sioc/ns#Container> rdfs:subClassOf <http://rdfs.org/sioc/ns#Space> . <http://rdfs.org/sioc/ns#Forum> rdfs:subClassOf <http://rdfs.org/sioc/ns#Container> . <http://rdfs.org/sioc/types#Weblog> rdfs:subClassOf <http://rdfs.org/sioc/ns#Forum> . <http://rdfs.org/sioc/types#MessageBoard> rdfs:subClassOf <http://rdfs.org/sioc/ns#Forum> . <http://rdfs.org/sioc/ns#link> rdfs:subPropertyOf <http://rdfs.org/sioc/ns> . ', '', 'http://localhost:8890/schema/test'); </pre> </div> <div> <pre class="programlisting"> rdfs_rule_set ('http://localhost:8890/schema/property_rules1', 'http://localhost:8890/schema/test'); </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>SPARQL define input:inference "http://localhost:8890/schema/property_rules1" SELECT ?s FROM <http://localhost:8890/test> WHERE {?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://rdfs.org/sioc/ns#Space> }; 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>SELECT id_to_iri (s) FROM rdf_quad table option (with 'http://localhost:8890/schema/property_rules1') WHERE g = iri_to_id ('http://localhost:8890/test',0) AND p = iri_to_id ('http://www.w3.org/1999/02/22-rdf-syntax-ns#type', 0) AND o = iri_to_id ('http://rdfs.org/sioc/ns#Space', 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>SPARQL define input:inference "http://localhost:8890/schema/property_rules1" SELECT * FROM <http://localhost:8890/test> WHERE { ?s ?p <http://rdfs.org/sioc/ns#Space> . ?s ?p1 <http://localhost:8890/dataspace/test2/weblog/test2tWeblog> . }; 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>SPARQL SELECT * FROM <http://localhost:8890/test> WHERE { ?s ?p <http://rdfs.org/sioc/ns#Space> OPTION (inference 'http://localhost:8890/schema/property_rules1') . ?s ?p1 <http://localhost:8890/dataspace/test2/weblog/test2tWeblog> . }; 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 (' prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . <http://dbpedia.org/property/birthcity> rdfs:subPropertyOf <http://dbpedia.org/property/birthPlace> . <http://dbpedia.org/property/birthcountry> rdfs:subPropertyOf <http://dbpedia.org/property/birthPlace> . <http://dbpedia.org/property/cityofbirth> rdfs:subPropertyOf <http://dbpedia.org/property/birthPlace> . <http://dbpedia.org/property/countryofbirth> rdfs:subPropertyOf <http://dbpedia.org/property/birthPlace> . <http://dbpedia.org/property/countyofbirth> rdfs:subPropertyOf <http://dbpedia.org/property/birthPlace> . <http://dbpedia.org/property/cityofdeath> rdfs:subPropertyOf <http://dbpedia.org/property/deathPlace> . <http://dbpedia.org/property/countryofdeath> rdfs:subPropertyOf <http://dbpedia.org/property/deathPlace> . ', '', 'http://dbpedia.org/inference/rules#') ; rdfs_rule_set ('http://dbpedia.org/schema/property_rules1', 'http://dbpedia.org/inference/rules#'); </pre> </div> <div> <pre class="programlisting"> SQL>SPARQL define input:inference "http://dbpedia.org/schema/property_rules1" prefix p: <http://dbpedia.org/property/> SELECT ?s FROM <http://dbpedia.org> 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>SPARQL define input:inference "http://dbpedia.org/schema/property_rules1" prefix p: <http://dbpedia.org/property/> SELECT ?s FROM <http://dbpedia.org> 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>SPARQL define input:inference "http://dbpedia.org/schema/property_rules1" prefix p: <http://dbpedia.org/property/> SELECT ?s FROM <http://dbpedia.org> WHERE {?s p:countyofbirth ?o } LIMIT 50 s VARCHAR _______________________________________________________________________________ http://dbpedia.org/resource/Eddie_Colman 1 Rows. -- 163 msec. SQL>SPARQL define input:inference "http://dbpedia.org/schema/property_rules1" prefix p: <http://dbpedia.org/property/> SELECT ?s FROM <http://dbpedia.org> 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 ('yago-class-hierarchy_en.nt'), '', 'http://dbpedia.org/resource/classes/yago#'); -- Create an Inference Rule that references the Yago Class Hierarchy Named Graph SQL>rdfs_rule_set ('http://dbpedia.org/resource/inference/rules/yago#', 'http://dbpedia.org/resource/classes/yago#'); -- Query for the "The Lord of the Rings" which is a "Fantasy Novel" as explicitly -- claimed in the DBpedia data set (instance data) SQL>SPARQL PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX dbpedia: <http://dbpedia.org/property/> PREFIX yago: <http://dbpedia.org/class/yago/> SELECT ?s FROM <http://dbpedia.org> WHERE { ?s a <http://dbpedia.org/class/yago/FantasyNovels> . ?s dbpedia:name "The Lord of the Rings"@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 "Fiction" class of -- which it is a subclass in the Yago Hierarchy SQL>SPARQL define input:inference "http://dbpedia.org/resource/inference/rules/yago#" PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX dbpedia: <http://dbpedia.org/property/> PREFIX yago: <http://dbpedia.org/class/yago/> SELECT ?s FROM <http://dbpedia.org> WHERE { ?s a <http://dbpedia.org/class/yago/Fiction106367107> . ?s dbpedia:name "The Lord of the Rings"@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's Full Text Index extension: bif:contains SQL>SPARQL define input:inference "http://dbpedia.org/resource/inference/rules/yago#" PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX dbpedia: <http://dbpedia.org/property/> PREFIX yago: <http://dbpedia.org/class/yago/> SELECT ?s ?n FROM <http://dbpedia.org> WHERE { ?s a <http://dbpedia.org/class/yago/Fiction106367107> . ?s dbpedia:name ?n . ?n bif:contains 'Lord and Rings' }; 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>SPARQL PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX dbpedia: <http://dbpedia.org/property/> PREFIX yago: <http://dbpedia.org/class/yago/> SELECT ?s ?n FROM <http://dbpedia.org> WHERE { ?s a <http://dbpedia.org/class/yago/FantasyNovels> . ?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>SPARQL define input:inference "http://dbpedia.org/resource/inference/rules/yago#" PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX dbpedia: <http://dbpedia.org/property/> PREFIX yago: <http://dbpedia.org/class/yago/> SELECT ?s ?n FROM <http://dbpedia.org> WHERE { ?s a <http://dbpedia.org/class/yago/Fiction106367107> . ?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 "Fiction" class of -- which it is a subclass in the Yago Hierarchy SQL>SPARQL define input:inference "http://dbpedia.org/resource/inference/rules/yago#" PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> PREFIX dbpedia: <http://dbpedia.org/property/> PREFIX yago: <http://dbpedia.org/class/yago/> SELECT ?s FROM <http://dbpedia.org> WHERE { ?s a <http://dbpedia.org/class/yago/Fiction106367107> . ?s dbpedia:name "The Lord of the Rings"@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 & DBpedia Instance Level Cross-Links (owl:sameAs) Triples SELECT ttlp_mt (file_to_string_output ('umbel_dbpedia_linkage_v071.n3'), '', 'http://dbpedia.org'); -- Load UMBEL and DBpedia Type (rdf:type) association Triples SELECT ttlp_mt (file_to_string_output ('umbel_dbpedia_types_v071.n3'), '', 'http://dbpedia.org'); --- Load UMBEL Subject Concept Class Hierarchy into a Named Graph SELECT ttlp_mt (file_to_string_output ('umbel_class_hierarchy_v071.n3'), '', 'http://dbpedia.org/resource/classes/umbel#'); --- load UMBEL Subject Concepts Instance Data SELECT ttlp_mt (file_to_string_output ('umbel_subject_concepts.n3'), '', 'http://dbpedia.org/resource/classes/umbel#'); --- Load UMBEL Abstract Concepts Instance Data SELECT ttlp_mt (file_to_string_output ('umbel_abstract_concepts.n3'), '', 'http://dbpedia.org/resource/classes/umbel#'); -- Load UMBEL External Ontology Mapping into a Named Graph SELECT ttlp_mt (file_to_string_output ('umbel_external_ontologies_linkage.n3'), '', 'http://dbpedia.org/resource/classes/umbel#'); -- Create UMBEL Inference Rules rdfs_rule_set ('http://dbpedia.org/resource/inference/rules/umbel#', 'http://dbpedia.org/resource/classes/umbel#'); </pre> </div> <p>Now let's execute the following queries:</p> <div> <pre class="programlisting"> SQL>SPARQL define input:inference "http://dbpedia.org/resource/inference/rules/umbel#" prefix umbel: <http://umbel.org/umbel/sc/> PREFIX dbpedia: <http://dbpedia.org/property/> prefix opencyc: <http://sw.opencyc.org/2008/06/10/concept/en/> SELECT ?s where { ?s a opencyc:Motorcycle. ?s dbpedia:name ?n. ?n bif:contains "BMW". }; 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>SPARQL define input:inference "http://dbpedia.org/resource/inference/rules/umbel#" prefix umbel: <http://umbel.org/umbel/sc/> PREFIX dbpedia: <http://dbpedia.org/property/> prefix opencyc: <http://sw.opencyc.org/2008/06/10/concept/en/> SELECT ?s where { ?s a umbel:Motorcycle. ?s dbpedia:name ?n. ?n bif:contains "BMW". }; 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>SPARQL PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX sioc: <http://rdfs.org/sioc/ns#> INSERT INTO GRAPH <urn:rules.skos> { foaf:knows rdfs:subPropertyOf sioc:follows . }; callret-0 VARCHAR Insert into <urn:rules.skos>, 1 triples -- done No. of rows in result: 1 SQL>rdfs_rule_set ('foaf-trans', 'urn:rules.skos'); Done. SPARQL>SPARQL DEFINE input:inference "foaf-trans" PREFIX sioc: <http://rdfs.org/sioc/ns#> 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's) are declared in the inference context used with the query, enabled with define input:inference = "context_name", 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's where this literal occurs as a value of an IFP.</li> <li>If two IRI'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's that share an IFP value with this IRI.</li> </ol> <p>Thus, if two IRI's are compared for distinctness, they will count as one if there is an IFP P with the same value with both IRI's. Literal data types are not translated into IRI'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 <http://www.openlinksw.com/schemas/virtrdf#nullIFPValue> property with the value to be ignored as the object. </p> <strong>Example</strong> <div> <pre class="programlisting"> SQL>ttlp (' <john1> a <person> . <john2> a <person> . <mary> a <person> . <mike> a <person> . <john1> <name> "John" . <john2> <name> "John" . <john1> <address> "101 A street" . <john2> <address> "102 B street" . <john2> <knows> <mike> . <john1> <http://www.w3.org/2002/07/owl#sameAs> <john2> . <mary> <knows> "John" . <mike> <knows> <john1> . <mike> <knows> <john2> . <john1> <name> "Tarzan" . <mike> <nam> "Tarzan" . ', '', 'ifps'); SQL>ttlp (' <name> a <http://www.w3.org/2002/07/owl#InverseFunctionalProperty> . <name> <http://www.openlinksw.com/schemas/virtrdf#nullIFPValue> "Tarzan" . ', '', 'ifp_list'); SQL>rdfs_rule_set ('ifps', 'ifp_list'); SQL>SPARQL define input:inference "ifps" SELECT * FROM <ifps> WHERE {<john1> ?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 <john2> also.</p> <div> <pre class="programlisting"> SQL>SPARQL define input:inference "ifps" SELECT distinct ?p FROM <ifps> WHERE { ?p a <person>}; 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: <http://vocab.org/relationship/> (Relationship Ontology) ## Use pragma to put latest in Quad store. DEFINE get:soft "replace" SELECT * FROM <http://vocab.org/relationship/> WHERE {?s ?p ?o} ## Clean up CLEAR GRAPH <urn:owl.tests> ## Create Instance Data for Relationship Ontology PREFIX rel: <http://purl.org/vocab/relationship/> INSERT into GRAPH <urn:owl.tests> { <http://dbpedia.org/resource/Prince_William_of_Wales> rel:siblingOf <http://dbpedia.org/resource/Prince_Harry_of_Wales>. <http://dbpedia.org/resource/Elizabeth_Bowes-Lyon> rel:ancestorOf <http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom>. <http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom> rel:ancestorOf <http://dbpedia.org/resource/Charles%2C_Prince_of_Wales>. <http://dbpedia.org/resource/Charles%2C_Prince_of_Wales> rel:ancestorOf <http://dbpedia.org/resource/Prince_William_of_Wales>. }; ## Verify SELECT * FROM <urn:owl.tests> WHERE { ?s ?p ?o } ## Create an Inference Rule that references the Relationship Ontology Named Graph rdfs_rule_set ('urn:owl.tests', 'http://vocab.org/relationship') ; ## Verify Rule'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: <http://dbpedia.org/resource/Elizabeth_Bowes-Lyon> ## and her descendants: Queen Elizabeth, Prince Charles, Prince William, and Prince Harry) DEFINE input:inference 'urn:owl.tests' PREFIX rel: <http://purl.org/vocab/relationship/> SELECT * FROM <urn:owl.tests> WHERE { <http://dbpedia.org/resource/Elizabeth_Bowes-Lyon> 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 'urn:owl.tests' PREFIX rel: <http://purl.org/vocab/relationship/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT * FROM <urn:owl.tests> WHERE { <http://dbpedia.org/resource/Prince_William_of_Wales> rel:siblingOf ?o } ## OR DEFINE input:inference 'urn:owl.tests' PREFIX rel: <http://purl.org/vocab/relationship/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT * FROM <urn:owl.tests> WHERE { ?s rel:siblingOf <http://dbpedia.org/resource/Prince_William_of_Wales> } </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 'urn:owl.tests' PREFIX rel: <http://purl.org/vocab/relationship/> SELECT * FROM <urn:owl.tests> WHERE { <http://dbpedia.org/resource/Elizabeth_II_of_the_United_Kingdom> rel:descendantOf ?o } ## OR with Transitivity Option applied DEFINE input:inference 'urn:owl.tests' PREFIX rel: <http://purl.org/vocab/relationship/> SELECT * FROM <urn:owl.tests> WHERE { <http://dbpedia.org/resource/Prince_William_of_Wales> 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 'urn:owl.tests' PREFIX rel: <http://purl.org/vocab/relationship/> SELECT * FROM <urn:owl.tests> 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 <urn:owl.test2.tbox> CLEAR GRAPH <http://turnguard.com/virtuoso/test10.rdf> ## Load Instance Data into Quad Store ## PL Procedure ## SQL realm DB.DBA.RDF_LOAD_RDFXML ( http_get('http://www.w3.org/2009/08/skos-reference/skos-owl1-dl.rdf'), 'no', 'urn:owl.test2.tbox' ); DB.DBA.RDF_LOAD_RDFXML ( http_get ('http://www.w3.org/2002/07/owl.rdf'), 'no', 'urn:owl.test2.tbox' ); DB.DBA.RDF_LOAD_RDFXML ( http_get ('http://turnguard.com/virtuoso/test10.rdf'), 'no', 'http://turnguard.com/virtuoso/test10.rdf' ); SELECT * FROM <http://www.w3.org/2004/02/skos/core> WHERE { { <http://www.w3.org/2004/02/skos/core#related> ?p ?o } UNION { ?s ?p <http://www.w3.org/2004/02/skos/core#related> } } ## Create Rules ## SQL Realm rdfs_rule_set ('urn:owl.test2.rules', 'urn:owl.test2.tbox'); ## Transitivity Query re. SKOS concept hierarchy DEFINE input:inference "urn:owl.test2.rules" PREFIX skos: <http://www.w3.org/2004/02/skos/core#> SELECT * FROM <http://turnguard.com/virtuoso/test10.rdf> WHERE { <http://www.turnguard.com/ElectroPop> 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>