Your SlideShare is downloading. ×
  • Like
SWT Lecture Session 8 - Inference in jena
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

SWT Lecture Session 8 - Inference in jena

  • 465 views
Published

 

Published in Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
465
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
14
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide
  • soundness, completeness, termintion
  • soundness, completeness, termintion
  • soundness, completeness, termintion
  • soundness, completeness, termintion
  • soundness, completeness, termintion
  • soundness, completeness, termintion
  • soundness, completeness, termintion
  • soundness, completeness, termintion
  • soundness, completeness, termintion
  • soundness, completeness, termintion
  • soundness, completeness, termintion
  • soundness, completeness, termintion
  • soundness, completeness, termintion
  • soundness, completeness, termintion
  • soundness, completeness, termintion

Transcript

  • 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
  • 4. + RDFS reasoning in Jena
  • 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() ); }
  • 10. + Inference engine in Jena
  • 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);