2. +
Disclaimer
License
This work is licensed under a
Creative Commons Attribution-Share Alike 3.0 License
(http://creativecommons.org/licenses/by-sa/3.0/)
5. +
Jena
Jena allows for a range of reasoners
Main objective: support RDFS and OWL
Pre-canned reasoning in the Ontology API
However, support is general, i.e.:
Generic inference rule engine
Support for arbitrary, rule-based processing of RDF
6. +
Ontology Model (the simple way)
A normal model that is aware of
inferences
Convenience methods to
access inference related
functionality
Simple recipes for reasoning in
different laguages
7. +
Creating ontology models
OntModel m =
ModelFactory.createOntologyModel();
Default ontology model:
in-memory storage
OWL-Full
RDFS inference
Hence a default OntModel is less performant than
a simple Graph
8. +
Ontology Models for specific
languages
OntModel m = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM );
Languages available:
OntModelSpec.OWL_DL_MEM
OntModelSpec.OWL_DL_MEM_RDFS_INF
…
OntModelSpec.OWL_LITE_MEM
OntModelSpec.OWL_LITE_MEM_RDFS_INF
…
OntModelSpec.OWL_MEM
OntModelSpec.OWL_MEM_MICRO_RULE_INF
OntModelSpec.OWL_MEM_MINI_RULE_INF
OntModelSpec.OWL_MEM_RDFS_INF
OntModelSpec.OWL_MEM_RULE_INF
OntModelSpec.RDFS_MEM
OntModelSpec.RDFS_MEM_RDFS_INF
OntModelSpec.RDFS_MEM_TRANS_INF
9. +
Asserted vs. Infered
OntModel base = ModelFactory.createOntologyModel( OWL_MEM );
base.read( SOURCE, "RDF/XML" );
// create the reasoning model using the base
OntModel inf = ModelFactory.createOntologyModel(
OWL_MEM_MICRO_RULE_INF, base );
// create a dummy paper for this example
OntClass paper = base.getOntClass( NS + "Paper" );
Individual p1 = base.createIndividual( NS + "paper1", paper );
// list the asserted types
for (Iterator<Resource> i = p1.listRDFTypes(); i.hasNext(); ) {
System.out.println( p1.getURI() + " is asserted in class " + i.next() );
}
// list the inferred types
p1 = inf.getIndividual( NS + "paper1" );
for (Iterator<Resource> i = p1.listRDFTypes(); i.hasNext(); ) {
System.out.println( p1.getURI() + " is inferred to be in class " + i.next() );
}
11. +
Overview
Model Factory: entry point
Using a reasoner and a Model
we create an “Inferred Graph”
Queries over the inferred graph
May use any Model
implementation
May use InfModel for extra
control over the infered graph
13. +
Available reasoners
Included reasoners:
Transitive reasoner
Implements the transitive and reflexibe properties of
rdfs:subPropertyOf and rdfs:subClassOf
RDFS
Configurable subset of RDFS entailments
OWL, OWL Mini, OWL Mico
Incomplete implementations of OWL-Lite
DAML reasoner
Provides DAML inferences
Generic rule reasoner
Generic rule-based reasoner with support for forward, backward and
hybrid execution strategies
14. +
Inference API
A Factory for each type of reasoner (ReasonerFactory
instances)
Factory handles can be obtained with:
theInstance() calls
Using the global ReasonerRegistry and the URI that identifies the
reasoner type
Default reasoner can be accessed with:
getTransitiveReasoner
getRDFSReasoner
getOWLReasoner, getOWLMiniReasoner, getOWLMicroReasoner
15. +
Inference through Models
Specific model implementations provide easy access to the
reasoners for different Ontology configurations
Example:
ModelFactory.createRDFSModel(Model)
provides an Model
16. // Build a trivial example data set
Model rdfsExample = ModelFactory.createDefaultModel();
Property p = rdfsExample.createProperty(NS, "p");
Property q = rdfsExample.createProperty(NS, "q");
rdfsExample.add(p, RDFS.subPropertyOf, q);
rdfsExample.createResource(NS+"a").addProperty(p, "foo");
InfModel inf = ModelFactory.createRDFSModel(rdfsExample); // [1]
Resource a = inf.getResource(NS+"a");
System.out.println("Statement: " + a.getProperty(q));
Statement: [urn:x-hp-jena:eg/a, urn:x-hp-jena:eg/q, Literal<foo>]
17. Reasoner reasoner = ReasonerRegistry.getRDFSReasoner();
InfModel inf = ModelFactory.createInfModel(reasoner, rdfsExample);
or even more manually by
Reasoner reasoner = RDFSRuleReasonerFactory.theInstance().create(null);
InfModel inf = ModelFactory.createInfModel(reasoner, rdfsExample);
Why create a reasoner instance?
18. +
Configuring a reasoner
RDF triples (a resource) is used to configure the reasoner
ReasonerFactory.create(Resource configuration)
Additionally use Resoner.setParameter
Built-in parameter can be found in ReasonerVocabulary
Reasoner reasoner = RDFSRuleReasonerFactory.theInstance()Create(null);
reasoner.setParameter(ReasonerVocabulary.PROPsetRDFSLevel,
ReasonerVocabulary.RDFS_SIMPLE);
InfModel inf = ModelFactory.createInfModel(reasoner, rdfsExample);
19. +
Configuring a reasoner
RDF triples (a resource) is used to configure the reasoner
ReasonerFactory.create(Resource configuration)
Additionally use Resoner.setParameter
Built-in parameter can be found in ReasonerVocabulary
Resource config = ModelFactory.createDefaultModel()
.createResource()
.addProperty(ReasonerVocabulary.PROPsetRDFSLevel,
"simple");
Reasoner reasoner =
RDFSRuleReasonerFactory.theInstance().create(config);
InfModel inf = ModelFactory.createInfModel(reasoner, rdfsExample);
20. +
Direct and indirect relations
Jena allows to distinguish between direct and indirect
relationships
Types of relations for transitive properties:
Asserted
Inferred
Direct
21. +
Direct and indirect relations
Access is done through ALIASES
Jena proves aliases for subClassOf and subProperty of in
ReasonerVocabulary
directSubPropertyOf
directSubClassOf
Directly using the Ontology API
can facilitate access to these
types of relations
22. +
Tracing
Jena allows to keep track of the derivation of statements
Use InfModel.getDerivation(Statement)
Iterator<RuleDerivation>
getConclusion() : Triple
getRule() : Rule
getMatces() : List<Triple>
The full trace can be obtained with
Dreivation.PrintTrace
26. +
The RDFS reasoner
Support for MOST RDFS entailments
Accessed from:
ModelFactory.createRDFSModel or
ReasonerRegistry.getRDFSReasoner
In FULL mode all entailments except:= bNode closure.
Example:
eg:a eg:p nnn^^datatype .
we should introduce the corresponding blank nodes:
eg:a eg:p :anon1 .
:anon1 rdf:type datatype .
27. +
The RDFS reasoner
RDFSRuleReasoner configuration:
Full (expensive)
All entailment except bNode closure and rdfD1
Default
Ommits container membership properties, x rdfs:type :Resource
and every predicate is a :Property (rdf1, rdfs4a, rdfs4b)
Simple
Transitive closure for subPropertyOf and subClassOf, domain and
range and implications of subPropertyOf and subClassOf
reasoner.setParameter(ReasonerVocabulary.PROPsetRDFSLevel,
ReasonerVocabulary.RDFS_SIMPLE);