blob: 879f67dcefaba1aa7b946ff5a6efefdb0379579f [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<title>Apache Jena - Data with RDFS Inferencing</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/css/bootstrap.min.css" rel="stylesheet" media="screen">
<link href="/css/bootstrap-extension.css" rel="stylesheet" type="text/css">
<link href="/css/jena.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" href="/images/favicon.ico" />
<script src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44="
crossorigin="anonymous"></script>
<script src="/js/jena-navigation.js" type="text/javascript"></script>
<script src="/js/bootstrap.min.js" type="text/javascript"></script>
<script src="/js/improve.js" type="text/javascript"></script>
</head>
<body>
<nav class="navbar navbar-default" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/index.html">
<img class="logo-menu" src="/images/jena-logo/jena-logo-notext-small.png" alt="jena logo">Apache Jena</a>
</div>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav">
<li id="homepage"><a href="/index.html"><span class="glyphicon glyphicon-home"></span> Home</a></li>
<li id="download"><a href="/download/index.cgi"><span class="glyphicon glyphicon-download-alt"></span> Download</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-book"></span> Learn <b class="caret"></b></a>
<ul class="dropdown-menu">
<li class="dropdown-header">Tutorials</li>
<li><a href="/tutorials/index.html">Overview</a></li>
<li><a href="/documentation/fuseki2/index.html">Fuseki Triplestore</a></li>
<li><a href="/documentation/notes/index.html">How-To's</a></li>
<li><a href="/documentation/query/manipulating_sparql_using_arq.html">Manipulating SPARQL using ARQ</a></li>
<li><a href="/tutorials/rdf_api.html">RDF core API tutorial</a></li>
<li><a href="/tutorials/sparql.html">SPARQL tutorial</a></li>
<li><a href="/tutorials/using_jena_with_eclipse.html">Using Jena with Eclipse</a></li>
<li class="divider"></li>
<li class="dropdown-header">References</li>
<li><a href="/documentation/index.html">Overview</a></li>
<li><a href="/documentation/query/index.html">ARQ (SPARQL)</a></li>
<li><a href="/documentation/assembler/index.html">Assembler</a></li>
<li><a href="/documentation/tools/index.html">Command-line tools</a></li>
<li><a href="/documentation/rdfs/">Data with RDFS Inferencing</a></li>
<li><a href="/documentation/geosparql/index.html">GeoSPARQL</a></li>
<li><a href="/documentation/inference/index.html">Inference API</a></li>
<li><a href="/documentation/javadoc.html">Javadoc</a></li>
<li><a href="/documentation/ontology/">Ontology API</a></li>
<li><a href="/documentation/permissions/index.html">Permissions</a></li>
<li><a href="/documentation/extras/querybuilder/index.html">Query Builder</a></li>
<li><a href="/documentation/rdf/index.html">RDF API</a></li>
<li><a href="/documentation/rdfconnection/">RDF Connection - SPARQL API</a></li>
<li><a href="/documentation/io/">RDF I/O</a></li>
<li><a href="/documentation/rdfstar/index.html">RDF-star</a></li>
<li><a href="/documentation/shacl/index.html">SHACL</a></li>
<li><a href="/documentation/shex/index.html">ShEx</a></li>
<li><a href="/documentation/jdbc/index.html">SPARQL over JDBC</a></li>
<li><a href="/documentation/tdb/index.html">TDB</a></li>
<li><a href="/documentation/tdb2/index.html">TDB2</a></li>
<li><a href="/documentation/query/text-query.html">Text Search</a></li>
</ul>
</li>
<li class="drop down">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-book"></span> Javadoc <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="/documentation/javadoc.html">All Javadoc</a></li>
<li><a href="/documentation/javadoc/arq/">ARQ</a></li>
<li><a href="/documentation/javadoc_elephas.html">Elephas</a></li>
<li><a href="/documentation/javadoc/fuseki2/">Fuseki</a></li>
<li><a href="/documentation/javadoc/geosparql/">GeoSPARQL</a></li>
<li><a href="/documentation/javadoc/jdbc/">JDBC</a></li>
<li><a href="/documentation/javadoc/jena/">Jena Core</a></li>
<li><a href="/documentation/javadoc/permissions/">Permissions</a></li>
<li><a href="/documentation/javadoc/extras/querybuilder/">Query Builder</a></li>
<li><a href="/documentation/javadoc/shacl/">SHACL</a></li>
<li><a href="/documentation/javadoc/tdb/">TDB</a></li>
<li><a href="/documentation/javadoc/text/">Text Search</a></li>
</ul>
</li>
<li id="ask"><a href="/help_and_support/index.html"><span class="glyphicon glyphicon-question-sign"></span> Ask</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-bullhorn"></span> Get involved <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="/getting_involved/index.html">Contribute</a></li>
<li><a href="/help_and_support/bugs_and_suggestions.html">Report a bug</a></li>
<li class="divider"></li>
<li class="dropdown-header">Project</li>
<li><a href="/about_jena/about.html">About Jena</a></li>
<li><a href="/about_jena/architecture.html">Architecture</a></li>
<li><a href="/about_jena/citing.html">Citing</a></li>
<li><a href="/about_jena/team.html">Project team</a></li>
<li><a href="/about_jena/contributions.html">Related projects</a></li>
<li><a href="/about_jena/roadmap.html">Roadmap</a></li>
<li class="divider"></li>
<li class="dropdown-header">ASF</li>
<li><a href="http://www.apache.org/">Apache Software Foundation</a></li>
<li><a href="http://www.apache.org/foundation/sponsorship.html">Become a Sponsor</a></li>
<li><a href="http://www.apache.org/licenses/LICENSE-2.0">License</a></li>
<li><a href="http://www.apache.org/security/">Security</a></li>
<li><a href="http://www.apache.org/foundation/thanks.html">Thanks</a></li>
</ul>
</li>
<li id="edit"><a href="https://github.com/apache/jena-site/edit/main/source/documentation/rdfs/__index.md" title="Edit this page on GitHub"><span class="glyphicon glyphicon-pencil"></span> Edit this page</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-12">
<div id="breadcrumbs">
<ol class="breadcrumb">
<li><a href='/documentation'>DOCUMENTATION</a></li>
<li class="active">RDFS</li>
</ol>
</div>
<h1 class="title">Data with RDFS Inferencing</h1>
<p>This page describes support for accessing data with additional statements
derived using RDFS. It supports <code>rdfs:subClassOf</code>, <code>rdfs:subPropertyOf</code>, <code>rdfs:domain</code> and <code>rdfs:range</code>. It
does not provide RDF axioms. The RDFS vocabulary is not included in the data.</p>
<p>It does support use with RDF datasets, where each graph in the dataset has the
same RDFS vocabulary applied to it.</p>
<p>This is not a replacement for the <a href="/inference/">Jena RDFS Reasoner support</a>
which covers full RDFS inference.</p>
<p>The data is updateable, and graphs can be added and removed from the dataset.
The vocabulary can not be changed during the lifetime of the RDFS dataset.</p>
<h3 id="api-rdfsfactory">API: <code>RDFSFactory</code></h3>
<p>The API provides operation to build RDF-enabled datasets from data storage and vocabularies:</p>
<p>Example:</p>
<pre><code> DatasetGraph data = ...
// Load the vocabulary
Graph vocab = RDFDataMgr.loadGraph(&quot;vocabulary.ttl&quot;);
// Create a DatasetGraph with RDFS
DatasetGraph dsg = datasetRDFS(DatasetGraph data, Graph vocab );
// (Optional) Present as a Dataset.
Dataset dataset = DatasetFactory.wrap(dsg);
</code></pre><p>The vocabulary is processed to produce datastructure needed for processing the
data eficiently at run time. This is the <code>SetupRDFS</code> class that can be created
and shared; it is thread-safe.</p>
<pre><code> SetupRDFS setup = setupRDFS(vocab);
</code></pre><h3 id="assembler-rdfs-dataset">Assembler: RDFS Dataset</h3>
<p>Datasets with RDFS can be built with an assembler:</p>
<pre><code>&lt;#rdfsDS&gt; rdf:type ja:DatasetRDFS ;
ja:rdfsSchema &lt;vocabulary.ttl&gt;;
ja:dataset &lt;#baseDataset&gt; ;
.
&lt;#baseDataset&gt; rdf:type ...some dataset type ... ;
...
.
</code></pre><p>where <code>&lt;#baseDataset&gt;</code> is the definition of the dataset to be enriched.</p>
<h3 id="assembler-rdfs-graph">Assembler: RDFS Graph</h3>
<p>It is possible to build a single <code>Model</code>:</p>
<pre><code> &lt;#rdfsGraph&gt; rdf:type ja:GraphRDFS ;
ja:rdfsSchema &lt;vocabulary.ttl&gt;;
ja:graph &lt;#baseGraph&gt; ;
.
&lt;#baseGraph&gt; rdf:type ja:MemoryModel;
...
</code></pre><p>More generally, inference models can be defined using the Jena Inference and Rule
engine:
<a href="https://github.com/apache/jena/tree/main/jena-fuseki2/examples/config-inference-1.ttl">jena-fuseki2/examples/config-inference-1.ttl</a>.</p>
<h2 id="use-with-fuseki">Use with Fuseki</h2>
<p>The files for this example are available at:
<a href="https://github.com/apache/jena/tree/main/jena-fuseki2/examples/rdfs">jena-fuseki2/examples/rdfs</a>.</p>
<p>From the command line (here, loading data from a file into an in-memory dataset):</p>
<pre><code>fuseki-server --data data.trig --rdfs vocabulary.ttl /dataset
</code></pre><p>or from a configuration file with an RDFS Dataset:</p>
<pre><code>PREFIX : &lt;#&gt;
PREFIX fuseki: &lt;http://jena.apache.org/fuseki#&gt;
PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;
PREFIX rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt;
PREFIX ja: &lt;http://jena.hpl.hp.com/2005/11/Assembler#&gt;
[] rdf:type fuseki:Server ;
fuseki:services (
:service
) .
## Fuseki service /dataset with SPARQ query
## /dataset?query=
:service rdf:type fuseki:Service ;
fuseki:name &quot;dataset&quot; ;
fuseki:endpoint [ fuseki:operation fuseki:query ] ;
fuseki:endpoint [ fuseki:operation fuseki:update ] ;
fuseki:dataset :rdfsDataset ;
.
## RDFS
:rdfsDataset rdf:type ja:DatasetRDFS ;
ja:rdfsSchema &lt;file:vocabulary.ttl&gt;;
ja:dataset :baseDataset;
.
## Transactional in-memory dataset.
:baseDataset rdf:type ja:MemoryDataset ;
ja:data &lt;file:data.trig&gt;;
.
</code></pre><h3 id="querying-the-fuseki-server">Querying the Fuseki server</h3>
<p>With the <a href="/documentation/fuseki2/soh.html">SOH</a> tools, a query (asking for plain
text output):</p>
<pre><code>s-query --service http://localhost:3030/dataset --output=text --file query.rq
</code></pre><p>or with <code>curl</code>:</p>
<pre><code>curl --data @query.rq \
--header 'Accept: text/plain' \
--header 'Content-type: application/sparql-query' \
http://localhost:3030/dataset
</code></pre><p>will return:</p>
<pre><code>-------------------------
| s | p | o |
=========================
| :s | ns:p | :o |
| :s | rdf:type | ns:D |
| :o | rdf:type | ns:T1 |
| :o | rdf:type | ns:T3 |
| :o | rdf:type | ns:T2 |
-------------------------
</code></pre><h3 id="files">Files</h3>
<p>data.trig:</p>
<pre><code>PREFIX : &lt;http://example/&gt;
PREFIX ns: &lt;http://example/ns#&gt;
:s ns:p :o .
</code></pre><p><code>vocabulary.ttl</code>:</p>
<pre><code>PREFIX xsd: &lt;http://www.w3.org/2001/XMLSchema#&gt;
PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;
PREFIX rdfs: &lt;http://www.w3.org/2000/01/rdf-schema#&gt;
PREFIX skos: &lt;http://www.w3.org/2008/05/skos#&gt;
PREFIX list: &lt;http://jena.hpl.hp.com/ARQ/list#&gt;
PREFIX ns: &lt;http://example/ns#&gt;
ns:T1 rdfs:subClassOf ns:T2 .
ns:T2 rdfs:subClassOf ns:T3 .
ns:p rdfs:domain ns:D .
ns:p rdfs:range ns:T1 .
</code></pre><p><code>query.rq</code>:</p>
<pre><code>PREFIX : &lt;http://example/&gt;
PREFIX ns: &lt;http://example/ns#&gt;
PREFIX rdf: &lt;http://www.w3.org/1999/02/22-rdf-syntax-ns#&gt;
SELECT * { ?s ?p ?o }
</code></pre>
</div>
</div>
</div>
<footer class="footer">
<div class="container" style="font-size:80%" >
<p>
Copyright &copy; 2011&ndash;2022 The Apache Software Foundation, Licensed under the
<a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.
</p>
<p>
Apache Jena, Jena, the Apache Jena project logo, Apache and the Apache feather logos are trademarks of
The Apache Software Foundation.
<br/>
<a href="https://privacy.apache.org/policies/privacy-policy-public.html"
>Apache Software Foundation Privacy Policy</a>.
</p>
</div>
</footer>
<script type="text/javascript">
var link = $('a[href="' + this.location.pathname + '"]');
if (link != undefined)
link.parents('li,ul').addClass('active');
</script>
</body>
</html>