IRIs vs Literals

When to identify and when to just carry data.

0/4 done

Theory

RDF objects come in two flavours:

  • IRIs — globally unique identifiers for things you might want to say more about later (:Alice, :Tokyo, :Book123).
  • Literals — raw data values you'll never need to identify on their own ("Alice", 42, "2024-01-01"^^xsd:date).

Rule of thumb: if you might attach more triples to it later, make it an IRI.

Quick decision table:

Use an IRI when…Use a literal when…
The thing has its own identityIt's just a value carried along
You'll add more facts about it laterIt's terminal data — nothing more
Two graphs might want to refer to itOnly this triple needs it
It's a person, place, document, event…It's a name, number, date, flag…

Analogy

A person's name is a literal — a string. But the person themself is an IRI: you can hire them, follow them, send them a postcard. You can't hire a string.

Same trick in software: "alice@example.com" is a literal (a delivery slot), whereas <https://alice.example/#me> is an IRI for the person who happens to use that mailbox. Confuse the two and your graph silently loses the ability to merge facts about Alice from a second source.

Worked example you can copy

Worked example — the exact pattern you'll write below.

We want to say two facts about Alice in one compact statement:

  1. Her name is the literal string "Alice Smith".
  2. Her birth date is the literal date 1990-04-12.

Pulling on the vocabularies you met in Level 0:

  • For the name of a person we reach for foaf:name.
  • For the birth date we'll use our own predicate :birthDate (no need to borrow one — it's our model).
  • The string is a plain literal — just wrap it in double quotes.
  • The date needs the ^^xsd:date tag so the parser understands it as a calendar date rather than a string.
  • The ; lets us avoid retyping :Alice twice.
:Alice  foaf:name   "Alice Smith" ;
        :birthDate  "1990-04-12"^^xsd:date .

Read it line-by-line:

TokenWhy it's there
:Alicethe subject — our own IRI
foaf:namethe predicate — borrowed FOAF vocabulary for a person's name
"Alice Smith"a literal string (default datatype xsd:string)
;same subject, new predicate
:birthDateour own predicate in the : namespace
"1990-04-12"^^xsd:datea typed literal — the ^^ operator tags it as a date
.end of the whole statement

That's everything the playground asks you to write.

Reading in progress · 0 of 4 activities done