• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
070517 Jena
 

070517 Jena

on

  • 7,669 views

 

Statistics

Views

Total Views
7,669
Views on SlideShare
6,495
Embed Views
1,174

Actions

Likes
3
Downloads
374
Comments
1

7 Embeds 1,174

http://yuhanaresearch.wordpress.com 1121
http://www.slideshare.net 46
http://translate.googleusercontent.com 3
http://static.slideshare.net 1
http://74.125.91.132 1
http://74.125.77.132 1
url_unknown 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

11 of 1 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Great~~~
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

070517 Jena 070517 Jena Presentation Transcript

  • Jena: A Semantic Web Framework for Java Reporter C.F.Liao ( 廖峻鋒 ) May 17,2007
  • About Me
    • Education
      • Ph.D. Candidate, CSIE ,NTU
      • Advisor: Prof. Li-Chen Fu
      • Research interests: Middleware for the smart living spaces.
    • Professional Services
      • SCJP / SCWCD
      • Lecturer, SL-750, Learning Services, Sun Microsystems Taiwan, Inc.
      • Columnist (Java EE), RUN! PC Magazine
      • Reviewer, Core JSF CHT edition
  • Outline
    • Introduction
    • Installing and Running Jena
    • RDF Model Operations
    • Inference Mechanisms
    • (Optional)
      • SPARQL
      • Joseki
    • Conclusion
  • Introduction
    • What is Jena?
      • An open source semantic web framework written in Java
    • Jena is composed of
      • RDF Processing API
      • OWL Processing API
      • A rule-based reasoning engine
      • SPARQL query engine
  • RDF and OWL Processing API Model RDF Files Console Model I/O Model I/O Model CRUD OWL OWL OWL
  • Jena Inference Mechanism OWL OWL OWL ReasonerVocabulary Original Model Reasoner Rules Inferred Model
  • SPARQL (W3C Standard) Model SELECT ?x WHERE { ?x locatedIn classroom} … ?x = {Jane, Mary, and Peter} SPARQL Query Engine
  • Review: The RDF Network Light Switch1 state on Literal Resource Bedroom locatedIn size 9 contains TV1 Property
  • Key Abstractions Light Switch1 status on Bedroom locatedIn Browse the Jena Javadoc RDFNode
  • Recommended Development Environment
    • JDK 1.5 +
    • Eclipse 3.2 +, JST (J2EE Standard Tools)
    • MySQL 4.x (optional)
  • Installing and Running Jena
    • Download JDK 5
    • Download and install Eclipse
    • Download Jena
    • Tuning your Eclipse
    • Create a java project
    • Append Jena libraries to your classpath
    • Use Jena API to create some RDFs
    demo
  • Downloading Jena
    • http://jena.sourceforge.net/
  • Typical Jena Usage Scenario RDF Consumer (Jena) query RDF Files RDF Producer (Jena) Model (Memory) load add
  • Advanced Jena Usage Scenario Persistent RDF Model (Relational Database) RDF Publishing Server (Joseki) SPARQL over HTTP RDF Producer (Jena) Remote RDF Consumer (Jena)
  • Lab Creating a Simple RDF Model
  • Objectives
    • Creating a simple RDF statement
    • Placing this RDF into a Model
    • Dumping the Model to system console
    RDF Producer add print Model (Memory)
  • Creating RDF
    • 2 ways
      • Using Jena API
      • Load from file
  • Creating a RDF statement
    • // declare URI prefix
    • String ns = "http://www.ispace.tw/smarthome#";
    • Model model = ModelFactory. createDefaultModel ();
    • Resource light = model.createResource(ns+" light1 ");
    • Property lightStatus = model.createProperty(ns+" status ");
    • Literal statusValue = model.createLiteral(" off ");
    • light.addProperty(lightStatus, statusValue);
    • model.write(System. out ,"N-TRIPLE");
    (light,status,off) ex1 demo light1 status off Model
  • Lab Model I/O
  • Model I/O
    • model.read("file:./bin/advai/rdf/smarthome.nt", "N-TRIPLE");
    • model.write( new FileWriter("test.nt"),"N-TRIPLE");
    System.out FileWriter Model
  • Loading RDF from an External File
    • Model model =
    • FileManager . get ()
    • . loadModel (
    • “ file: ./bin/advai/rdf/smarthome.nt ",
    • " N-TRIPLE ");
    src advai rdf smarthome.nt ReadRdfFromFileTest.java MyJenaProject ex2 demo bin ReadRdfFromFileTest.class
  • Dumping the Model
    • model.write(System. out ,"N-TRIPLE");
    • model.write(System. out ,"N3");
    • model.write(new FileWriter("test.nt"),“RDF/XML");
    • model.write(new FileWriter("test.nt"),“RDF/XML-ABBREV");
    System.out FileWriter ex3 demo Model
  • Lab Model CRUD
  • Model CRUD
    • Create
    • Retrieve
    • Update
    • Delete
    RDF Consumer (Jena) Model query
  • Navigating a Model
    • for (Iterator it = model.listStatements() ;it.hasNext();)
    • {
    • Statement stmt = (Statement) it.next(); System. out .println(stmt.getSubject().getLocalName());
    • }
    RDF Consumer Model Reification ex4 demo query Subject Property Object
  • Querying Model
    • “ Select * from MODEL where SUBJECT=‘Jane’ ”
    • Resource jane = model.getResource("http://...Jane");
    • Selector selector =
    • new SimpleSelector( jane, (Property) null , (Resource) null );
    • for (Iterator it = model.listStatements(selector) ;it.hasNext();){ …}
    RDF Consumer Model Reification selector ex5 demo
  • Updating Model
    • Using Statement’s changeObject() method:
    • Resource jane = model.getResource("http://www.try.idv.tw/try#Jane");
    • Resource home =
    • model.getResource("http://www.try.idv.tw/try#Home");
    • Property locatedIn =
    • model.getProperty("http://www.try.idv.tw/try#locatedIn");
    • jane.getProperty(locatedIn). changeObject (home);
    RDF Consumer ex6 demo New object
  • Removing a Statement from Model
    • Using Statement’s remove() method:
    • Resource jane = model.getResource("http://www.try.idv.tw/try#Jane");
    • Property locatedIn =
    • model.getProperty("http://www.try.idv.tw/try#locatedIn");
    • jane.getProperty(locatedIn). remove ;
    ex7 demo
  • Lab Basic Inference
  • Jena Inference Mechanism ReasonerRegistry RDFSReasoner Application Existing Model + Reasoner New Model (InfModel) ModelFactory Data (Model) GenericReasoner OwlReasoner ModelFactory InfModel
  • A Simple RDFS Reasoner Example
    • Property teachesAtProp = data.createProperty(ns, "teachesAt");
    • Property worksAtProp = data.createProperty(ns, "worksAt");
    • data.add(teachesAtProp, RDFS.subPropertyOf, worksAtProp);
    • data.createResource(ns + "jane").addProperty(teachesAtProp, "NTU");
    • Reasoner reasoner = ReasonerRegistry. getRDFSReasoner() ;
    • InfModel infModel = ModelFactory.createInfModel(reasoner, data);
    (Jane, teachesAt, NTU) RDFS Example demo (Jane, worksAt, NTU) teachesAt worksAt
  • Lab Ontological Inference
  • Modeling a Domain with Schema and Data Schema Level Data Level
  • Separating Schema and Data ReasonerRegistry RDFSReasoner GenericReasoner Application Data (Model) Schema (OntModel) OwlReasoner ModelFactory InfModel
  • Example: The Smart Home Ontology locatedIn contains inverse transitive Building Room Person Light type type type Home Bedroom Jane type light1 contains locatedIn
  • Creating OntModel with Ontology API
    • OntModel m =
    • ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
    • m.createClass(ns + " Building ");
    • m.createClass(ns + " Room ");
    • m.createClass(ns + " Person ");
    • m.createClass(ns + “ Light ");
    • ObjectProperty contains =
    • m.createObjectProperty(ns + "contains", true).convertToTransitiveProperty();
    • ObjectProperty locatedIn =
    • m.createObjectProperty(ns + "locatedIn").convertToTransitiveProperty();
    • contains.setInverseOf(locatedIn);
    ex8 demo Inverse relationship Create 4 Class Definitions properties Model Configuration
  • A Ont Reasoner Example
    • OntModel schema = ModelFactory.createOntologyModel(…);
    • schema.read("file:./bin/advai/schema.owl");
    • Model data =
    • FileManager.get().loadModel("file:./bin/advai/data.rdf");
    • Reasoner reasoner = ReasonerRegistry.getOWLReasoner();
    • InfModel infModel =
    • ModelFactory .createInfModel(reasoner, schema, data);
    ex10 demo
  • Lab Cascading Inference
  • Combining Generic and OWL Reasoners GenericReasoner Rules Data (Model) Schema (OntModel) OwlReasoner ontInfModel ModelFactory infModel ModelFactory
  • An “Openlight” Rule
    • @prefix h: <http://www.ispace.tw/smarthome#> .
    • @include <RDFS>.
    • @include <OWL>.
    • [openlight:
    • (?a h:locatedIn h:bedroom)
    • (?a rdf:type h:Person)
    • (?b rdf:type h:Light)
    • (?b h:status 'off') -> drop(3) (?b h:status 'on')
    • ]
    “ if a person is in the bedroom then open all light”
  • Cascading Reasoners
    • OntModel schema =
    • ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_TRANS_INF);
    • schema.read(&quot;file:./bin/advai/inf/schema-inf-owl.owl&quot;);
    • Model data = FileManager.get().loadModel(&quot;file:./bin/advai/inf/data-inf-owl.rdf&quot;);
    • Reasoner owlReasoner = ReasonerRegistry.getOWLReasoner();
    • InfModel owlInfModel = ModelFactory.createInfModel(owlReasoner, schema, data);
    • GenericRuleReasoner reasoner =
    • new GenericRuleReasoner(Rule.rulesFromURL(&quot;file:./bin/advai/inf/myrule.rule&quot;));
    • reasoner.setDerivationLogging(true);
    • InfModel infModel = ModelFactory.createInfModel(reasoner, owlInfModel);
    ex11 demo
  • Summary
    • What we have learned
      • RDF / Model CRUD
      • OWL
      • OWL inference
      • OWL + Generic Rule engine inference
    • Further readings
      • Jena Javadocs
      • Be sure to understand the meaning of advanced configuration mechanisms of models and reasoners.
  • Querying Model with SPARQL
    • Query query = …(Query String);
    • QueryExecution qexec = QueryExecutionFactory. create (query, model );
    • try
    • {
    • ResultSet results = qexec.execSelect();
    • for (; results.hasNext();)
    • {
    • QuerySolution soln = results.nextSolution();
    • … // the solutions may be Resources or Literals
    • }
    • }
    • finally
    • {
    • qexec.close();
    • }
    Sparql Demo
  • Persisting RDF Model
    • Download required bundles
      • MySQL DB
      • MySQL JDBC Driver
    • Install MySQL database
    • Create jenadb
      • create database jenatest character set utf8 ;
    • Persist with ModelMaker