When learning RDF (Resource Description Framework), one of the first concepts to understand is the different types of nodes that can appear in an RDF graph.
Every RDF graph is built from triples (Subject → Predicate → Object), but the nodes that participate in those triples can be of different kinds.
Using characters from the Marvel Avengers universe makes it easier to visualize how RDF models real-world information.
In RDF, there are three types of nodes:
· IRIs (Internationalized Resource Identifiers)
· Literals
· Blank Nodes
Let's explore each of them using Avengers examples.
1. IRIs: Identifying Real Things
One of the most important concepts in RDF is the IRI (Internationalized Resource Identifier).
An IRI is a globally unique identifier used to represent a real-world entity, concept, place, person, organization, movie, or anything else that exists in your domain.
Think of an IRI as the RDF equivalent of a primary key that works across the entire internet.
1.1 Why Do We Need IRIs?
Imagine we store information about Tony Stark. If we simply write "Tony Stark":
we immediately encounter a problem.
· Is this the Marvel character?
· Is it a comic-book version?
· Is it the Marvel Cinematic Universe (MCU) version?
· Is it a fan-created character?
The name alone is ambiguous. Instead, RDF uses a unique IRI. For example, Wikipedia identifies the MCU version of Tony Stark using a dedicated page: https://en.wikipedia.org/wiki/Tony_Stark_(Marvel_Cinematic_Universe). The URL itself can serve as a globally unique identifier.
Now there is no ambiguity. Anyone using this IRI knows exactly which Tony Stark we are talking about.
RDF Triples Using IRIs
@prefix ex: <http://example.org/marvel/> . ex:TonyStark ex:alias ex:IronMan . ex:SteveRogers ex:alias ex:CaptainAmerica . ex:BruceBanner ex:alias ex:Hulk . ex:NatashaRomanoff ex:alias ex:BlackWidow .
The RDF parser expands the triples to:
<http://example.org/marvel/TonyStark> <http://example.org/marvel/alias> <http://example.org/marvel/IronMan> . <http://example.org/marvel/SteveRogers> <http://example.org/marvel/alias> <http://example.org/marvel/CaptainAmerica> . <http://example.org/marvel/BruceBanner> <http://example.org/marvel/alias> <http://example.org/marvel/Hulk> . <http://example.org/marvel/NatashaRomanoff> <http://example.org/marvel/alias> <http://example.org/marvel/BlackWidow> .
2. Literals: Storing Actual Values
In the previous section, we learned that IRIs identify things.
For example:
· Tony Stark
· Iron Man
· Avengers
· Thanos
These are all entities in our graph. But entities alone are not enough. We also need to store information about those entities:
· What is Tony Stark's name?
· What is his age?
· When was he born?
· What is his net worth?
· Is he an Avenger?
This is where literals come in.
2.1 What Is a Literal?
A literal is a concrete data value stored in an RDF graph.
Examples include:
· Text
· Numbers
· Dates
· Times
· Boolean values
· Decimal values
Unlike IRIs, literals are not entities. They are simply values.
For example:
@prefix ex: <http://example.org/marvel/> . ex:TonyStark ex:name "Tony Stark" .
Notice something important, the left side identifies a character, and the right side is merely a text value.
2.2 IRIs vs Literals
Consider these two triples:
Triple 1
@prefix ex: <http://example.org/marvel/> . ex:TonyStark ex:alias ex:IronMan .
Everything here is an IRI.
Triple 2
@prefix ex: <http://example.org/marvel/> . ex:TonyStark ex:name "Tony Stark" .
Here:
|
Component |
Type |
|
ex:TonyStark |
IRI |
|
ex:name |
IRI |
|
"Tony Stark" |
Literal |
If it is something you might want to connect to other things later, use an IRI. If it is simply a value, use a literal.
Example
@prefix ex: <http://example.org/marvel/> . ex:TonyStark ex:name "Tony Stark" . ex:TonyStark ex:occupation "Inventor" . ex:TonyStark ex:status "Alive" .
2.3 Numeric Literals
RDF can store numbers.
Example:
@prefix ex: <http://example.org/marvel/> . ex:TonyStark ex:armorCount 85 . ex:TonyStark ex:netWorth 100000000000 .
2.4 Date Literals
Dates are extremely common in RDF.
Example
@prefix ex: <http://example.org/marvel/> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . ex:TonyStark ex:birthDate "1970-05-29"^^xsd:date .
Following table summarizes the common data types.
|
Datatype |
Example |
|
xsd:string |
"Tony Stark" |
|
xsd:integer |
"85"^^xsd:integer |
|
xsd:decimal |
"123.45"^^xsd:decimal |
|
xsd:boolean |
"true"^^xsd:boolean |
|
xsd:date |
"1970-05-29"^^xsd:date |
Complete Avenger Example.
@prefix ex: <http://example.org/marvel/> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> . ex:TonyStark ex:name "Tony Stark" . ex:TonyStark ex:age "48"^^xsd:integer . ex:TonyStark ex:isAvenger "true"^^xsd:boolean . ex:TonyStark ex:birthDate "1970-05-29"^^xsd:date .
In summary, IRIs identify things, whereas literals are data values.
3. Blank Nodes: Anonymous Resources
So far, we've seen two types of RDF nodes:
IRIs: identify entities
Literals: store values
There is a third type of node called a Blank Node. A blank node represents a resource that exists in the graph but does not have its own IRI.
Think of it as an anonymous object.
3.1 Why Do Blank Nodes Exist?
Sometimes we need to describe something that:
· Has multiple properties
· Is not important enough to identify globally
· Will not be referenced elsewhere
For example, suppose we want to model Tony Stark's address. An address is not a simple literal because it contains multiple fields:
· Street
· City
· State
· Country
A literal cannot have properties attached to it.
In Turtle, a blank node label is written using _:
Example
_:address1
blankNode.turtle
@prefix ex: <http://example.org/marvel/> . ex:TonyStark ex:address _:address1 . _:address1 ex:street "10880 Malibu Point" . _:address1 ex:city "Malibu" . _:address1 ex:state "California" .
In summary, RDF graphs are built using three types of nodes: IRIs, Literals, and Blank Nodes. IRIs uniquely identify entities such as Tony Stark, Iron Man, or the Avengers, enabling them to be connected across a graph. Literals represent actual data values like names, numbers, dates, and boolean values, for example "Tony Stark" or "1970-05-29"^^xsd:date. Blank Nodes are anonymous resources used when a resource needs structure but does not require a permanent identifier, such as an address or contact information. As a general rule, use an IRI when something needs an identity, a Literal when storing a value, and a Blank Node only for anonymous structures that are unlikely to be referenced elsewhere.
Previous Next Home









No comments:
Post a Comment