How Triples Are Written

Prefixes, local names, and the period that ends a fact.

0/4 done

Theory

Before Level 1 asks you to write triples, let's read them.

Every Turtle file starts with a tiny header of prefixes. A prefix is just an abbreviation for a long URL so you don't have to type the whole thing every time:

@prefix : <http://academy.org/ninja/> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:  <http://www.w3.org/2002/07/owl#> .
@prefix xsd:  <http://www.w3.org/2001/XMLSchema#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .

Now :Alice is shorthand for <http://academy.org/ninja/Alice> — a full IRI but written in one breath. The empty prefix : is your own namespace; foaf:, xsd:, rdf: etc. are vocabularies you borrow from the Web (we'll explore them in the next lesson).

Then comes the fact itself — three slots, a period to end it:

:Alice  :knows  :Bob  .
# ^subject ^predicate ^object  ^end-of-statement

The four rules you need for Level 1:

  1. A Turtle file starts with @prefix lines (we provide them — you'll > rarely need to change them).
  2. Use :Local (with a leading colon) to name things in your own > namespace.
  3. Use prefix:Local (e.g. foaf:name) to use a borrowed vocabulary.
  4. Every fact ends with a single period . — forget it and the parser > will complain.

Analogy

Prefixes are like contact-list shortcuts on your phone. The real address of your friend is something long (a full URL); the prefix :Alice is the nickname you saved so you don't have to dial the whole number every time. The Web still uses the full URL underneath — the prefix is just for your eyes.

Concretely, here is what your three most-used prefixes expand to:

Prefix you typeFull IRI it stands for
:Alice<http://academy.org/ninja/Alice>
foaf:name<http://xmlns.com/foaf/0.1/name>
xsd:date<http://www.w3.org/2001/XMLSchema#date>

Visualization

Subject Object predicate

How one Turtle line becomes one edge in the graph: the period at the end is what tells the parser this fact is finished.

The period matters more than it looks: without it, the parser keeps reading the next tokens as more predicates and objects for the same subject (the ; / , shortcuts you'll meet next rely on exactly that). A missing period is the #1 cause of confusing Turtle errors.

Three more shortcuts: `a`, `;`, `,`

Two shortcuts you'll see everywhere (also in Level 1 validation queries):

  • ; keeps the subject and starts a new predicate.
  • , keeps the subject AND the predicate and adds another object.

These two forms are exactly equivalent:

# Long form — three separate triples.
:Alice  :age      30 .
:Alice  foaf:name "Alice Smith" .
:Alice  :knows    :Bob .
:Alice  :knows    :Carol .

# Same facts, compact form.
:Alice  :age      30 ;
        foaf:name "Alice Smith" ;
        :knows    :Bob , :Carol .

And one more shortcut you'll meet immediately: writing a instead of rdf:type (because typing every entity is so common it deserves a one-letter alias):

:Donatello  a  :Ninja .   # same as:  :Donatello rdf:type :Ninja .

Reading in progress · 0 of 4 activities done