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

6 Months Project Training in PHP
6 Months Project Training in PHP6 Months Project Training in PHP
6 Months Project Training in PHPTech Mentro
 
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 SolrBiogeeks
 
Input/Output Exploring java.io
Input/Output Exploring java.ioInput/Output Exploring java.io
Input/Output Exploring java.ioNilaNila16
 
Semantic Web - Ontology 101
Semantic Web - Ontology 101Semantic Web - Ontology 101
Semantic Web - Ontology 101Luigi De Russis
 
Ti1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: PolymorphismTi1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: PolymorphismEelco Visser
 
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 pluginsearchbox-com
 
Solr Query Parsing
Solr Query ParsingSolr Query Parsing
Solr Query ParsingErik Hatcher
 
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)Erik Hatcher
 
Collections - Sorting, Comparing Basics
Collections - Sorting, Comparing Basics Collections - Sorting, Comparing Basics
Collections - Sorting, Comparing Basics Hitesh-Java
 
File Input & Output
File Input & OutputFile Input & Output
File Input & OutputPRN USM
 
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 systemRichard Cave
 
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 ComparisonJosé Paumard
 
Lucene's Latest (for Libraries)
Lucene's Latest (for Libraries)Lucene's Latest (for Libraries)
Lucene's Latest (for Libraries)Erik Hatcher
 
Java - File Input Output Concepts
Java - File Input Output ConceptsJava - File Input Output Concepts
Java - File Input Output ConceptsVicter Paul
 
Collections - Array List
Collections - Array List Collections - Array List
Collections - Array List Hitesh-Java
 
Solr introduction
Solr introductionSolr introduction
Solr introductionLap Tran
 
Session 17 - Collections - Lists, Sets
Session 17 - Collections - Lists, SetsSession 17 - Collections - Lists, Sets
Session 17 - Collections - Lists, SetsPawanMM
 
FUNctional Programming in Java 8
FUNctional Programming in Java 8FUNctional Programming in Java 8
FUNctional Programming in Java 8Richard 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

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

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...Raffi Khatchadourian
 
Patterns in Python
Patterns in PythonPatterns in Python
Patterns in Pythondn
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming LanguageYLTO
 
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-678Editor IJARCET
 
OOP, Networking, Linux/Unix
OOP, Networking, Linux/UnixOOP, Networking, Linux/Unix
OOP, Networking, Linux/UnixNovita Sari
 
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 8Raffi Khatchadourian
 
SOLID mit Java 8
SOLID mit Java 8SOLID mit Java 8
SOLID mit Java 8Roland Mast
 
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 InterfacesRaffi Khatchadourian
 
Phenoflow: An Architecture for Computable Phenotypes
Phenoflow: An Architecture for Computable PhenotypesPhenoflow: An Architecture for Computable Phenotypes
Phenoflow: An Architecture for Computable PhenotypesMartin Chapman
 

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 RDFSMariano 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 SPARQLMariano Rodriguez-Muro
 
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...Mariano Rodriguez-Muro
 
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 dependenciesMariano Rodriguez-Muro
 
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 rewriringMariano Rodriguez-Muro
 
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-mappingsMariano 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

MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
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 ...EduSkills OECD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 

Recently uploaded (20)

MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
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 ...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 

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