jena a java api for rdf n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Jena --- A Java API for RDF PowerPoint Presentation
Download Presentation
Jena --- A Java API for RDF

Loading in 2 Seconds...

play fullscreen
1 / 19

Jena --- A Java API for RDF - PowerPoint PPT Presentation


  • 174 Views
  • Uploaded on

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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Jena --- A Java API for RDF' - Sophia


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
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
Outline
  • Introduction RDF and Jena
  • Install and Run Jena
  • Jena package and Interface
  • Jena API examples
  • References
slide3
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)
rdf cont

Tut:name

Tut:email

@yahoo

Tut:email

Brain

@hotmail

RDF (Cont.)

DC:date

Tutorial

DC:creator

DC:title

Oct 31 2001

Introduction

slide5
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
install and run jena
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
jena package
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
jena interfaces
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
jena interfaces cont

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.)
ex 1 create resource
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);

ex 2 go through statements
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(")"); }

ex 3 read and write file
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)));

ex 4 navigating a model
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());

}

ex 5 querying a model
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();

}

containers
Containers
  • Represents collections of things
    • BAG : unordered collection
    • ALT: unordered collection except first element
    • SEQ: ordered collection
ex 6 containers
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));

references
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/