RDF (Resource Description Framework)
A W3C standard for representing information as subject-predicate-object triples, enabling machine-readable data exchange and semantic web applications.
RDF (Resource Description Framework) is a W3C standard for representing information as triples—statements consisting of subject, predicate, and object. RDF provides a foundation for the Semantic Web by enabling machines to understand and exchange structured data using URIs, literals, and standardized vocabularies.
Core Concepts
Triple Structure
Every piece of information in RDF is expressed as a triple:
Subject Predicate Object
┌─────┐ ┌────────┐ ┌────────┐
│Alice│ ─→ │worksAt │─→ │TechCorp│
└─────┘ └────────┘ └────────┘
Components:
- Subject: The resource being described (URI or blank node)
- Predicate: The property or relationship (URI)
- Object: The value (URI, blank node, or literal)
URIs as Identifiers
RDF uses URIs to uniquely identify resources globally:
<http://example.org/people/alice>
<http://xmlns.com/foaf/0.1/name>
"Alice Johnson" .
RDF Serialization Formats
1. Turtle (Terse RDF Triple Language)
Human-readable syntax with prefixes:
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix ex: <http://example.org/> .
ex:alice a foaf:Person ;
foaf:name "Alice Johnson" ;
foaf:mbox <mailto:alice@example.com> ;
foaf:knows ex:bob .
ex:bob a foaf:Person ;
foaf:name "Bob Smith" .
Features:
- Prefix declarations (
@prefix) - Type shorthand (
a=rdf:type) - Multiple predicates with
; - Multiple objects with
,
2. RDF/XML
XML-based serialization:
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<foaf:Person rdf:about="http://example.org/alice">
<foaf:name>Alice Johnson</foaf:name>
<foaf:mbox rdf:resource="mailto:alice@example.com"/>
<foaf:knows rdf:resource="http://example.org/bob"/>
</foaf:Person>
</rdf:RDF>
3. N-Triples
Line-by-line triple format (machine-friendly):
<http://example.org/alice> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> .
<http://example.org/alice> <http://xmlns.com/foaf/0.1/name> "Alice Johnson" .
<http://example.org/alice> <http://xmlns.com/foaf/0.1/knows> <http://example.org/bob> .
4. JSON-LD
JSON-based linked data:
{
"@context": "http://xmlns.com/foaf/0.1/",
"@id": "http://example.org/alice",
"@type": "Person",
"name": "Alice Johnson",
"mbox": "mailto:alice@example.com",
"knows": {
"@id": "http://example.org/bob"
}
}
RDF in TrustGraph
TrustGraph uses RDF triples internally with a JSON representation:
// RDF triple in TrustGraph format
{
s: {
v: "http://example.org/alice", // Subject URI
e: true // Entity flag
},
p: {
v: "http://xmlns.com/foaf/0.1/knows", // Predicate URI
e: true
},
o: {
v: "http://example.org/bob", // Object URI
e: true
}
}
// Literal object
{
s: { v: "http://example.org/alice", e: true },
p: { v: "http://xmlns.com/foaf/0.1/name", e: true },
o: { v: "Alice Johnson", e: false } // Literal value
}
Field Explanation:
s: Subjectp: Predicateo: Objectv: Value (URI or literal)e: Entity flag (true= URI,false= literal)
RDF Vocabularies
Standard vocabularies provide shared terms:
FOAF (Friend of a Friend)
Social network vocabulary:
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
ex:alice foaf:name "Alice" ;
foaf:knows ex:bob ;
foaf:mbox <mailto:alice@example.com> ;
foaf:homepage <http://alice.example.org> .
Dublin Core
Metadata vocabulary:
@prefix dc: <http://purl.org/dc/elements/1.1/> .
ex:document dc:title "RDF Guide" ;
dc:creator "TrustGraph Team" ;
dc:date "2025-12-24" ;
dc:subject "Semantic Web" .
Schema.org
Web content markup:
@prefix schema: <https://schema.org/> .
ex:article a schema:Article ;
schema:headline "Understanding RDF" ;
schema:author ex:alice ;
schema:datePublished "2025-12-24" .
Benefits of RDF
- Global Identifiers: URIs enable worldwide data linking
- Standardized: W3C standard with wide tool support
- Flexible: Schema-free, extensible data model
- Interoperable: Multiple serialization formats
- Reasoning-Ready: Formal semantics enable inference
- Linked Data: Connect data across organizations
RDF vs Property Graphs
| Aspect | RDF | Property Graphs |
|---|---|---|
| Data Model | Triples only | Nodes + edges with properties |
| Edge Properties | Requires reification | Native support |
| Standards | W3C standards (RDF, OWL, SPARQL) | Vendor-specific (Cypher, Gremlin) |
| Query Language | SPARQL | Cypher, Gremlin, GraphQL |
| Reasoning | Built-in (RDFS, OWL) | Limited/custom |
| Serialization | Turtle, RDF/XML, JSON-LD | Custom JSON formats |
Common Use Cases
- Linked Open Data: Publishing government, research, cultural data
- Knowledge Graphs: Enterprise knowledge management
- Semantic Search: Understanding query meaning
- Data Integration: Merging data from multiple sources
- AI/ML: Structured knowledge for reasoning
- Scientific Data: Biology, chemistry, astronomy datasets
Working with RDF
Querying with SPARQL
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?person ?name
WHERE {
?person a foaf:Person ;
foaf:name ?name ;
foaf:knows <http://example.org/alice> .
}
Importing RDF in TrustGraph
# Import Turtle file
tg-load-text --text "$(cat data.ttl)" --title "RDF Data"
# Query RDF data
tg-invoke-graph-rag -q "Find all people who know Alice"
Best Practices
- Use Standard Vocabularies: Prefer FOAF, Schema.org, Dublin Core over custom terms
- Provide Context: Use
@prefixdeclarations for readability - URI Design: Use dereferenceable HTTP URIs
- Avoid Blank Nodes: Use URIs for important resources
- Document Vocabularies: Clear definitions for custom predicates
- Version Control: Track RDF schema changes
- Validate Data: Check for syntax and semantic errors
Limitations
- No Native Edge Properties: Requires reification workaround
- Verbosity: More verbose than property graph formats
- Learning Curve: URI/prefix syntax can be complex
- Query Complexity: SPARQL can be harder than Cypher for simple traversals
- Performance: Large-scale RDF stores may be slower than specialized graph databases
See Also
Examples
- •Turtle format: <http://example.org/alice> foaf:knows <http://example.org/bob> .
- •JSON-LD: {"@id": "alice", "knows": {"@id": "bob"}}
- •Triple: (Alice, worksAt, TechCorp)