@prefix and the `a` shortcut

Make IRIs short; make `rdf:type` shorter.

0/3 done

Theory

@prefix lets you alias a long IRI:

@prefix : <http://academy.org/ninja/> .

Now :Donatello expands to <http://academy.org/ninja/Donatello>.

The keyword a is shorthand for rdf:type:

:Donatello a :Turtle .

A quick cheat sheet of the Turtle keywords you'll see in every file:

You writeTurtle expands it to
@prefix : <...> .A namespace alias for the rest of the document
:Foo<http://academy.org/ninja/Foo> (full IRI)
ardf:type — i.e. <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
"text"An xsd:string literal (default datatype)

Theory

Going deeper — why it works, where it bites

Why it works. Turtle is a serialization, not the data. The parser expands every prefix and shortcut into full-IRI triples before anything downstream sees them, so :Donatello a :Turtle and the fully-spelled <http://academy.org/ninja/Donatello> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://academy.org/ninja/Turtle> . are byte-for-byte the same graph. Prefixes exist purely for humans; the machine only ever stores absolute IRIs.

Where it bites.

  • A prefix is lexical, not semantic. Renaming : in the header silently rewrites every term in the file. Two files that both use the empty prefix : for different base IRIs do not clash when merged — but a human skimming them will be fooled. Trust the absolute IRI.
  • a is exactly rdf:type and nothing softer. It asserts membership as a fact the reasoner can build on, not a hint. Mistyping the class IRI doesn't error — it cheerfully creates a brand-new, empty class.
  • The trailing . is mandatory. Turtle's one truly common beginner error is a missing final period; the parser then swallows the next statement into the previous one and reports a confusing column number.

Reading in progress · 0 of 3 activities done