Resource Description Framework RDF and Turtle

1. RDF

1.1 INTRODUCTION

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 http://www.w3.org/1999/02/22-rdf-syntax-ns# If the namespace prefix of is RDF, the QName of QName rdf:type will be extended to http://www.w3.org/1999/02/22-rdf-syntax-ns#type .

  • 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: http://example.org

  • 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:

<http://www.sciam.com> <http://purl.org/dc/elements/1.1/title> "Scientific American" .

For longer literals, you can use three double quotes.

<http://www.sciam.com> <http://purl.org/dc/elements/1.1/title> """This is a multi-line
literal""" .

2.1.2 namespace in turtle

The @ prefix definition is used without angle brackets.

@prefix dc: <http://purl.org/dc/elements/1.1/> .
<http://www.sciam.com> dc:creator <mailto:john @example.org> .

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 <http://example.org/data> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<#john> foaf:name "John Smith" .

amount to

<http://example.org/data#john> <http://xmlns.com/foaf/0.1/name> "John Smith" .

2.1.4 predicate list

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

@prefix dc: < http://purl.org/dc/elements/1.1/> .
<http://example.org> dc:title "Example Inc. Homepage" ;
                     dc:creator <mailto:john @example.org> .

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: < http://purl.org/dc/elements/1.1/> .
<http://example.org> dc:creator <mailto:john @example.org> ,
                                <mailto:sally@example.org> .

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: < http://purl.org/dc/elements/1.1/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<http://www.example.org/> 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: < http://purl.org/dc/elements/1.1/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<http://example.org/> dc:creator [ foaf:name "John Smith" ] .
<http://test.example.org/> 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: < http://purl.org/dc/elements/1.1/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
<http://example.org/> dc:creator _:foo .
<http://test.example.org/> 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: < http://purl.org/dc/elements/1.1/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<http://example.org/> 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: < http://purl.org/dc/elements/1.1/> .
<http://example.org/foreword> dc:title "Foreword"@en .
<http://example.org/foreword> 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: <http://example.org/ontology/> .
<http://example.org/> 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: < http://purl.org/dc/elements/1.1/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<> dc:date "2020-01-26"^^xsd:date ;
   dc:creator <mailto:nmg@ecs.soton.ac.uk> .

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: <http://purl.org/dc/elements/1.1/> .
<http://example.org> dc:creator ( <mailto:john@example.org>
                                  <mailto:bill@example.org>
                                  <mailto:sally@example.org> ) .

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

@prefix dc: <http://purl.org/dc/elements/1.1/> .
<http://example.org> dc:creator <mailto:john@example.org> ,
                                <mailto:bill@example.org> ,
                                <mailto:sally@example.org> .

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