RDF Graph and Syntax


These triples together form RDF graph. A graph with the triples from figures showing triple and showing literal and with some additional triples are shown in the figure below. The top triple uses type as a predicate from RDF vocabulary to express that joesmith is of type Person.

A normative syntax for serializing RDF is RDF/XML. The RDF graph from the figure below is written in RDF/XML as follows. Note that it uses XML namespaces with prefixes defined in the beginning of the XML document.

      <rdf:RDF
          xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
          xmlns:foaf="http://xmlns.com/foaf/0.1/"
          xmlns="http://www.example.org/~joe/contact.rdf#">
        <foaf:Person rdf:about=
               "http://www.example.org/~joe/contact.rdf#joesmith">
          <foaf:mbox rdf:resource="mailto:joe.smith@example.org"/>
          <foaf:homepage
                     rdf:resource="http://www.example.org/~joe/"/>
          <foaf:family_name>Smith</foaf:family_name>
          <foaf:givenname>Joe</foaf:givenname>
        </foaf:Person>
      </rdf:RDF>

joe smith rdf

RDF graph describing Joe Smith

RDF/XML is a normative syntax, however, other serialization formats are used as well. The TURTLE and N3 syntax is less verbose than RDF/XML and so is quite popular. The Notation 3 (N3) is designed as a readable language for data on the Web that goes beyond RDF (it contains logical extensions and rules). The Terse RDF Triple Language (TURTLE) is a RDF-only subset of N3. For the purposes of this text these two languages are interchangeable. An example of N3 serialization of the graph from the figure above follows.

      @prefix :     <http://www.example.org/~joe/contact.rdf#> .
      @prefix foaf: <http://xmlns.com/foaf/0.1/> .
      @prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
      
      :joesmith a foaf:Person ;
            foaf:givenname "Joe" ;
            foaf:family_name "Smith" ;
            foaf:homepage <http://www.example.org/~joe/> ;
            foaf:mbox <mailto:joe.smith@example.org> .

The a in the first triple is a syntactic shortcut for rdf:type. Note that it N3 is similar to the linear form of conceptual graphs serialization. In the rest of this text we will use primarily the N3/TURTLE notation when expressing RDF. The same syntax is used for SPARQL RDF querying language.



Previous - Resource Description Framework           Next - RDF Elements


(c) Marek Obitko, 2007 - Terms of use