1 / 19

Jena --- A Java API for RDF

Jena --- A Java API for RDF. Jing deng CSCI 7818 Web Technologies Computer Science Department University of Colorado at Boulder Wednesday, October 31, 2001. Outline. Introduction RDF and Jena Install and Run Jena Jena package and Interface Jena API examples References. RDF.

Sophia
Download Presentation

Jena --- A Java API for RDF

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Jena --- A Java API for RDF Jing deng CSCI 7818 Web Technologies Computer Science Department University of Colorado at Boulder Wednesday, October 31, 2001

  2. Outline • Introduction RDF and Jena • Install and Run Jena • Jena package and Interface • Jena API examples • References

  3. RDF • Resource Description Framework • represents information on Web with machine-understandable syntax and semantics • Framework: Subject has the predicate whose value is object • Resource (Subject) • Property (Predicate) • Literal (Object)

  4. Tut:name Tut:email @yahoo Tut:email Brain @hotmail RDF (Cont.) DC:date Tutorial DC:creator DC:title Oct 31 2001 Introduction

  5. Jena • A Java API for RDF • Developed by Brian McBride of HP • Derived from SiRPAC API • Can parse, create, and search RDF models • Easy to use

  6. Install and Run Jena • Get package from http://www.hpl.hp.co.uk/people/bwm/rdf/jena/download.htm • Unzip it • Setup environments (CLASSPATH) • Test tutorial programs • http://www.bmcb.btinternet.co.uk/2001/rdf/jenatutorial/ • Online documentation • http://www.hpl.hp.co.uk/people/bwm/rdf/jena/javadoc/index.html

  7. Jena package • jena.model • Key package for application developer. It contains interfaces for model, resource, … • jena.mem • Contains an implementation of Jena API which stores all model state in main memory • Jena.common • Contains implementation classes

  8. Jena API Structure

  9. Jena interfaces • Model: a set of statements • Statement: a triple of {R, P, O} • Resource: subject, URI • Property: “item” of resource • Object: may be a resource or a literal • Literal: non-nested “object” • Container: special resource, collection of things

  10. resource Tutorial Model object DC:author DC:title property DC:date Statement Oct 31 2001 Introduction Tut:name Tut:email Literal @yahoo Tut:email Brain @hotmail Jena interfaces (cont.)

  11. Ex. 1 Create Resource static String tutorialURI = "http://hostname/rdf/tutorial/"; static String author = "Brian McBride"; static String title = "An Introduction to RDF and the Jena API"; static String date = "23/01/2001"; Model model = new ModelMem(); Resource tutorial = model.createResource(tutorialURI); tutorial.addProperty(DC.creator, author); tutorial.addProperty(DC.title, title); tutorial.addProperty(DC.date, date);

  12. Ex. 2 Go through Statements StmtIterator iter = model.listStatements(); while (iter.hasNext()) { Statement stmt = iter.next(); Resource subject = stmt.getSubject(); Property predicate = stmt.getPredicate(); RDFNode object = stmt.getObject(); System.out.print("(" + predicate.toString() + ","); System.out.print(" " + subject.toString() + ","); if (object instanceof Resource) { System.out.print(" " + object.toString()); } else { System.out.print(" \"" + object.toString() + "\""); } System.out.println(")"); }

  13. Ex. 3 Read and Write File Model model = new ModelMem(); String filename = “temp/tutorial4.xml”; Model.read(new FileReader(filename), “”); Model.write(new PrintWriter(System.out)); // or… String output_filename = “temp/test.xml”; Model.write(new PrintWriter(new FileOutputStream(output_filename)));

  14. Ex. 4 Navigating a Model Property email = model.createProperty(tutorialURI, "emailAddress"); Resource tutorial = model.getResource(tutorialURI); Resource author = tutorial.getProperty(DC.creator) .getResource(); StmtIterator iter = author.listProperties(email); while (iter.hasNext()) { System.out.println(" " + iter.next().getObject().toString()); }

  15. Ex. 5 Querying a Model ResIterator iter = model.listSubjectsWithProperty(DC.date, date); while (iter.hasNext()) { cout << iter.next().getProperty(DC.title) .getString(); } NodeIterator iter2 = model.listObjectsOfProperty(DC.creator); while (iter2.hasNext()) { cout << ((Resource)iter2.next()) .getProperty(name) .getString(); }

  16. Containers • Represents collections of things • BAG : unordered collection • ALT: unordered collection except first element • SEQ: ordered collection

  17. Ex. 6 Containers Bag bag = model.createBag(); bag.add("Romeo and Juliet") .add("Hamlet") .add("Othello"); NodeIterator iter = bag.iterator(); while (iter.hasNext()) { System.out.println(" " + iter.next().toString()); } model.write(new PrintWriter(System.out));

  18. References • Jena Web Site • http://www.hpl.hp.co.uk/people/bwm/index.html • Jena tutorial • http://bmcb.btinternet.co.uk/2001/rdf/jenatutorial/ • http://www.xml.com/pub/a/2001/05/23/jena.html • RDF Model and Syntax Specification • http://www.w3.org/TR/1999/REC-rdf-syntax-19990222/

  19. Thanks!

More Related