What Is RDF? A Data Model Built on Triples

architecture10 min한국어

#rdf#semantic-web#ontology#knowledge-graph#data-model

A security device records one detection. Stored in a table, it looks like this.

idtypesource IPscore
42ransomware192.0.2.100.92

Expressed in RDF (Resource Description Framework), that one row becomes three lines.
Below is the result in N-Triples, one of the RDF file formats (# lines are explanatory comments).

# Detection 42 is a ransomware detection
<http://example.org/detection/42> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/RansomwareDetection> .
# The source IP of detection 42 is 192.0.2.10
<http://example.org/detection/42> <http://example.org/sourceIp> <http://example.org/ip/192.0.2.10> .
# The score of detection 42 is 0.92
<http://example.org/detection/42> <http://example.org/score> "0.92"^^<http://www.w3.org/2001/XMLSchema#decimal> .

The id became the first element of every line, and each remaining column became a line of its own.
Each line states what, through which property, connects to what, in that order.

1. What RDF Stands For

RDF is short for Resource Description Framework.

1.1 Resource

Not only things that exist, such as detection 42, an IP address or a host, but also a concept like “ransomware detection” is a resource.

1.2 Description

A property such as “the score is 0.92” and a relation such as “the source IP is 192.0.2.10” are described in RDF with sentences of the same shape; RDF does not treat them differently.

detection/42 detection 42 "0.92" value (literal) ip/192.0.2.10 another resource (IRI) score sourceIp property relation subject predicate object
A property (arrow to a value) and a relation (arrow to another resource) are both triples of the same shape: subject, predicate, object.

1.3 Framework

RDF is a framework that standardizes both the graph structure that holds data and the file formats for storing it (serialization formats).

WordMeaningIn RDF
Resourcea thinganything that can be given a name
Descriptiondescribingproperties of resources and relations between them
Frameworkstructurea graph with directed, named edges, plus its file formats

2. The RDF Data Model: Triples

RDF expresses data with three elements: subject, predicate and object.
A line made of these three elements is called a triple.

SubjectPredicateObject
detection 42has typeransomware detection
detection 42has source IP192.0.2.10
detection 42has score0.92
192.0.2.10belongs to hostweb-01

To link an owner to a detection in a relational database, you first change the schema by adding a column or a table.
In RDF, you add one triple with an owner predicate.

Drawn as a picture, the subject and object of a triple are nodes and the predicate is the arrow between them.
Arrows connect at nodes that appear in several triples, such as detection 42, and together they form a graph.

detection/42 detection 42 RansomwareDetection ransomware detection ip/192.0.2.10 IP host/web-01 host rdf:type sourceIp host
One triple is one arrow from the subject to the object. Arrows that share nodes form a graph.

An RDF graph is a set of triples.
Adding the same triple twice still leaves one triple in the graph.

3. IRIs: Why Names Look Like URLs

Resources are named with IRIs (Internationalized Resource Identifiers).
An IRI is a global identifier that looks like http://example.org/detection/42, and it identifies one thing uniquely.

  • Names do not collide. Even if companies A and B both define Host, their IRIs differ.
  • The same IRI is one node. When data from different sources is merged, identical IRIs become one node.

An IRI is only an identifier; it does not have to be an address you can open.

Same name, different IRI: different things http://a.example/Host Company A's Host http://b.example/Host Company B's Host ≠ Same IRI: same thing detection system asset inventory ip/192.0.2.10 one node
The domain at the front of an IRI keeps names from colliding, and the same IRI means the same thing even across sources.

4. What Goes into a Triple

The RDF 1.1 specification defines three kinds of values in a triple: IRIs, literals and blank nodes.

KindAllowed positionExample
IRIsubject, predicate, object<http://example.org/ip/192.0.2.10>
Literal (value)object"0.92"^^xsd:decimal, "ransomware"@en
Blank node (unnamed node)subject, object_:b0

A literal is a lexical form plus a datatype IRI.
"0.92"^^xsd:decimal is the decimal 0.92, while a plain quoted "0.92" is a string (xsd:string).
A language tag gives names per language, as in "랜섬웨어"@ko and "ransomware"@en.

A blank node is an intermediate node that needs no name of its own.
It groups several values together, as in “address = [city Seoul, postal code 04524]”.
A label such as _:b0 is local to one file, so _:b0 in another document is a different node.

5. Shortening IRIs with Prefixes

Formats such as Turtle shorten the common beginning of IRIs with a short prefix.

@prefix ex:  <http://example.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

After these declarations, ex:sourceIp means <http://example.org/sourceIp> and xsd:decimal means <http://www.w3.org/2001/XMLSchema#decimal>.
A prefix only shortens the notation; the stored IRI is the same.
The common rdf:type can be written as just a in Turtle.

6. Serialization Formats: Turtle, N-Triples and Others

RDF is a data model, and there are several formats for storing it in a file (serialization formats).
The detection record from the introduction looks like this in Turtle and in N-Triples.

# Turtle: prefixes and ; avoid repeating the subject, so it is easy to read and write
@prefix ex:  <http://example.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://example.org/detection/42> a ex:RansomwareDetection ;
    ex:sourceIp <http://example.org/ip/192.0.2.10> ;
    ex:score "0.92"^^xsd:decimal .
# N-Triples: one triple per line, nothing abbreviated, easy to process line by line
<http://example.org/detection/42> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/RansomwareDetection> .
<http://example.org/detection/42> <http://example.org/sourceIp> <http://example.org/ip/192.0.2.10> .
<http://example.org/detection/42> <http://example.org/score> "0.92"^^<http://www.w3.org/2001/XMLSchema#decimal> .
FormatCharacteristicsTypical use
Turtleprefixes and abbreviations, easy to readwriting ontologies and mappings
N-Triplesone triple per line, no abbreviationlarge outputs, streaming, line-by-line comparison
N-QuadsN-Triples plus a fourth element (graph name)output with named graphs
TriGTurtle plus graph blockswriting named graphs by hand
JSON-LDRDF in JSON formstructured data in web pages, API responses
RDF/XMLthe oldest, XML-based formatexchange with older tools

Changing the format does not change the graph.

7. Merging Graphs from Different Sources

If different systems name the same thing with the same IRI, their graphs can be merged as they are.
When both the detection system and the asset inventory use ex:ip/192.0.2.10, the merged graph connects detection 42 all the way to host web-01.
If one side stored the IP as a string literal or used a different IRI, the identifiers have to be aligned first.

detection system asset inventory detection/42 ip/192.0.2.10 host/web-01 sourceIp host Same IRI, so merging alone connects them detection/42 → ip/192.0.2.10 → host/web-01
Putting two graphs from different sources together is enough: they connect at the shared IRI.

8. Named Graphs and Datasets

To separate triples by source or by collection batch, use named graphs.
A graph name is added to each triple to show which graph it belongs to.
A default graph plus any number of named graphs is called a dataset.

<http://example.org/detection/42> <http://example.org/sourceIp> <http://example.org/ip/192.0.2.10> <http://example.org/graph/edr> .
<http://example.org/ip/192.0.2.10> <http://example.org/host>    <http://example.org/host/web-01>  <http://example.org/graph/cmdb> .
dataset graph/edr graph/cmdb detection/42 sourceIp ip/192.0.2.10 ip/192.0.2.10 host host/web-01
A named graph gives triples a graph name. A dataset is a default graph plus named graphs.

In N-Quads, the last element is the graph name.
Separating EDR data and asset inventory data by graph lets you query only one graph or reload one collection batch.

Named graphsFormats
SupportedN-Quads, TriG, JSON-LD
Not supportedN-Triples, Turtle, RDF/XML

9. Adding Properties and Relations to a Triple

Suppose there is a triple “the source of detection 42 is 192.0.2.10”.
Trying to add “engine v3 made this decision, with confidence 0.8” to it runs into a problem.
The engine and the confidence belong to the triple itself, not to detection 42 or the IP, yet the subject of a triple can only be an IRI or a blank node.

One triple detection42 ip/192.0.2.10 sourceIp source of detection 42 is 192.0.2.10 Properties and relations on a triple the whole triple detection42 sourceIp ip/192.0.2.10 engine-v3 deciding engine "0.8" confidence assertedBy confidence
Left, one triple; right, properties and relations attached to that triple. The engine and confidence belong to the triple, not to detection 42 or the IP.

RDF 1.1 offers two ways to add properties and relations to a triple.

  • Reification: create a description node (rdf:Statement) that points back to the original triple through rdf:subject, rdf:predicate and rdf:object. Describing one triple takes four more triples, and the description is not automatically linked to the original triple.
  • Separate node: turn the relation itself into a node (a source observation, obs42) and attach the IP, the engine and the confidence to it. The structure is simple, but the direct relation detection42 sourceIp ip/192.0.2.10 disappears and queries change shape.
① Reification (rdf:Statement) _:st1 rdf:Statement detection42 rdf:subject ex:sourceIp rdf:predicate ip/192.0.2.10 rdf:object engine-v3 assertedBy "0.8" confidence ② Separate node (relation as a node) obs42 source observation detection42 sourceObservation ip/192.0.2.10 ip engine-v3 assertedBy "0.8" confidence
① Reification restates the triple as three triples (subject, predicate, object) and attaches properties and relations. ② A separate node turns the relation itself into a node and attaches them there.

10. Schemas Are Defined in RDF Too

RDF itself does not say that RansomwareDetection is a kind of MalwareDetection, or that the value of sourceIp is an IP.
Classes and properties are defined with schema languages such as RDFS and OWL, and the definitions are themselves RDF triples.

@prefix ex:   <http://example.org/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

ex:RansomwareDetection rdfs:subClassOf ex:MalwareDetection .
ex:sourceIp rdfs:domain ex:Detection ; rdfs:range ex:IPAddress .
StandardWhat it defines
RDFSclasses, subclasses, and the classes a property connects
OWLclasses and properties defined with logical conditions; a reasoner infers new facts from them
SKOSterm systems: broader and narrower terms, synonyms, mappings to other systems
SHACLthe shape data must have, e.g. “a detection must have exactly one score”

RDF is a data model, and an ontology is a model that defines the meaning of concepts and relations.
RDFS and OWL ontologies are expressed in RDF as well.
SHACL is for validating data, a different job from OWL reasoning.

schema (RDFS) RansomwareDetection MalwareDetection subClassOf data detection42 rdf:type inferred: rdf:type MalwareDetection
A schema is triples too. Read with the data, it yields facts the data never stated (dashed).

11. How RDF Differs from Property Graphs (Neo4j)

The model Neo4j uses is the property graph (labeled property graph).
In 2024, GQL, a query language for property graphs, became an ISO standard.

RDFProperty graph
Namesresources identified by IRIsmostly internal IDs; external IDs can be stored as properties
Values on edgesturn the relation into a separate node, or use reificationproperties directly on the edge
SchemaRDFS and OWL schemas, SHACL validation rulesproduct-specific schema and constraint features
Query languageSPARQLCypher, GQL
Strengthsintegrating data from different sources, reusing standard schemas, reasoningexploring relations within one application, intuitive modeling

Property graphs are convenient for quickly modeling relations inside one service and working with edge properties.
RDF fits better when systems need to share identifiers and schemas.

Property graph Alice Acme WORKS_AT { since: 2024 } RDF ex:alice ex:job1 employment ex:acme "2024" ex:job ex:org ex:since
Values on edges work differently. A property graph puts properties on the edge; RDF turns the relation into a separate node and attaches values to it.

12. Ways to Create RDF Data

MethodDescriptionExample
Writing it directlywrite triples in a format such as Turtleontologies, small reference data
Converting existing dataconvert databases, JSON or CSV with mapping rulesR2RML for relational databases, RML for JSON, CSV and XML as well
Embedding in web pagesembed JSON-LD in HTMLstructured data for search engines (schema.org)

Whichever method you use, check three things.

  • A graph is a set. Generating the same triple several times leaves one triple in the graph. Whether duplicate lines actually disappear from an output file depends on the tool.
  • Formats hold different information. To keep named graphs, store data as N-Quads or TriG.
  • A literal is a lexical form plus a datatype. When converting database values to literals, keep datatypes and lexical forms consistent so other systems can compare them. The same number written differently can become a different literal.

Common Misconceptions

  • ❌ RDF is XML.
    ✅ RDF/XML is one serialization format. Turtle, N-Triples and JSON-LD exist too.
  • ❌ RDF is an ontology.
    ✅ RDF is a data model; an ontology is a conceptual model defined with RDFS or OWL.
  • ❌ An IRI must be a web address you can open.
    ✅ An IRI is an identifier. Making it return a description when opened (a dereferenceable IRI) is a Linked Data principle, not a requirement of the RDF standard.
  • ❌ The same triple twice means two facts.
    ✅ A graph is a set, so it is one.
  • ❌ A triple store and a graph database are the same thing.
    ✅ They name things differently and attach values to edges differently.

Summary

  • RDF expresses relations as triples of subject, predicate and object, and adds new relations by adding triples.
  • Data from different systems connects into one graph just by merging, as long as it uses the same IRIs.
  • A graph is a set of triples. Named graphs separate triples by graph, and properties and relations on a triple are expressed with reification or a separate node.
  • Serialization formats hold different information. Use N-Quads or TriG when you need named graphs.
  • Schemas and ontologies are defined with RDFS, OWL and SKOS, and data shapes are validated with SHACL.

References