Triples

The atomic unit of data in RDF.

Everything in RDF is a triple. A triple states one fact about something:

subject    predicate    object

The subject is the thing you're talking about. The predicate is the property or relationship. The object is the value.

Examples

"Alice's email is alice@example.com":

<https://example.org/people/alice> <https://example.org/vocab/email> "alice@example.com" .

"Alice works in the Engineering department":

<https://example.org/people/alice> <https://example.org/vocab/department> <https://example.org/departments/engineering> .

The first triple has a string value as the object. The second has another resource (the Engineering department). Both are valid triples.

With prefixes, these become readable. Prefixes map a short label to a namespace, so you don't have to write the full URI every time:

@prefix people:      <https://example.org/people/> .
@prefix vocab:       <https://example.org/vocab/> .
@prefix departments: <https://example.org/departments/> .

Now the same triples look like this:

people:alice vocab:email "alice@example.com" .
people:alice vocab:department departments:engineering .

people:alice expands to <https://example.org/people/alice>. The prefix replaces the namespace.

Multiple Facts

Describe something with as many triples as you need. When multiple triples share the same subject, use semicolons to avoid repeating it:

people:alice
    vocab:name "Alice Chen" ;
    vocab:email "alice@example.com" ;
    vocab:department departments:engineering ;
    vocab:role "senior engineer" .

Four triples, four facts, all about the same person. The semicolons mean "same subject, next predicate." The period ends the block. See Turtle Syntax for more on this shorthand.

Types

A special predicate, rdf:type, says what kind of thing something is. It requires the rdf: prefix:

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
people:alice        rdf:type vocab:Person .
departments:engineering rdf:type vocab:Department .

Turtle has a shorthand for rdf:type: the keyword a:

people:alice        a vocab:Person .
departments:engineering a vocab:Department .

Both forms mean exactly the same thing. The a shorthand doesn't need a prefix declaration.

The Graph

A collection of triples forms a graph. Resources connect to other resources through predicates, creating a web of facts:

@prefix people:   <https://example.org/people/> .
@prefix projects: <https://example.org/projects/> .
@prefix vocab:    <https://example.org/vocab/> .

people:alice a vocab:Person ;
    vocab:name "Alice Chen" ;
    vocab:manages projects:q3 .

projects:q3 a vocab:Project ;
    vocab:title "Q3 Planning" ;
    vocab:status "active" .

Alice is connected to the Q3 project through vocab:manages. The project has its own facts. Follow any connection and you reach more facts. That's the graph.

See Also

On this page