Resource Description Framework (RDF)

2008-12-24

Tyng-Ruey Chuang
trc@iis.sinica.edu.tw

Institute of Information Science
Academia Sinica, Taipei, Taiwan

What is Resource Description Framework (RDF) for?

The Main Idea of RDF

RDF Graph

RDF/XML: RDF in XML-based Syntax

RDF: Making Statements about Resources

RDF Terminology for Making Statements

RDF: Making Machine-processable Statements

The RDF Model

The Triple Notation for RDF Graphs

Vocabulary in RDF

More on URIrefs and Vocabularies

Advantages of using URIrefs as RDF's basic way of identifying things (using the following RDF graph as an example):

More Information About John Smith

Note that RDF uses URIrefs as predicates in RDF statements. That is, rather than using character strings such as "creator" or "name" to identify properties, RDF uses URIrefs. Using URIrefs to identify properties has several advantages:

Using URIrefs as subjects, predicates, and objects in RDF statements supports the development and use of shared vocabularies on the Web.

For this reason, it is a good idea to try to use terms from existing vocabularies (such as the Dublin Core) where possible, rather than making up new terms that might overlap with those of some other vocabulary.

Structured Property Values

A person's whole address could be written out as a plain literal, as in the following triple:

exstaff:85740   exterms:address   "1501 Grant Avenue, Bedford, Massachusetts 01730" .

What if the address needed to be recorded as a structure consisting of separate street, city, state, and postal code values? This is solved in RDF by the following:

exstaff:85740       exterms:address        exaddressid:85740 .
exaddressid:85740   exterms:street         "1501 Grant Avenue" .
exaddressid:85740   exterms:city           "Bedford" .
exaddressid:85740   exterms:state          "Massachusetts" .
exaddressid:85740   exterms:postalCode     "01730" .
More Information About John Smith

Blank Nodes

Using a Blank Node
exstaff:85740   exterms:address         _:johnaddress .
_:johnaddress   exterms:street          "1501 Grant Avenue" .
_:johnaddress   exterms:city            "Bedford" .
_:johnaddress   exterms:state           "Massachusetts" .
_:johnaddress   exterms:postalCode      "01730" .

Typed Literals

An RDF typed literal is formed by pairing a string with a URIref that identifies a particular datatype. The value represented by the typed literal is the value that the specified datatype associates with the specified string. The datatypes used in typed literals are defined externally to RDF, and identified by their datatype URIs.

Example:

A Typed Literal for John Smith's Age

Triple notation:

<http://www.example.org/staffid/85740>  <http://www.example.org/terms/age> "27"^^<http://www.w3.org/2001/XMLSchema#integer> .

Or, using the QName abbreviation:

exstaff:85740  exterms:age  "27"^^xsd:integer .

RDF/XML: An XML Syntax for RDF

A RDF graph:

Several Statements About the Same Resource

Its RDF/XML presentation:

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
            xmlns:dc="http://purl.org/dc/elements/1.1/"
            xmlns:exterms="http://www.example.org/terms/">

  <rdf:Description rdf:about="http://www.example.org/index.html">

      <exterms:creation-date>August 16, 1999</exterms:creation-date>
  </rdf:Description>

  <rdf:Description rdf:about="http://www.example.org/index.html">
      <dc:language>en</dc:language>

  </rdf:Description>

  <rdf:Description rdf:about="http://www.example.org/index.html">
      <dc:creator rdf:resource="http://www.example.org/staffid/85740"/>
  </rdf:Description>

</rdf:RDF>

An abbreviation:

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
            xmlns:dc="http://purl.org/dc/elements/1.1/"
            xmlns:exterms="http://www.example.org/terms/">

  <rdf:Description rdf:about="http://www.example.org/index.html">

       <exterms:creation-date>August 16, 1999</exterms:creation-date>
       <dc:language>en</dc:language>
       <dc:creator rdf:resource="http://www.example.org/staffid/85740"/>
  </rdf:Description>

</rdf:RDF>

Blank Nodes in RDF/XML

A RDF graph:

A Graph Containing a Blank Node

Its RDF/XML presentation:

<?xml version="1.0"?>

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
            xmlns:dc="http://purl.org/dc/elements/1.1/"
            xmlns:exterms="http://example.org/stuff/1.0/">

   <rdf:Description rdf:about="http://www.w3.org/TR/rdf-syntax-grammar">
     <dc:title>RDF/XML Syntax Specification (Revised)</dc:title>
     <exterms:editor rdf:nodeID="abc"/>
   </rdf:Description>

   <rdf:Description rdf:nodeID="abc">
       <exterms:fullName>Dave Beckett</exterms:fullName>
       <exterms:homePage rdf:resource="http://purl.org/net/dajobe/"/>
   </rdf:Description>

</rdf:RDF>

Typed Literals in RDF/XML

A triple with typed literal:

ex:index.html   exterms:creation-date   "1999-08-16"^^xsd:date .

Its RDF/XML presentation:

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
            xmlns:exterms="http://www.example.org/terms/">

 <rdf:Description rdf:about="http://www.example.org/index.html">
   <exterms:creation-date rdf:datatype=
     "http://www.w3.org/2001/XMLSchema#date">1999-08-16
   </exterms:creation-date>
 </rdf:Description>

</rdf:RDF>

Abbreviation using internal DTD subset:

<?xml version="1.0"?>

<!DOCTYPE rdf:RDF [<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">]>

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
            xmlns:exterms="http://www.example.org/terms/">

  <rdf:Description rdf:about="http://www.example.org/index.html">
    <exterms:creation-date rdf:datatype="&xsd;date">1999-08-16
    </exterms:creation-date>

  </rdf:Description>

</rdf:RDF>

Use Fragment Identifiers and Base URIs in RDF/XML

An Example:

<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">]>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
            xmlns:exterms="http://www.example.com/terms/"
            xml:base="http://www.example.com/2002/04/products">

  <rdf:Description rdf:ID="item10245">
       <exterms:model rdf:datatype="&xsd;string">Overnighter</exterms:model>
       <exterms:sleeps rdf:datatype="&xsd;integer">2</exterms:sleeps>
       <exterms:weight rdf:datatype="&xsd;decimal">2.4</exterms:weight>
       <exterms:packedSize rdf:datatype="&xsd;integer">784</exterms:packedSize>
  </rdf:Description>

</rdf:RDF>

The above statement (the rdf:Description element) talks about the resource located at http://www.example.com/2002/04/products#item10245.

Class in RDF

What a RDF resource is described with a predefined rdf:type property, the value of that property is considered to be a resource that represents a category or class of things, and the subject of that property is considered to be an instance of that category or class.

An example:

<?xml version="1.0"?>

<!DOCTYPE rdf:RDF [<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">]>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
            xmlns:exterms="http://www.example.com/terms/"
            xml:base="http://www.example.com/2002/04/products">

  <rdf:Description rdf:ID="item10245">
       <rdf:type rdf:resource="http://www.example.com/terms/Tent"/>
       <exterms:model rdf:datatype="&xsd;string">Overnighter</exterms:model>
       <exterms:sleeps rdf:datatype="&xsd;integer">2</exterms:sleeps>
       <exterms:weight rdf:datatype="&xsd;decimal">2.4</exterms:weight>
       <exterms:packedSize rdf:datatype="&xsd;integer">784</exterms:packedSize>
  </rdf:Description>
</rdf:RDF>

Resource http://www.example.com/2002/04/products#item10245 is an instance of the class http://www.example.com/terms/Tent. Note that a class is in itself a resource.

Typed Node in RDF

It is fairly common in RDF for resources to have rdf:type properties that describe the resources as instances of specific types or classes. Such resources are called typed nodes in the graph, or typed node elements in the RDF/XML.

RDF/XML provides a special abbreviation for describing these typed nodes. In this abbreviation, the rdf:type property and its value are removed, and the rdf:Description element for the node is replaced by an element whose name is the QName corresponding to the value of the removed rdf:type property (a URIref that names a class).

The previous example, in abbreviation :

<?xml version="1.0"?>

<!DOCTYPE rdf:RDF [<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">]>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
            xmlns:exterms="http://www.example.com/terms/"
            xml:base="http://www.example.com/2002/04/products">

  <exterms:Tent rdf:ID="item10245">
       <exterms:model rdf:datatype="&xsd;string">Overnighter</exterms:model>
       <exterms:sleeps rdf:datatype="&xsd;integer">2</exterms:sleeps>
       <exterms:weight rdf:datatype="&xsd;decimal">2.4</exterms:weight>
       <exterms:packedSize rdf:datatype="&xsd;integer">784</exterms:packedSize>
  </exterms:Tent>
</rdf:RDF>

RDF Containers

RDF provides a container vocabulary for describing things in groups. A container is a resource that contains other things (called members). The members of a container may be resources or literals.

RDF defines three types of containers:

RDF Containers: An Example

"Course 6.001 has the students Amy, Mohamed, Johann, Maria, and Phuong":

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:s="http://example.org/students/vocab#">

   <rdf:Description rdf:about="http://example.org/courses/6.001">
      <s:students>
         <rdf:Bag>
            <rdf:li rdf:resource="http://example.org/students/Amy"/>
            <rdf:li rdf:resource="http://example.org/students/Mohamed"/>
            <rdf:li rdf:resource="http://example.org/students/Johann"/>
            <rdf:li rdf:resource="http://example.org/students/Maria"/>
            <rdf:li rdf:resource="http://example.org/students/Phuong"/>
         </rdf:Bag>
      </s:students>
   </rdf:Description>
</rdf:RDF>

Note that, in forming the corresponding graph, the the numbered properties rdf:_1, rdf:_2, and so on are generated from the rdf:li elements:

A Simple Bag Container Description

RDF Schema

RDF Schema provides the facilities needed to describe application-specific classes and properties, and to indicate which classes and properties are expected to be used together.

RDF Schema provides a type system for RDF. The RDF Schema type system is similar in some respects to the type systems of object-oriented programming languages. That is, it allows resources to be defined as instances of one or more classes. In addition, it allows classes to be organized in a hierarchical fashion.

The RDF Schema facilities are themselves provided in the form of an RDF vocabulary; that is, as a specialized set of predefined RDF resources with their own special meanings. The resources in the RDF Schema vocabulary have URIrefs with the prefix http://www.w3.org/2000/01/rdf-schema# (conventionally associated with the QName prefix rdfs:).

Describing Classes

In RDF Schema, a class is any resource having an rdf:type property whose value is the resource rdfs:Class.

Often a class to be described is a specialization of an existing class. This kind of relationship between the two classes is described using the predefined rdfs:subClassOf property.

An example (in triple notation):

ex:MotorVehicle       rdf:type          rdfs:Class .
ex:PassengerVehicle   rdf:type          rdfs:Class .
ex:Van                rdf:type          rdfs:Class .
ex:Truck              rdf:type          rdfs:Class .
ex:MiniVan            rdf:type          rdfs:Class .

ex:PassengerVehicle   rdfs:subClassOf   ex:MotorVehicle .
ex:Van                rdfs:subClassOf   ex:MotorVehicle .
ex:Truck              rdfs:subClassOf   ex:MotorVehicle .

ex:MiniVan            rdfs:subClassOf   ex:Van .
ex:MiniVan            rdfs:subClassOf   ex:PassengerVehicle .

The RDF model:

A Vehicle Class Hierarchy

Describing Properties

In RDF Schema, properties are described using the RDF class rdf:Property, and the RDF Schema properties rdfs:domain, rdfs:range, and rdfs:subPropertyOf.

All properties in RDF are described as instances of class rdf:Property.

The rdfs:range property is used to indicate that the values of a particular property are instances of a designated class.

The rdfs:domain property is used to indicate that a particular property applies to a designated class.

RDF Schema provides a way to specialize properties as well as classes. This specialization relationship between two properties is described using the predefined rdfs:subPropertyOf property.

RDF Schema Document: An Example

<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">]>
<rdf:RDF   
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"  
  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
  xml:base="http://example.org/schemas/vehicles">

<rdfs:Class rdf:ID="MotorVehicle"/>

<rdfs:Class rdf:ID="PassengerVehicle">

  <rdfs:subClassOf rdf:resource="#MotorVehicle"/>
</rdfs:Class>

<rdfs:Class rdf:ID="Truck">
  <rdfs:subClassOf rdf:resource="#MotorVehicle"/>
</rdfs:Class>

<rdfs:Class rdf:ID="Van">
  <rdfs:subClassOf rdf:resource="#MotorVehicle"/>

</rdfs:Class>

<rdfs:Class rdf:ID="MiniVan">
  <rdfs:subClassOf rdf:resource="#Van"/>
  <rdfs:subClassOf rdf:resource="#PassengerVehicle"/>
</rdfs:Class>

<rdfs:Class rdf:ID="Person"/>

<rdfs:Datatype rdf:about="&xsd;integer"/>

<rdf:Property rdf:ID="registeredTo">
  <rdfs:domain rdf:resource="#MotorVehicle"/>
  <rdfs:range rdf:resource="#Person"/>
</rdf:Property>

<rdf:Property rdf:ID="rearSeatLegRoom">

  <rdfs:domain rdf:resource="#PassengerVehicle"/> 
  <rdfs:range rdf:resource="&xsd;integer"/>
</rdf:Property>

<rdf:Property rdf:ID="driver">
  <rdfs:domain rdf:resource="#MotorVehicle"/>
</rdf:Property>

<rdf:Property rdf:ID="primaryDriver">
  <rdfs:subPropertyOf rdf:resource="#driver"/>
</rdf:Property>

</rdf:RDF>

An Instance

<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [<!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">]>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
            xmlns:ex="http://example.org/schemas/vehicles#"
            xml:base="http://example.org/things">

  <ex:PassengerVehicle rdf:ID="johnSmithsCar">
       <ex:registeredTo rdf:resource="http://www.example.org/staffid/85740"/>
       <ex:rearSeatLegRoom 
           rdf:datatype="&xsd;integer">127</ex:rearSeatLegRoom>
       <ex:primaryDriver rdf:resource="http://www.example.org/staffid/85740"/>
  </ex:PassengerVehicle>

</rdf:RDF>