XML RDF
Resource Description Framework for semantic web data
πΈοΈ What is RDF?
RDF (Resource Description Framework) is a standard for describing web resources using XML. It represents information as subject-predicate-object triples, enabling machines to understand relationships between data on the web.
<!-- Simple RDF Triple -->
<rdf:Description rdf:about="John">
<knows>Jane</knows>
</rdf:Description>
RDF Core Concepts
Subject
The resource being described
<rdf:Description
rdf:about="http://example.com/john">
Predicate
The property or relationship
<foaf:name>John Doe</foaf:name>
Object
The value or related resource
<foaf:age>30</foaf:age>
Namespaces
Define vocabularies and schemas
xmlns:foaf=
"http://xmlns.com/foaf/0.1/"
πΉ Basic RDF Example
A simple RDF document describing a person with basic properties. RDF uses triples to express facts: subject (person), predicate (property), and object (value).
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<rdf:Description rdf:about="http://example.com/john">
<foaf:name>John Doe</foaf:name>
<foaf:age>30</foaf:age>
<foaf:email>[email protected]</foaf:email>
</rdf:Description>
</rdf:RDF>
RDF Triples:
πΉ RDF with Relationships
RDF excels at describing relationships between resources. This example shows how people know each other using resource references instead of literal values.
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<!-- Person 1 -->
<rdf:Description rdf:about="http://example.com/john">
<foaf:name>John Doe</foaf:name>
<foaf:knows rdf:resource="http://example.com/jane"/>
<foaf:knows rdf:resource="http://example.com/bob"/>
</rdf:Description>
<!-- Person 2 -->
<rdf:Description rdf:about="http://example.com/jane">
<foaf:name>Jane Smith</foaf:name>
<foaf:knows rdf:resource="http://example.com/john"/>
</rdf:Description>
<!-- Person 3 -->
<rdf:Description rdf:about="http://example.com/bob">
<foaf:name>Bob Johnson</foaf:name>
</rdf:Description>
</rdf:RDF>
Relationship Graph:
- John knows Jane and Bob
- Jane knows John
- Bob is known by John
πΉ RDF with Typed Resources
Use rdf:type to classify resources into categories. This helps organize data and enables semantic queries based on resource types.
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:ex="http://example.com/vocab#">
<rdf:Description rdf:about="http://example.com/book1">
<rdf:type rdf:resource="http://example.com/vocab#Book"/>
<ex:title>Learning XML</ex:title>
<ex:author>John Doe</ex:author>
<ex:isbn>978-0-123456-78-9</ex:isbn>
<ex:publishedYear>2024</ex:publishedYear>
</rdf:Description>
<rdf:Description rdf:about="http://example.com/book2">
<rdf:type rdf:resource="http://example.com/vocab#Book"/>
<ex:title>RDF Guide</ex:title>
<ex:author>Jane Smith</ex:author>
<ex:isbn>978-0-987654-32-1</ex:isbn>
<ex:publishedYear>2024</ex:publishedYear>
</rdf:Description>
</rdf:RDF>
Resource Types:
π book1 is a Book
π book2 is a Book
β Both share common Book properties
πΉ RDF Abbreviated Syntax
RDF/XML supports abbreviated syntax for cleaner, more readable documents. Use rdf:type shorthand and nested descriptions:
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/">
<!-- Using foaf:Person instead of rdf:type -->
<foaf:Person rdf:about="http://example.com/john">
<foaf:name>John Doe</foaf:name>
<foaf:age>30</foaf:age>
<!-- Nested resource -->
<foaf:knows>
<foaf:Person rdf:about="http://example.com/jane">
<foaf:name>Jane Smith</foaf:name>
<foaf:age>28</foaf:age>
</foaf:Person>
</foaf:knows>
</foaf:Person>
</rdf:RDF>
Abbreviation Benefits:
- Shorter: Less verbose than full syntax
- Readable: Easier to understand structure
- Nested: Related resources grouped together
πΉ RDF Collections and Containers
RDF provides structures for grouping multiple resources together using bags, sequences, and alternatives:
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:ex="http://example.com/vocab#">
<rdf:Description rdf:about="http://example.com/course">
<ex:title>Web Development</ex:title>
<!-- Bag: Unordered collection -->
<ex:students>
<rdf:Bag>
<rdf:li rdf:resource="http://example.com/student1"/>
<rdf:li rdf:resource="http://example.com/student2"/>
<rdf:li rdf:resource="http://example.com/student3"/>
</rdf:Bag>
</ex:students>
<!-- Sequence: Ordered collection -->
<ex:lessons>
<rdf:Seq>
<rdf:li>HTML Basics</rdf:li>
<rdf:li>CSS Styling</rdf:li>
<rdf:li>JavaScript</rdf:li>
</rdf:Seq>
</ex:lessons>
<!-- Alternative: Choose one -->
<ex:instructor>
<rdf:Alt>
<rdf:li>John Doe</rdf:li>
<rdf:li>Jane Smith</rdf:li>
</rdf:Alt>
</ex:instructor>
</rdf:Description>
</rdf:RDF>
Container Types:
- rdf:Bag: Unordered collection (students)
- rdf:Seq: Ordered sequence (lessons)
- rdf:Alt: Alternatives (choose one instructor)
πΉ Complete RDF Example: Product Catalog
A comprehensive RDF document describing products with categories, prices, and relationships:
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:prod="http://example.com/products#">
<!-- Product 1 -->
<prod:Product rdf:about="http://example.com/products/laptop">
<prod:name>Professional Laptop</prod:name>
<prod:price>899.99</prod:price>
<prod:currency>USD</prod:currency>
<prod:inStock>true</prod:inStock>
<prod:category rdf:resource="http://example.com/categories/electronics"/>
<prod:manufacturer>TechCorp</prod:manufacturer>
<rdfs:comment>High-performance laptop for professionals</rdfs:comment>
</prod:Product>
<!-- Product 2 -->
<prod:Product rdf:about="http://example.com/products/mouse">
<prod:name>Wireless Mouse</prod:name>
<prod:price>29.99</prod:price>
<prod:currency>USD</prod:currency>
<prod:inStock>true</prod:inStock>
<prod:category rdf:resource="http://example.com/categories/accessories"/>
<prod:compatibleWith rdf:resource="http://example.com/products/laptop"/>
<rdfs:comment>Ergonomic wireless mouse</rdfs:comment>
</prod:Product>
<!-- Category -->
<prod:Category rdf:about="http://example.com/categories/electronics">
<prod:name>Electronics</prod:name>
<rdfs:comment>Electronic devices and gadgets</rdfs:comment>
</prod:Category>
</rdf:RDF>
πΉ Common RDF Vocabularies
Popular RDF vocabularies for different domains:
Standard Vocabularies:
- FOAF: Friend of a Friend - People and relationships
- Dublin Core: Metadata for documents and resources
- SKOS: Simple Knowledge Organization System
- Schema.org: Structured data for web pages
- OWL: Web Ontology Language for complex relationships
<!-- Using multiple vocabularies -->
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<rdf:Description rdf:about="http://example.com/article">
<dc:title>Introduction to RDF</dc:title>
<dc:creator>John Doe</dc:creator>
<dc:date>2024-10-16</dc:date>
<dc:subject>Semantic Web</dc:subject>
</rdf:Description>
</rdf:RDF>