SlideShare a Scribd company logo
1 of 27
+

Inference in Jena

Mariano Rodriguez-Muro,
Free University of Bozen-Bolzano
+

Disclaimer


License


This work is licensed under a
Creative Commons Attribution-Share Alike 3.0 License
(http://creativecommons.org/licenses/by-sa/3.0/)
+

Reading material


Foundations of Semantic Web Chapter 3.



Jena Documentation
+
RDFS reasoning in Jena
+

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
+

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
+

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
+

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
+

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() );
}
+
Inference engine in Jena
+

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
+

Overview


Entry point for reasoners:
ReasonerRegistry
+

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
+

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
+

Inference through Models


Specific model implementations provide easy access to the
reasoners for different Ontology configurations



Example:


ModelFactory.createRDFSModel(Model)
provides an Model
// 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>]
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?
+

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);
+

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);
+

Direct and indirect relations


Jena allows to distinguish between direct and indirect
relationships



Types of relations for transitive properties:


Asserted



Inferred



Direct
+

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
+

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
+

Tracing (example)
eg:A eg:p eg:B .
eg:B eg:p eg:C .
eg:C eg:p eg:D .

String rules = "[rule1: (?a eg:p ?b) (?b eg:p ?c) -> (?a eg:p ?c)]";
Reasoner reasoner = new
GenericRuleReasoner(Rule.parseRules(rules));
reasoner.setDerivationLogging(true);
InfModel inf = ModelFactory.createInfModel(reasoner, rawData);
+

Tracing (example)
eg:A eg:p eg:B .
eg:B eg:p eg:C .
eg:C eg:p eg:D .

PrintWriter out = new PrintWriter(System.out);
for (StmtIterator i = inf.listStatements(A, p, D); i.hasNext(); ) {
Statement s = i.nextStatement();
System.out.println("Statement is " + s);
for (Iterator id = inf.getDerivation(s); id.hasNext(); ) {
Derivation deriv = (Derivation) id.next();
deriv.printTrace(out, true);
}
}
out.flush();
+

Tracing (example)

Statement is [urn:x-hp:eg/A, urn:x-hp:eg/p, urn:x-hp:eg/D]
Rule rule1 concluded (eg:A eg:p eg:D) <Fact (eg:A eg:p eg:B)
Rule rule1 concluded (eg:B eg:p eg:D) <Fact (eg:B eg:p eg:C)
Fact (eg:C eg:p eg:D)
+

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 .
+

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);

More Related Content

What's hot

Ti1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: PolymorphismTi1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: Polymorphism
Eelco Visser
 
Solr Query Parsing
Solr Query ParsingSolr Query Parsing
Solr Query Parsing
Erik Hatcher
 
FUNctional Programming in Java 8
FUNctional Programming in Java 8FUNctional Programming in Java 8
FUNctional Programming in Java 8
Richard Walker
 

What's hot (20)

Java and OWL
Java and OWLJava and OWL
Java and OWL
 
6 Months Project Training in PHP
6 Months Project Training in PHP6 Months Project Training in PHP
6 Months Project Training in PHP
 
Building your own search engine with Apache Solr
Building your own search engine with Apache SolrBuilding your own search engine with Apache Solr
Building your own search engine with Apache Solr
 
Input/Output Exploring java.io
Input/Output Exploring java.ioInput/Output Exploring java.io
Input/Output Exploring java.io
 
Semantic Web - Ontology 101
Semantic Web - Ontology 101Semantic Web - Ontology 101
Semantic Web - Ontology 101
 
Ti1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: PolymorphismTi1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: Polymorphism
 
Java 8 Stream API (Valdas Zigas)
Java 8 Stream API (Valdas Zigas)Java 8 Stream API (Valdas Zigas)
Java 8 Stream API (Valdas Zigas)
 
Tutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component pluginTutorial on developing a Solr search component plugin
Tutorial on developing a Solr search component plugin
 
Solr Query Parsing
Solr Query ParsingSolr Query Parsing
Solr Query Parsing
 
code4lib 2011 preconference: What's New in Solr (since 1.4.1)
code4lib 2011 preconference: What's New in Solr (since 1.4.1)code4lib 2011 preconference: What's New in Solr (since 1.4.1)
code4lib 2011 preconference: What's New in Solr (since 1.4.1)
 
Collections - Sorting, Comparing Basics
Collections - Sorting, Comparing Basics Collections - Sorting, Comparing Basics
Collections - Sorting, Comparing Basics
 
File Input & Output
File Input & OutputFile Input & Output
File Input & Output
 
Introduction to the Topaz OTM framework and the Ambra publishing system
Introduction to the Topaz OTM framework and the Ambra publishing systemIntroduction to the Topaz OTM framework and the Ambra publishing system
Introduction to the Topaz OTM framework and the Ambra publishing system
 
Java 8 Stream API and RxJava Comparison
Java 8 Stream API and RxJava ComparisonJava 8 Stream API and RxJava Comparison
Java 8 Stream API and RxJava Comparison
 
Lucene's Latest (for Libraries)
Lucene's Latest (for Libraries)Lucene's Latest (for Libraries)
Lucene's Latest (for Libraries)
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output Concepts
 
Collections - Array List
Collections - Array List Collections - Array List
Collections - Array List
 
Solr introduction
Solr introductionSolr introduction
Solr introduction
 
Session 17 - Collections - Lists, Sets
Session 17 - Collections - Lists, SetsSession 17 - Collections - Lists, Sets
Session 17 - Collections - Lists, Sets
 
FUNctional Programming in Java 8
FUNctional Programming in Java 8FUNctional Programming in Java 8
FUNctional Programming in Java 8
 

Viewers also liked

SWT Lecture Session 9 - RDB2RDF direct mapping
SWT Lecture Session 9 - RDB2RDF direct mappingSWT Lecture Session 9 - RDB2RDF direct mapping
SWT Lecture Session 9 - RDB2RDF direct mapping
Mariano Rodriguez-Muro
 
SWT Lecture Session 6 - RDFS semantics, inference techniques, sesame rdfs
SWT Lecture Session 6 - RDFS semantics, inference techniques, sesame rdfsSWT Lecture Session 6 - RDFS semantics, inference techniques, sesame rdfs
SWT Lecture Session 6 - RDFS semantics, inference techniques, sesame rdfs
Mariano Rodriguez-Muro
 
2011.118 1233
2011.118 12332011.118 1233
2011.118 1233
swaipnew
 

Viewers also liked (13)

JADE+JENA
JADE+JENAJADE+JENA
JADE+JENA
 
SWT Lecture Session 10 R2RML Part 1
SWT Lecture Session 10 R2RML Part 1SWT Lecture Session 10 R2RML Part 1
SWT Lecture Session 10 R2RML Part 1
 
SWT Lab 1
SWT Lab 1SWT Lab 1
SWT Lab 1
 
SWT Lab 5
SWT Lab 5SWT Lab 5
SWT Lab 5
 
SWT Lecture Session 9 - RDB2RDF direct mapping
SWT Lecture Session 9 - RDB2RDF direct mappingSWT Lecture Session 9 - RDB2RDF direct mapping
SWT Lecture Session 9 - RDB2RDF direct mapping
 
SWT Lecture Session 8 - Rules
SWT Lecture Session 8 - RulesSWT Lecture Session 8 - Rules
SWT Lecture Session 8 - Rules
 
SWT Lab 2
SWT Lab 2SWT Lab 2
SWT Lab 2
 
SWT Lecture Session 6 - RDFS semantics, inference techniques, sesame rdfs
SWT Lecture Session 6 - RDFS semantics, inference techniques, sesame rdfsSWT Lecture Session 6 - RDFS semantics, inference techniques, sesame rdfs
SWT Lecture Session 6 - RDFS semantics, inference techniques, sesame rdfs
 
2011.118 1233
2011.118 12332011.118 1233
2011.118 1233
 
SWT Lecture Session 2 - RDF
SWT Lecture Session 2 - RDFSWT Lecture Session 2 - RDF
SWT Lecture Session 2 - RDF
 
Ontologies and semantic web
Ontologies and semantic webOntologies and semantic web
Ontologies and semantic web
 
RuleML2015 - Tutorial - Powerful Practical Semantic Rules in Rulelog - Funda...
RuleML2015 - Tutorial -  Powerful Practical Semantic Rules in Rulelog - Funda...RuleML2015 - Tutorial -  Powerful Practical Semantic Rules in Rulelog - Funda...
RuleML2015 - Tutorial - Powerful Practical Semantic Rules in Rulelog - Funda...
 
7 advanced uses of rdfs
7 advanced uses of rdfs7 advanced uses of rdfs
7 advanced uses of rdfs
 

Similar to SWT Lecture Session 8 - Inference in jena

Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming Language
YLTO
 
Ijarcet vol-2-issue-2-676-678
Ijarcet vol-2-issue-2-676-678Ijarcet vol-2-issue-2-676-678
Ijarcet vol-2-issue-2-676-678
Editor IJARCET
 
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
New York City College of Technology Computer Systems Technology Colloquium
 

Similar to SWT Lecture Session 8 - Inference in jena (20)

Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
 
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Python
 
14274730 (1).ppt
14274730 (1).ppt14274730 (1).ppt
14274730 (1).ppt
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming Language
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
Ijarcet vol-2-issue-2-676-678
Ijarcet vol-2-issue-2-676-678Ijarcet vol-2-issue-2-676-678
Ijarcet vol-2-issue-2-676-678
 
OOP, Networking, Linux/Unix
OOP, Networking, Linux/UnixOOP, Networking, Linux/Unix
OOP, Networking, Linux/Unix
 
Java Notes
Java NotesJava Notes
Java Notes
 
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...Towards Improving Interface Modularity in Legacy Java Software Through Automa...
Towards Improving Interface Modularity in Legacy Java Software Through Automa...
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8
 
Semantic Web
Semantic WebSemantic Web
Semantic Web
 
Semantic Web
Semantic WebSemantic Web
Semantic Web
 
SOLID mit Java 8
SOLID mit Java 8SOLID mit Java 8
SOLID mit Java 8
 
Automatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to InterfacesAutomatic Migration of Legacy Java Method Implementations to Interfaces
Automatic Migration of Legacy Java Method Implementations to Interfaces
 
Phenoflow: An Architecture for Computable Phenotypes
Phenoflow: An Architecture for Computable PhenotypesPhenoflow: An Architecture for Computable Phenotypes
Phenoflow: An Architecture for Computable Phenotypes
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Andy On Closures
Andy On ClosuresAndy On Closures
Andy On Closures
 
Core_Java_Interview.pdf
Core_Java_Interview.pdfCore_Java_Interview.pdf
Core_Java_Interview.pdf
 

More from Mariano Rodriguez-Muro

SWT Lecture Session 7 - Advanced uses of RDFS
SWT Lecture Session 7 - Advanced uses of RDFSSWT Lecture Session 7 - Advanced uses of RDFS
SWT Lecture Session 7 - Advanced uses of RDFS
Mariano Rodriguez-Muro
 
SWT Lecture Session 4 - SW architectures and SPARQL
SWT Lecture Session 4 - SW architectures and SPARQLSWT Lecture Session 4 - SW architectures and SPARQL
SWT Lecture Session 4 - SW architectures and SPARQL
Mariano Rodriguez-Muro
 

More from Mariano Rodriguez-Muro (20)

SWT Lecture Session 11 - R2RML part 2
SWT Lecture Session 11 - R2RML part 2SWT Lecture Session 11 - R2RML part 2
SWT Lecture Session 11 - R2RML part 2
 
SWT Lecture Session 7 - Advanced uses of RDFS
SWT Lecture Session 7 - Advanced uses of RDFSSWT Lecture Session 7 - Advanced uses of RDFS
SWT Lecture Session 7 - Advanced uses of RDFS
 
SWT Lecture Session 5 - RDFS
SWT Lecture Session 5 - RDFSSWT Lecture Session 5 - RDFS
SWT Lecture Session 5 - RDFS
 
SWT Lecture Session 4 - SW architectures and SPARQL
SWT Lecture Session 4 - SW architectures and SPARQLSWT Lecture Session 4 - SW architectures and SPARQL
SWT Lecture Session 4 - SW architectures and SPARQL
 
SWT Lecture Session 4 - Sesame
SWT Lecture Session 4 - SesameSWT Lecture Session 4 - Sesame
SWT Lecture Session 4 - Sesame
 
SWT Lecture Session 3 - SPARQL
SWT Lecture Session 3 - SPARQLSWT Lecture Session 3 - SPARQL
SWT Lecture Session 3 - SPARQL
 
5 rdfs
5 rdfs5 rdfs
5 rdfs
 
4 sw architectures and sparql
4 sw architectures and sparql4 sw architectures and sparql
4 sw architectures and sparql
 
4 sesame
4 sesame4 sesame
4 sesame
 
SWT Lecture Session 1 - Introduction
SWT Lecture Session 1 - IntroductionSWT Lecture Session 1 - Introduction
SWT Lecture Session 1 - Introduction
 
ontop: A tutorial
ontop: A tutorialontop: A tutorial
ontop: A tutorial
 
Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...
Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...
Stanford'12 Intro to Ontology Based Data Access for RDBMS through query rewri...
 
Introduction to query rewriting optimisation with dependencies
Introduction to query rewriting optimisation with dependenciesIntroduction to query rewriting optimisation with dependencies
Introduction to query rewriting optimisation with dependencies
 
OXFORD'13 Optimising OWL 2 QL query rewriring
OXFORD'13 Optimising OWL 2 QL query rewriringOXFORD'13 Optimising OWL 2 QL query rewriring
OXFORD'13 Optimising OWL 2 QL query rewriring
 
OWLED'12 Quest
OWLED'12 QuestOWLED'12 Quest
OWLED'12 Quest
 
ODBASE'08 dl-lite explanations
ODBASE'08 dl-lite explanationsODBASE'08 dl-lite explanations
ODBASE'08 dl-lite explanations
 
IMAS'08 obda plugin
IMAS'08 obda pluginIMAS'08 obda plugin
IMAS'08 obda plugin
 
DL'12 dl-lite explanations
DL'12 dl-lite explanationsDL'12 dl-lite explanations
DL'12 dl-lite explanations
 
DL'12 mastro at work
DL'12 mastro at workDL'12 mastro at work
DL'12 mastro at work
 
AMW'11 dependencies-sem index-t-mappings
AMW'11 dependencies-sem index-t-mappingsAMW'11 dependencies-sem index-t-mappings
AMW'11 dependencies-sem index-t-mappings
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Recently uploaded (20)

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 

SWT Lecture Session 8 - Inference in jena

  • 1. + Inference in Jena Mariano Rodriguez-Muro, Free University of Bozen-Bolzano
  • 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/)
  • 3. + Reading material  Foundations of Semantic Web Chapter 3.  Jena Documentation
  • 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
  • 12. + Overview  Entry point for reasoners: ReasonerRegistry
  • 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
  • 23. + Tracing (example) eg:A eg:p eg:B . eg:B eg:p eg:C . eg:C eg:p eg:D . String rules = "[rule1: (?a eg:p ?b) (?b eg:p ?c) -> (?a eg:p ?c)]"; Reasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules)); reasoner.setDerivationLogging(true); InfModel inf = ModelFactory.createInfModel(reasoner, rawData);
  • 24. + Tracing (example) eg:A eg:p eg:B . eg:B eg:p eg:C . eg:C eg:p eg:D . PrintWriter out = new PrintWriter(System.out); for (StmtIterator i = inf.listStatements(A, p, D); i.hasNext(); ) { Statement s = i.nextStatement(); System.out.println("Statement is " + s); for (Iterator id = inf.getDerivation(s); id.hasNext(); ) { Derivation deriv = (Derivation) id.next(); deriv.printTrace(out, true); } } out.flush();
  • 25. + Tracing (example) Statement is [urn:x-hp:eg/A, urn:x-hp:eg/p, urn:x-hp:eg/D] Rule rule1 concluded (eg:A eg:p eg:D) <Fact (eg:A eg:p eg:B) Rule rule1 concluded (eg:B eg:p eg:D) <Fact (eg:B eg:p eg:C) Fact (eg:C eg:p eg:D)
  • 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);

Editor's Notes

  1. soundness, completeness, termintion
  2. soundness, completeness, termintion
  3. soundness, completeness, termintion
  4. soundness, completeness, termintion
  5. soundness, completeness, termintion
  6. soundness, completeness, termintion
  7. soundness, completeness, termintion
  8. soundness, completeness, termintion
  9. soundness, completeness, termintion
  10. soundness, completeness, termintion
  11. soundness, completeness, termintion
  12. soundness, completeness, termintion
  13. soundness, completeness, termintion
  14. soundness, completeness, termintion
  15. soundness, completeness, termintion