A Simple Vcard Might Look Like This in RDF
A Simple Vcard Might Look Like This in RDF
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.
Resources have properties.
Each arc in an RDF Model is called a statement. Each statement asserts a fact about a
resource. A statement has three parts:
Tutorial 3
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.
<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:
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: