0% found this document useful (0 votes)
43 views

A Simple Vcard Might Look Like This in RDF

Jena is a Java API that can be used to create and manipulate RDF graphs, where graphs are represented as models containing statements with three parts: a subject, predicate, and object; it provides classes to represent resources, properties, and literals that make up these statements. Models written in Jena can be output in different RDF formats like XML, N-Triples, and more compact abbreviated syntax by specifying different writers.

Uploaded by

Mani Chaudry
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

A Simple Vcard Might Look Like This in RDF

Jena is a Java API that can be used to create and manipulate RDF graphs, where graphs are represented as models containing statements with three parts: a subject, predicate, and object; it provides classes to represent resources, properties, and literals that make up these statements. Models written in Jena can be output in different RDF formats like XML, N-Triples, and more compact abbreviated syntax by specifying different writers.

Uploaded by

Mani Chaudry
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Jena is a Java API which can be used to create and manipulate RDF graphs like this

one. Jena has object classes to represent graphs, resources, properties and literals.
The interfaces representing resources, properties and literals are called Resource,
Property and Literal respectively. In Jena, a graph is called a model and is
represented by the Model interface.

A simple vcard might look like this in RDF:

The resource, John Smith, is shown as an elipse and is identified by a Uniform Resource


Identifier (URI)1, in this case "http://.../JohnSmith".

Resources have properties.

A property is represented by an arc, labeled with the


name of a property.

Here we have added a new


property, vcard:N, to represent
the structure of John Smith's
name. There are several things of
interest about this Model. Note
that the vcard:N property takes a
resource as its value. Note also
that the ellipse representing the
compound name has no URI. It is
known as an blank Node.
Statements

Each arc in an RDF Model is called a statement. Each statement asserts a fact about a
resource. A statement has three parts:

 the subject is the resource from which the arc leaves


 the predicate is the property that labels the arc
 the object is the resource or literal pointed to by the arc

A statement is sometimes called a triple, because of its three parts.

An RDF Model is represented as a set of statements. Each call of addProperty in tutorial2


added another statement to the Model.

Tutorial 3

When run, this program should produce output resembling:

http://somewhere/JohnSmith http://www.w3.org/2001/vcard-rdf/3.0#N
anon:14df86:ecc3dee17b:-7fff .
anon:14df86:ecc3dee17b:-7fff http://www.w3.org/2001/vcard-
rdf/3.0#Family "Smith" .
anon:14df86:ecc3dee17b:-7fff http://www.w3.org/2001/vcard-
rdf/3.0#Given "John" .
http://somewhere/JohnSmith http://www.w3.org/2001/vcard-rdf/3.0#FN
"John Smith" .

Each line
consists of
three fields
representing
the subject,
predicate
and object of each statement. 

There are four arcs in the Model, so there are four statements. The
"anon:14df86:ecc3dee17b:-7fff" is an internal identifier generated by Jena.

Tutorial 4 modifies tutorial 3 to write the model in RDF XML form to the standard
output stream. The code again, is very simple: model.write can take
an OutputStream argument.
RDF is usually embedded in an <rdf:RDF>
element. The element is optional if there are
other ways of know that some XML is RDF,
but it is usually present.

There is then an <rdf:Description> element


which describes the resource whose URI is
"http://somewhere/JohnSmith". If the
rdf:about attribute was missing, this element
would represent a blank node.

<rdf:RDF
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
xmlns:vcard='http://www.w3.org/2001/vcard-rdf/3.0#'
>
<rdf:Description rdf:about='http://somewhere/JohnSmith'>
<vcard:FN>John Smith</vcard:FN>
<vcard:N rdf:nodeID="A0"/>
</rdf:Description>
<rdf:Description rdf:nodeID="A0">
<vcard:Given>John</vcard:Given>
<vcard:Family>Smith</vcard:Family>
</rdf:Description>
</rdf:RDF>
The <vcard:FN> element describes a property
The <vcard:N> element is a resource. In this
of the resource. The property name is the "FN"
case the resource is represented by a relative
in the vcard namespace.
URI reference.
Jena has an extensible interface which allows new writers for different serialization languages for RDF to
be easily plugged in. The above call invoked the standard 'dumb' writer. Jena also includes a more
sophisticated RDF/XML writer which can be invoked by specifying another argument to
the write() method call:

// now write the model in XML form to a file


model.write(System.out, "RDF/XML-ABBREV");

This writer, the so called PrettyWriter, takes advantage of features of the RDF/XML abbreviated syntax
to write a Model more compactly. It is also able to preserve blank nodes where that is possible. It is
however, not suitable for writing very large Models, as its performance is unlikely to be acceptable. To
write large files and preserve blank nodes, write in N-Triples format:

// now write the model in XML form to a file


model.write(System.out, "N-TRIPLE");
Model m = ModelFactory.createDefaultModel(); # -- no special prefixes defined
String nsA = "http://somewhere/else#";
String nsB = "http://nowhere/else#"; <rdf:RDF
Resource root = m.createResource( nsA + "root" ); xmlns:j.0="http://nowhere/else#"
Property P = m.createProperty( nsA + "P" ); xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-
Property Q = m.createProperty( nsB + "Q" ); ns#"
Resource x = m.createResource( nsA + "x" ); xmlns:j.1="http://somewhere/else#" >
Resource y = m.createResource( nsA + "y" ); <rdf:Description rdf:about="http://somewhere/else#root">
Resource z = m.createResource( nsA + "z" ); <j.1:P rdf:resource="http://somewhere/else#x"/>
m.add( root, P, x ).add( root, P, y ).add( y, Q, z ); <j.1:P rdf:resource="http://somewhere/else#y"/>
System.out.println( "# -- no special prefixes defined" ); </rdf:Description>
m.write( System.out ); <rdf:Description rdf:about="http://somewhere/else#y">
System.out.println( "# -- nsA defined" ); <j.0:Q rdf:resource="http://somewhere/else#z"/>
m.setNsPrefix( "nsA", nsA ); </rdf:Description>
m.write( System.out ); </rdf:RDF>
System.out.println( "# -- nsA and cat defined" );
m.setNsPrefix( "cat", nsB );
m.write( System.out );
Blank Node
Represents a resource, but does not indicate a URI for the resource. Blank nodes act
like existentially qualified variables in first order logic.
Dublin Core
A standard for metadata about web resources. Further information can be found at
the Dublin Core web site.
Literal
A string of characters which can be the value of a property.
Object
The part of a triple which is the value of the statement
Predicate
The property part of a triple.
Property
A property is an attribute of a resource. For example DC.title is a property, as is
RDF.type.
Resource
Some entity. It could be a web resource such as web page, or it could be a concrete
physical thing such as a tree or a car. It could be an abstract idea such as chess or
football. Resources are named by URI's.
Statement
An arc in an RDF Model, normally interpreted as a fact.
Subject
The resource which is the source of an arc in an RDF Model
Triple
A structure containing a subject, a predicate and an object. Another term for a
statement.

You might also like