The data model of RDF is deceptively simple: it merely defines a directed binary relation between two resources: the binary relation is called a predicate or a property; the two resources are subject and object. These three elements form a triple and they are all identified by URIs. An object can be a constant data value instead of a URI but the subject and predicate must be URIs. Table 7.1 shows different equivalent notations for an RDF triple. The RDF/XML is the most widely used for storing and exchanging RDF information. The equivalent triple (or its more recent variant Turtle [86]) is easier for humans to type and to understand. The graphical form can also be useful to grasp relations between many resources, but it can become quite hairy when there are many resources and relations. A very useful tool for converting between different RDF notations is the RDF validator [77] which not only validates the input but can produce the corresponding graph or show the equivalent triples. Twinkle [87] provides a GUI interface to query RDF data, but it can also parse and produce the output of the queries in different notations of RDF.
Table 7.1. RDF Triples in different forms, all of them equivalent
Graphical form |
|
|
Triple | subject predicate object |
|
Relational form | predicate(subject,object) |
|
RDF/XML |
<rdf:Description rdf:about="subject"> <ex:predicate> <rdf:Description rdf:about="object"/> </ex:predicate> </rdf:Description> |
|
Turtle | subject ex:predicate object. |
Going from top to bottom, we see: the graphical notation in which the subject and object are linked by a labelled arrow; the triple format in which each component is a URI or data value in the case of an object; the relational form that would be the equivalent in Prolog; the RDF/XML exchange format and the Turtle format which, in the case of a single triple, only differs from the triple notation by its use of namespace prefix in URIs.
Information is represented by a set of RDF triples, often called a model. As it is a set, there is no ordering, nor repetition between triples within a model. Information is encoded as a conjunction of triples. Negation and disjunction cannot be expressed in RDF.
Figure 7.2. Selected information from the cellar-book
Graphical representation of triples. The circled numbers are not part of the
graphical representation, they are only given here for reference purposes. They
correspond to the numbers given in XML comments besides each
rdf:Description
in Example 7.1 and Example 7.2. The top part of this diagram deals with the RDF while
the bottom part deals with the RDF Schema (RDFS) explained in the next
section.
![]() |
All these RDF notations are equivalent, in fact the first thing an RDF parser does when it reads a file, is to transform the information in terms of triples, removing duplicates. The output files are produced by serializing the triples in the same or in another format.
Given the emphasis on XML in this document, we will first focus on the RDF/XML notation. But first, we will explain the concepts with a small set of relations given in the top part of Figure 7.2, the bottom part will be explained in the next section. Example 7.1 gives the corresponding RDF/XML version. As RDF predicates can link any subject and object, an arbitrary network of information can be built which is not necessarily limited to a tree like in XML
As shown in the fourth line of Table 7.1, a triple in
RDF/XML, is formed by a rdf:Description
element whose content is an
element named by the URI of the predicate having the object as content (see line 13‑
of Example 7.1). By embedding a predicate and its
object within a subject, it is easy to regroup triples that share a subject by writing
all predicates and their object within the subject element.
A triple can only indicate a binary relation. To indicate an n-ary relation between a subject and n objects, we make use of a blank node (indicated by a circle in Figure 7.2) which is a node with a local URI different from any other one in another file. We first make a relation between the subject and the blank node and then other relations between the blank node and the other objects. For example, to indicate that the cellar-book is located at a given street in a certain city, we first link the cellar-book with a blank node which is then linked to the name of the street and to the name of the city (see the arrow marked by a circled 5 in Figure 7.2).
Components of a triple are URIs which are usually quite long strings many of them
varying only at the end within the same file, so it is quite convenient to abbreviate
them using entities for the constant part. As the predicates are elements, the constant
part can be given as the namespace of the element. A practical way of achieving this is
to define an entity and the corresponding namespace prefix with the same letter. As the
entity is defined for the whole file, we can also use it for defining the namespace
prefix thus ensuring that they always correspond. We use this approach in Example 7.1 at line 3‑ and line 7‑
. Another way of abbreviating URIs is to make them
relative to another one using
xml:base
, see line 11‑
of Example 7.1.
An object can either be a URI or a string value. In the latter case, the string is
given as the content of the predicate element. The predicate and its string value can
also appear as an attribute with its value of the rdf:Description
element
of the subject (see line 20‑
of Example 7.1).
Example 7.1. [CBWC-RDF-S.rdf
] Subject, Predicate and Object triples for the
cellar book in RDF/XML.
Selected information from Example 2.2 coded in RDF/XML. The information was selected to illustrate different features of RDF/XML.
1 <?xml version="1.0" encoding="UTF-8"?> <?oxygen RNGSchema="rdfxml.rnc" type="compact"?><!DOCTYPE RDF [
<!ENTITY wc "http://www.iro.umontreal.ca/lapalme/WineCatalog#" > 5 <!ENTITY cb "http://www.iro.umontreal.ca/lapalme/CellarBook" > ]> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:wc="&wc;" 10 xmlns:cb="&cb;#" xml:base="&cb;">
<rdf:Description
rdf:about="http://www.iro.umontreal.ca/lapalme/CellarBook#theCellar"> 15 <cb:ownedBy> <!-- 1 --> <rdf:Description rdf:about="&cb;#JudeRaisin"/> </cb:ownedBy> </rdf:Description> 20 <rdf:Description
rdf:about="http://www.iro.umontreal.ca/lapalme/CellarBook#JudeRaisin" cb:street="1234 rue des Châteaux" cb:city="St-George"> <cb:named rdf:parseType="Resource"> <!-- 2 --> <cb:first>Jude</cb:first> 25 <cb:family>Raisin</cb:family> </cb:named> </rdf:Description> <rdf:Description rdf:about="#JudeRaisin"><!-- 3 -->
30 <cb:loved rdf:resource="&wc;C00043125"/> <cb:loved rdf:resource="&wc;C00871996"/> <cb:comment rdf:parseType="Literal">this is <b>great</b>!</cb:comment> </rdf:Description> 35 <rdf:Bag rdf:ID="theCellar"> <!-- 4 -->
<rdf:li rdf:resource="&wc;C00043125"/> <rdf:li rdf:resource="&wc;C00042101"/> <rdf:li rdf:resource="&wc;C00871996"/> </rdf:Bag> 40 <rdf:Description rdf:about="#theCellar"><!-- 5 -->
<cb:locatedAt rdf:nodeID="loc"/> </rdf:Description> 45 <rdf:Description rdf:nodeID="loc"> <!-- 6 -->
<cb:street>4587 des Futailles</cb:street> <cb:city>Vallée des crus</cb:city> </rdf:Description> 50 <!-- Schema definition -->
<!-- Classes --> <rdfs:Class rdf:ID="Person"/> <!-- 7 -->
55 <rdfs:Class rdf:ID="Cellar"/> <rdfs:Class rdf:ID="Wine"/> <!-- Properties --> <rdf:Property rdf:ID="loved"> <!-- 8 -->
60 <rdfs:domain rdf:resource="#Person"/> <rdfs:range rdf:resource="#Wine"/> </rdf:Property> <rdf:Property rdf:ID="ownedBy"> <!-- 9 -->
65 <rdfs:domain rdf:resource="#Cellar"/> <rdfs:range rdf:resource="#Person"/> </rdf:Property> </rdf:RDF>
|
XML validation can be done using the Relax-NG schema given in appendix A of the RDF definition [76]. Note that this validation only validates the form of the XML file and is different from the schema notion used in RDFS explained in the next section. |
|
Defines two entities to simplify the writing of an URI. |
|
Starts an RDF model by setting the appropriate namespaces.
|
|
Defines the base for relative URI in this document indicated by
|
|
The cellar-book is owned by the resource identified by
|
|
Description of |
|
|
|
The cellar-book, referred by the id |
|
The cellar-book has complex information, so it is regrouped under a
blank node referred to by a |
|
Regrouping the information about the location within a blank node. The string information of the object is given as the value of the predicate element. |
|
Start of the RDFS part that will be further explained in the next section. |
|
Definition of three classes identified with IDs within the namespace
identified by the |
|
Defines the |
|
Defines a |
Although RDF/XML is a convenient triple notation for computers, it is not very
user-friendly. So alternatives have been developed, one of the most widespread being the
Terse RDF Triple Language
more commonly called
Turtle
[86]. The main rules for writing Turtle triplets are the
following:
There are three types of terms:
QNAME
i.e. an identifier preceded by a
namespace prefix and a colon. A namespace prefix is defined with
a @prefix
definition. The full URI is obtained
by concatenating the content of the namespace prefix with the
rest of the r-uri;. A namespace prefix can be empty but the :
still appears.
^^
followed by a
type name, most often of the form xsd:...
for
standard XML Schema types.
_:nodeId
, a []
or a
parenthesized group (explained below)
p
is defined by @prefix p:
URI
.
ex:a ex:b ex:c, ex:d.
is the same as
ex:a ex:b ex:c. ex:a ex:b ex:d.
ex:a ex:b ex:c; ex:d ex:e.
is the
same as ex:a ex:b ex:c. ex:a ex:d ex:e.
A blank node of the form _:nodeId
can also be noted as []
when the nodeId
is not used elsewhere. A blank node as subject such as
[] ex:p "o"
can be noted as [ex:p "o"]
. This type of
bracketing can be used in either subject or object position and combined with commas and
semi-colons. Table 7.2 compares the bracket notation with the
corresponding triples using blank nodes.
Table 7.2. Comparison of Turtle brackets with triples
[] ex:p "o" . |
_:b0 ex:p "o" . |
[ex:p "o"] . |
_:b1 ex:p "o" . |
[ex:p "o"] ex:q ex:o2 . |
_:b2 ex:p "o". |
_:b2 ex:q ex:o2 . |
|
ex:s ex:p [ex:p1 ex:o]. |
ex:s ex:p _:b3 . |
_:b3 ex:p1 ex:o . |
|
[ex:p ex:o;ex:p1 "o1"] |
_:b4 ex:p ex:o . |
_:b4 ex:p1 "o1" . |
Comparison between the bracketed notation for blank nodes and the corresponding triples.
Jena [68] provides libraries and a command line tool
rdfcopy
for parsing and writing RDF triples in different notations,
thus providing a simple conversion tool between these notations.
Example 7.2. [CBWC-RDF-S.ttl
] The Turtle version of Example 7.1
An easier to type and to read version of the RDF information described in
Example 7.1. As before, this section only deals with the RDF
part and not the RDFS part starting at line 22‑. In
Turtle, comments start with # and span for the rest of the line. In this example,
the numbers in comments correspond to the lines with the same numbers within XML
comments in Example 7.1.
1 @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix cb: <http://www.iro.umontreal.ca/lapalme/CellarBook#> . @prefix wc: <http://www.iro.umontreal.ca/lapalme/WineCatalog#> . 5 cb:theCellar
cb:ownedBy cb:JudeRaisin ; # 1 a rdf:Bag ; # 4
rdf:_1 wc:C00043125 ; 10 rdf:_2 wc:C00042101 ; rdf:_3 wc:C00871996 ; cb:locatedAt [ cb:city "Vallée des crus" ; # 5,6 cb:street "4587 des Futailles"] . 15 cb:JudeRaisin cb:city "St-George" ; # 2
cb:named [ cb:family "Raisin" ;
cb:first "Jude" ] ; cb:loved wc:C00043125 , wc:C00871996 ; # 3
cb:comment "this is <b>great</b>!"^^rdf:XMLLiteral ; 20 cb:street "1234 rue des Châteaux" . # Schema part in RDFS
cb:Person a rdfs:Class . # 7
25 cb:Cellar a rdfs:Class . cb:Bottle a rdfs:Class . cb:loved # 8
a rdf:Property ; 30 rdfs:domain cb:Person ; rdfs:range cb:Wine . cb:ownedBy # 9
a rdf:Property ; 35 rdfs:domain cb:Cellar ; rdfs:range cb:Person .
|
Definition of namespace prefixes. As prefixes can also be used for subjects and objects of triples, which is not the case in RDF/XML, base definition is less useful, but still possible. |
|
Six predicates sharing |
|
The notation for a container in Turtle corresponds to the graphical representation:
here, the bag is represented by a link to the predefined
|
|
Four predicates having |
|
A blank node is used as object of |
|
Two
objects in namespaces |
|
Start of the RDFS part further described in the next section. |
|
Definition of three classes in |
|
Defines the |
|
Defines a |