070517 Jena

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    070517 Jena - Presentation Transcript

    1. Jena: A Semantic Web Framework for Java Reporter C.F.Liao ( 廖峻鋒 ) May 17,2007
    2. 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
    3. Outline
      • Introduction
      • Installing and Running Jena
      • RDF Model Operations
      • Inference Mechanisms
      • (Optional)
        • SPARQL
        • Joseki
      • Conclusion
    4. 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
    5. RDF and OWL Processing API Model RDF Files Console Model I/O Model I/O Model CRUD OWL OWL OWL
    6. Jena Inference Mechanism OWL OWL OWL ReasonerVocabulary Original Model Reasoner Rules Inferred Model
    7. SPARQL (W3C Standard) Model SELECT ?x WHERE { ?x locatedIn classroom} … ?x = {Jane, Mary, and Peter} SPARQL Query Engine
    8. Review: The RDF Network Light Switch1 state on Literal Resource Bedroom locatedIn size 9 contains TV1 Property
    9. Key Abstractions Light Switch1 status on Bedroom locatedIn Browse the Jena Javadoc RDFNode
    10. Recommended Development Environment
      • JDK 1.5 +
      • Eclipse 3.2 +, JST (J2EE Standard Tools)
      • MySQL 4.x (optional)
    11. 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
    12. Downloading Jena
      • http://jena.sourceforge.net/
    13. Typical Jena Usage Scenario RDF Consumer (Jena) query RDF Files RDF Producer (Jena) Model (Memory) load add
    14. Advanced Jena Usage Scenario Persistent RDF Model (Relational Database) RDF Publishing Server (Joseki) SPARQL over HTTP RDF Producer (Jena) Remote RDF Consumer (Jena)
    15. Lab Creating a Simple RDF Model
    16. Objectives
      • Creating a simple RDF statement
      • Placing this RDF into a Model
      • Dumping the Model to system console
      RDF Producer add print Model (Memory)
    17. Creating RDF
      • 2 ways
        • Using Jena API
        • Load from file
    18. 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
    19. Lab Model I/O
    20. 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
    21. 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
    22. 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
    23. Lab Model CRUD
    24. Model CRUD
      • Create
      • Retrieve
      • Update
      • Delete
      RDF Consumer (Jena) Model query
    25. 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
    26. 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
    27. 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
    28. 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
    29. Lab Basic Inference
    30. Jena Inference Mechanism ReasonerRegistry RDFSReasoner Application Existing Model + Reasoner New Model (InfModel) ModelFactory Data (Model) GenericReasoner OwlReasoner ModelFactory InfModel
    31. 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
    32. Lab Ontological Inference
    33. Modeling a Domain with Schema and Data Schema Level Data Level
    34. Separating Schema and Data ReasonerRegistry RDFSReasoner GenericReasoner Application Data (Model) Schema (OntModel) OwlReasoner ModelFactory InfModel
    35. Example: The Smart Home Ontology locatedIn contains inverse transitive Building Room Person Light type type type Home Bedroom Jane type light1 contains locatedIn
    36. 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
    37. 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
    38. Lab Cascading Inference
    39. Combining Generic and OWL Reasoners GenericReasoner Rules Data (Model) Schema (OntModel) OwlReasoner ontInfModel ModelFactory infModel ModelFactory
    40. 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”
    41. 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
    42. 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.
    43. 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
    44. 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

    + yuhanayuhana, 3 years ago

    custom

    1857 views, 0 favs, 4 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 1857
      • 1687 on SlideShare
      • 170 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 115
    Most viewed embeds
    • 167 views on http://yuhanaresearch.wordpress.com
    • 1 views on http://static.slideshare.net
    • 1 views on http://74.125.91.132
    • 1 views on http://translate.googleusercontent.com

    more

    All embeds
    • 167 views on http://yuhanaresearch.wordpress.com
    • 1 views on http://static.slideshare.net
    • 1 views on http://74.125.91.132
    • 1 views on http://translate.googleusercontent.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Tags