The core structure of the abstract syntax is a set of
triples
, each consisting of a
subject
, a
predicate
and an
object
.
A set of such triples is called an RDF graph.
An RDF graph can be visualized as a node and directed-arc diagram, in which each triple is represented as a node-arc-node link.
There can be three kinds of nodes in an RDF graph:
IRIs
,
literals
, and
blank nodes
.
2.2. Resources and Statements
Any
IRI
or
literal(这里注意RDF图中的结点一共有3类:IRI、literal、blank node)
denotes something in the world (the "universe of discourse").
These things are called resources.
Anything can be a resource, including physical things, documents, abstract concepts, numbers and strings; the term is synonymous with "entity" as it is used in the RDF Semantics specification.
The resource denoted by an
IRI
is called its
referent
, and the resource denoted by a
literal
is called its
literal value
.
Literals have datatypes
that define the range of possible values, such as strings, numbers, and dates.
Asserting an RDF triple says that some
relationship
, indicated by the
predicate
, holds
between
the resources denoted by the
subject
and
object
. This statement corresponding to an RDF triple is known as an RDF statement. The
predicate
itself is an
IRI
and denotes a
property
, that is, a
resource
that can be thought of as a
binary relation
. (
Relations that involve more than two entities can only be indirectly expressed in RDF
)
Unlike IRIs and literals,
blank nodes do not identify specific resources.
Statements involving blank nodes say that something with the given relationships exists, without explicitly naming it.
2.3. RDF Vocabularies and Namespace IRIs
An RDF vocabulary is a collection of IRIs intended for use in RDF graphs.
For example, the IRIs documented in [RDF11-SCHEMA] are the RDF Schema vocabulary. RDF Schema can itself be used to define and document additional RDF vocabularies.
The IRIs in an RDF vocabulary often
begin with
a common substring known as a
namespace IRI
. Some namespace IRIs are associated by convention with a
short name
known as a
namespace prefix
. Some examples:
In some serialization formats it is common to abbreviate IRIs that start with namespace IRIs by using a namespace prefix in order to assist readability. For example, the IRI
http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral
would be abbreviated as
rdf:XMLLiteral
.
2.4. RDF Documents and Syntaxes
An RDF document is a document that encodes an RDF graph or RDF dataset in a
concrete RDF syntax
, such as Turtle [TURTLE], RDFa [RDFA-PRIMER], JSON-LD [JSON-LD], or TriG [TRIG]. RDF documents enable the exchange of RDF graphs and RDF datasets between systems.
2.5. RDF Graphs
An
RDF graph
is a set of
RDF triples
.
2.6. Triples
An RDF triple consists of three components:
the subject, which is an IRI or a blank node
the predicate, which is an IRI
the object, which is an IRI, a literal or a blank node
An RDF triple is conventionally written in the order subject, predicate, object.
IRIs
,
literals
and
blank nodes
are collectively known as
RDF terms
.
2.7. IRIs
An
IRI (Internationalized Resource Identifier)
within an RDF graph is a
Unicode string
[UNICODE] that conforms to the syntax defined in RFC 3987 [RFC3987].
IRIs in the RDF abstract syntax
must be absolute
, and
may contain a fragment identifier
.
2.8. Blank Nodes
Blank node identifiers are local identifiers that are used in some concrete RDF syntaxes or RDF store implementations.
They are always locally scoped to the file or RDF store, and are not persistent or portable identifiers for blank nodes. Blank node identifiers are not part of the RDF abstract syntax, but are entirely dependent on the concrete syntax or implementation. The syntactic restrictions on blank node identifiers, if any, therefore also depend on the concrete RDF syntax or implementation. Implementations that handle blank node identifiers in concrete syntaxes need to be careful not to create the same blank node from multiple occurrences of the same blank node identifier except in situations where this is supported by the syntax.
2.9. Fragment Identifiers
RDF uses IRIs, which may include fragment identifiers, as resource identifiers. The semantics of fragment identifiers is defined in RFC 3986 [RFC3986]:
They identify a secondary resource that is usually a part of, view of, defined in, or described in the primary resource
, and the precise semantics depend on the set of representations that might result from a retrieval action on the primary resource.
3. RDF 1.1 Turtle 语法
3.1. 是什么
A Turtle document is a textual representations of an RDF graph, a concrete syntax for RDF.
A Turtle document allows writing down an RDF graph
in a compact textual form
. An RDF graph is made up of triples consisting of a subject, predicate and object.
@base <http://example.org/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix rel: <http://www.perceive.net/schemas/relationship/> .
<#green-goblin>
rel:enemyOf <#spiderman> ;
a foaf:Person ; # in the context of the Marvel universe
foaf:name "Green Goblin" .
<#spiderman>
rel:enemyOf <#green-goblin> ;
a foaf:Person ;
foaf:name "Spiderman", "Человек-паук"@ru .
3.2. Simple Triples
The simplest triple statement is a
sequence of (subject, predicate, object)
terms,
separated by whitespace
and
terminated by '.'
after each triple.
Often the same subject will be referenced by a number of predicates. The predicateObjectList production matches a series of predicates and objects,
separated by ';'
, following a subject. This expresses a series of RDF Triples with that subject and each predicate and object allocated to one triple. Thus,
the ';' symbol is used to repeat the subject of triples that vary only in predicate and object RDF terms.
As with predicates often objects are repeated with the same subject and predicate. The objectList production matches a series of objects
separated by ','
following a predicate. This expresses a series of RDF Triples with the corresponding subject and predicate and each object allocated to one triple. Thus,
the ',' symbol is used to repeat the subject and predicate of triples that only differ in the object RDF term.
IRIs
may be written as
relative
or
absolute IRIs
or
prefixed names
.
Relative and absolute IRIs are enclosed in '<' and '>'
and may contain numeric escape sequences (described below). For example <http://example.org/#green-goblin>.
Relative IRIs
like <#green-goblin> are resolved
relative to the current base IRI
. A new base IRI can be defined using the '
@base
' or 'BASE' directive.
The
token 'a'
in the predicate position of a Turtle triple represents the IRI
http://www.w3.org/1999/02/22-rdf-syntax-ns#type
.
A prefixed name is a prefix label and a local part, separated by a colon ":"
. A prefixed name is turned into an IRI by
concatenating
the IRI associated with the prefix and the local part. The '@prefix' or 'PREFIX' directive associates a prefix label with an IRI. Subsequent '@prefix' or 'PREFIX' directives may re-map the same prefix label.
In Turtle, fresh RDF blank nodes are also allocated when matching the production blankNodePropertyList. Both of these may appear in the subject or object position of a triple. That subject or object is a fresh RDF blank node. This blank node also serves as the subject of the triples produced by matching the predicateObjectList production embedded in a blankNodePropertyList.