Resource Description Framework RDF and Turtle

1. RDF


The standard data model of RDF (Resource Description Framework) semantic Web is a framework for describing resources on the Web. RDF itself is represented as an XML file.

RDF specifies in the form of subject predicate object triples to represent the relationship between resources. The set of RDF statements represents a marked and directional graph.

RDF is used as the basis of other knowledge representation and ontology languages in semantic web.

1.2 format

  • RDF/XML: the oldest syntax, supported by almost all tools, but not humanized in any way

  • RDF/N3 family: compact, humanized, non XML syntax: N3, NTriples, Turtle

  • Other XML and non-XML syntaxes: TriX, JSON-LD, etc

1.3 RDF requirements

  • Means of identifying objects and vocabulary terms (URIs);

  • Ways to distinguish different words (namespaces and qualified names);

    • RDF syntax uses namespaces to abbreviate URIs to qualified names (QNames)

    • A QName consists of a namespace prefix, a colon, and a local name
      For example: rdf:type, dc:creator, foaf:Person

    • Namespace prefix corresponds to URI prefix

      For example: given URI If the namespace prefix of is RDF, the QName of QName rdf:type will be extended to .

  • A method of serializing three elements (a data format).

2. Turtle

Turtle (Terse RDF Triple Language) has become a common standard for serializing RDF data models because of its easy to read and write characteristics.

  • Resource URIs are written in angle brackets:

  • The literal quantity is written in double quotation marks: "like this"

  • Triples end with a period:

  • whitespace is not important

2.1 grammar

2.1.1 simple triples

Literal quantity as object:

<> <> "Scientific American" .

For longer literals, you can use three double quotes.

<> <> """This is a multi-line
literal""" .

2.1.2 namespace in turtle

The @ prefix definition is used without angle brackets.

@prefix dc: <> .
<> dc:creator <mailto:john> .

2.1.3 Base URI

@Base introduces a base URI, and the identifiers of all URI fragments are extended relative to this URI (similar to the use of xml:base in RDF/XML).

@base <> .
@prefix foaf: <> .
<#john> foaf:name "John Smith" .

amount to

<> <> "John Smith" .

2.1.4 predicate list

When a subject is quoted by multiple predicates, they have repeated subjects. Use semicolons; separate.

@prefix dc: <> .
<> dc:title "Example Inc. Homepage" ;
                     dc:creator <mailto:john> .

2.1.5 object list

Like the predicate, the object is often repeated with the same subject and predicate. Use commas to separate.

@prefix dc: <> .
<> dc:creator <mailto:john> ,
                                <> .

2.1.6 blank nodes (bNodes)

Sometimes we have resources that we don't want to identify with URI s. These are blank nodes or anonymous resources.

@prefix dc: <> .
@prefix foaf: <> .
<> dc:creator [ foaf:name "John Smith" ] .

However, the [] syntax is not enough to explicitly represent all graphs with blank nodes. For example, in the following example, it is difficult to show that the two blank nodes are the same.

@prefix dc: <> .
@prefix foaf: <> .
<> dc:creator [ foaf:name "John Smith" ] .
<> dc:creator [ foaf:name "John Smith" ] .

The ambiguity caused by blank nodes can be solved by using node IDs. Node IDs is a specific serialized local identifier of the RDF graph.

  • Node IDs appear to have_ (underscore) qNames of the namespace prefix.

  • For example:.: a123,_: foo, _: bar

  • Node IDs cannot be referenced outside the scope of the definition diagram

When an RDF file is parsed and serialized, the Node IDs cannot be guaranteed to remain unchanged: the identifier string may change, but the structure of the graph will remain unchanged. Using Node IDs, the above example can be changed to:

@prefix dc: <> .
@prefix foaf: <> .
<> dc:creator _:foo .
<> dc:creator _:foo .
_:foo foaf:name "John Smith" .

2.1.7 data type

Many applications need to be able to distinguish between different types of literal symbols, such as integers, dates, and decimals. RDF uses the XML Schema data type.

@prefix dc: <> .
@prefix xsd: <> .
<> dc:date "2020-01-27"^^xsd:date .

RDF supports literal language annotations. Use the language recognized by ISO369-1 two letter code: en, zh, fr, de, es.

@prefix dc: <> .
<> dc:title "Foreword"@en .
<> dc:title "Avant-propos"@fr .

2.1.8 Class membership

The membership of an object in a class is represented by the rdf:type attribute. Turtle let's abbreviate rdf:type with 'a'.

@prefix ex: <> .
<> a ex:Website .

2.1.9 empty URI

Empty URI s are represented by < >. The assertion about null URIref is about the RDF graph itself.

@prefix dc: <> .
@prefix xsd: <> .
<> dc:date "2020-01-26"^^xsd:date ;
   dc:creator <> .

2.1.10 assembly

Set (rdf:List) is a way to express ordered groups in RDF.

  • Recursive definition: a set consists of the first item in the set and another set, which is the remaining item.

  • Resources representing an empty collection: rdf:nil

  • Similar to the cons/car/cdr list in Lisp

    rdf:first is equivalent to car: the first item in a set

    rdf:rest is equivalent to the rest of the cdr: set

  • Immutable: it cannot be changed without changing the form of the set.

Collections are relatively uncommon in normal RDF, but are widely used in RDF serialization of OWL.

The Turtle syntax for a collection uses parentheses ().

@prefix dc: <> .
<> dc:creator ( <>
                                  <> ) .

It is worth noting that these two pictures are fundamentally different things. In this picture, There is only one creator, that is, a container. But in the picture below There are three creators. Therefore, there is no specific order for the three objects in this figure.

@prefix dc: <> .
<> dc:creator <> ,
                                <> ,
                                <> .

Posted by werushka on Thu, 14 Apr 2022 06:41:21 +0930