Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Jena --- A Java API for RDF Jing deng CSCI 7818 Web Technologies Computer Science Department University of Colorado at Boulder Wednesday, October 31, 2001."— 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 RDF (Cont.) Tutorial Oct 31 2001Introduction DC:creator DC:dat e DC:title Brain @hotmail @yahoo Tut:name Tut:email

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 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/jenatuto rial/http://www.bmcb.btinternet.co.uk/2001/rdf/jenatuto rial/ Online documentation –http://www.hpl.hp.co.uk/people/bwm/rdf/jena/javad oc/index.htmlhttp://www.hpl.hp.co.uk/people/bwm/rdf/jena/javad oc/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 Jena interfaces (cont.) Tutorial Oct 31 2001Introduction DC:author DC:date DC:title Brain @hotmail @yahoo Tut:name Tut:email Model Statement resource property Literal object

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.htmlhttp://www.hpl.hp.co.uk/people/bwm/index.html Jena tutorial –http://bmcb.btinternet.co.uk/2001/rdf/jenatutorial/http://bmcb.btinternet.co.uk/2001/rdf/jenatutorial/ –http://www.xml.com/pub/a/2001/05/23/jena.htmlhttp://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/http://www.w3.org/TR/1999/REC-rdf-syntax- 19990222/

19 Thanks!


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

Similar presentations


Ads by Google