TrustGraphGet Started

RDF (Resource Description Framework)

A W3C standard for representing information as subject-predicate-object triples, enabling machine-readable data exchange and semantic web applications.

Standards

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: Subject
  • p: Predicate
  • o: Object
  • v: 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

  1. Global Identifiers: URIs enable worldwide data linking
  2. Standardized: W3C standard with wide tool support
  3. Flexible: Schema-free, extensible data model
  4. Interoperable: Multiple serialization formats
  5. Reasoning-Ready: Formal semantics enable inference
  6. Linked Data: Connect data across organizations

RDF vs Property Graphs

AspectRDFProperty Graphs
Data ModelTriples onlyNodes + edges with properties
Edge PropertiesRequires reificationNative support
StandardsW3C standards (RDF, OWL, SPARQL)Vendor-specific (Cypher, Gremlin)
Query LanguageSPARQLCypher, Gremlin, GraphQL
ReasoningBuilt-in (RDFS, OWL)Limited/custom
SerializationTurtle, RDF/XML, JSON-LDCustom JSON formats

Common Use Cases

  1. Linked Open Data: Publishing government, research, cultural data
  2. Knowledge Graphs: Enterprise knowledge management
  3. Semantic Search: Understanding query meaning
  4. Data Integration: Merging data from multiple sources
  5. AI/ML: Structured knowledge for reasoning
  6. 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

  1. Use Standard Vocabularies: Prefer FOAF, Schema.org, Dublin Core over custom terms
  2. Provide Context: Use @prefix declarations for readability
  3. URI Design: Use dereferenceable HTTP URIs
  4. Avoid Blank Nodes: Use URIs for important resources
  5. Document Vocabularies: Clear definitions for custom predicates
  6. Version Control: Track RDF schema changes
  7. Validate Data: Check for syntax and semantic errors

Limitations

  1. No Native Edge Properties: Requires reification workaround
  2. Verbosity: More verbose than property graph formats
  3. Learning Curve: URI/prefix syntax can be complex
  4. Query Complexity: SPARQL can be harder than Cypher for simple traversals
  5. Performance: Large-scale RDF stores may be slower than specialized graph databases

See Also

  • Triples - Subject-Predicate-Object structure
  • SPARQL - RDF query language
  • Turtle - Human-readable RDF syntax
  • JSON-LD - JSON-based linked data
  • Semantic Web - Vision of machine-readable web
  • OWL - Web Ontology Language built on RDF

Examples

  • Turtle format: <http://example.org/alice> foaf:knows <http://example.org/bob> .
  • JSON-LD: {"@id": "alice", "knows": {"@id": "bob"}}
  • Triple: (Alice, worksAt, TechCorp)

Related Terms

Learn More