Semantic Web
A vision of the Web where data is machine-readable and interlinked through standardized formats, enabling automated reasoning and knowledge sharing across systems.
The Semantic Web is an extension of the World Wide Web that enables machines to understand and process web content through standardized, structured data formats and shared vocabularies.
Core Vision
Tim Berners-Lee's vision: Transform the web from a "web of documents" to a "web of data" where:
- Machines can understand the meaning of information, not just display it
- Data is interlinked across different sources and systems
- Automated reasoning can derive new knowledge from existing data
- Intelligent agents can perform complex tasks on behalf of users
Key Technologies
1. RDF (Resource Description Framework)
The foundation of the Semantic Web - a way to represent data as triples:
# RDF Triple format: Subject - Predicate - Object
@prefix ex: <http://example.com/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
ex:John foaf:name "John Smith" .
ex:John foaf:mbox <mailto:john@example.com> .
ex:John ex:worksAt ex:TechCorp .
ex:TechCorp ex:industry "Technology" .
ex:TechCorp ex:founded "2010"^^xsd:date .
Benefits:
- Universal data model
- Easy to merge data from multiple sources
- Machine-processable
- Supports inference
2. RDF Schema (RDFS)
Provides vocabulary for describing classes and properties:
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex: <http://example.com/> .
# Define classes
ex:Person a rdfs:Class .
ex:Company a rdfs:Class .
# Define properties
ex:worksAt a rdf:Property ;
rdfs:domain ex:Person ;
rdfs:range ex:Company ;
rdfs:label "works at" .
# Establish hierarchy
ex:Employee rdfs:subClassOf ex:Person .
ex:Manager rdfs:subClassOf ex:Employee .
3. OWL (Web Ontology Language)
More expressive language for defining complex ontologies:
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix ex: <http://example.com/> .
# Define an ontology
ex:CompanyOntology a owl:Ontology .
# Classes
ex:Person a owl:Class .
ex:Company a owl:Class .
# Properties with constraints
ex:founded a owl:DatatypeProperty ;
rdfs:domain ex:Company ;
rdfs:range xsd:date .
ex:employs a owl:ObjectProperty ;
rdfs:domain ex:Company ;
rdfs:range ex:Person ;
owl:inverseOf ex:worksAt .
# Inference rules
ex:CEO rdfs:subClassOf ex:Person .
ex:CEO rdfs:subClassOf [
a owl:Restriction ;
owl:onProperty ex:leadsCompany ;
owl:someValuesFrom ex:Company
] .
4. SPARQL Query Language
SQL for the Semantic Web:
# Query RDF data
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX ex: <http://example.com/>
SELECT ?person ?company ?role
WHERE {
?person foaf:name ?name .
?person ex:worksAt ?company .
?person ex:hasRole ?role .
?company ex:industry "Technology" .
FILTER(?role = "CEO" || ?role = "CTO")
}
ORDER BY ?company
Semantic Web Stack
Layer 7: Trust, Proof, Cryptography
Layer 6: Unifying Logic
Layer 5: Ontology (OWL)
Layer 4: Rules (RIF, SWRL)
Layer 3: Query (SPARQL)
Layer 2: Schema (RDFS)
Layer 1: Data (RDF, XML, JSON-LD)
Layer 0: URIs, Unicode, XML
Linked Data Principles
Tim Berners-Lee's four rules for Linked Data:
- Use URIs to name things
- Use HTTP URIs so people can look up those names
- Provide useful information using standards (RDF, SPARQL)
- Include links to other URIs to discover more things
Example Implementation
# Using HTTP URIs
<http://example.com/people/john> a foaf:Person ;
foaf:name "John Smith" ;
foaf:knows <http://example.com/people/jane> ;
foaf:knows <http://other-org.com/employees/bob> ; # Link to external data
owl:sameAs <http://dbpedia.org/resource/John_Smith> . # Link to DBpedia
Practical Applications
1. Knowledge Graphs
# Google Knowledge Graph style
@prefix schema: <http://schema.org/> .
<http://kg.google.com/entity/apple> a schema:Organization ;
schema:name "Apple Inc." ;
schema:founder <http://kg.google.com/entity/steve-jobs> ;
schema:product <http://kg.google.com/entity/iphone> ;
schema:industry "Technology" .
<http://kg.google.com/entity/steve-jobs> a schema:Person ;
schema:birthDate "1955-02-24" ;
schema:deathDate "2011-10-05" ;
schema:founded <http://kg.google.com/entity/apple> .
2. Schema.org Markup
<!-- Semantic annotations for search engines -->
<div itemscope itemtype="http://schema.org/Person">
<h1 itemprop="name">John Smith</h1>
<p>Email: <span itemprop="email">john@example.com</span></p>
<p>Works at:
<span itemprop="worksFor" itemscope itemtype="http://schema.org/Organization">
<span itemprop="name">TechCorp</span>
</span>
</p>
</div>
Or in JSON-LD format:
{
"@context": "http://schema.org",
"@type": "Person",
"name": "John Smith",
"email": "john@example.com",
"worksFor": {
"@type": "Organization",
"name": "TechCorp",
"industry": "Technology"
}
}
3. Linked Open Data (LOD)
# Linking to authoritative sources
@prefix dbr: <http://dbpedia.org/resource/> .
@prefix dbo: <http://dbpedia.org/ontology/> .
ex:Article123 a schema:Article ;
schema:about dbr:Artificial_Intelligence ; # Link to DBpedia
schema:mentions dbr:Machine_Learning ;
schema:mentions dbr:Deep_Learning .
# DBpedia provides rich information
dbr:Artificial_Intelligence
dbo:abstract "AI is..." ;
dbo:field dbr:Computer_Science ;
owl:sameAs <http://www.wikidata.org/entity/Q11660> . # Link to Wikidata
Semantic Web in TrustGraph
TrustGraph leverages Semantic Web technologies:
// Import RDF/OWL ontology
await trustgraph.schema.import({
format: "turtle",
ontology: `
@prefix ex: <http://example.com/ontology#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
ex:Person a owl:Class .
ex:Company a owl:Class .
ex:worksAt a owl:ObjectProperty ;
rdfs:domain ex:Person ;
rdfs:range ex:Company .
`
});
// Query using SPARQL-like syntax
const results = await trustgraph.query({
sparql: `
SELECT ?person ?company
WHERE {
?person rdf:type ex:Person .
?person ex:worksAt ?company .
?company ex:industry "Technology" .
}
`
});
// Export as Linked Data
const linkedData = await trustgraph.export({
format: "json-ld",
context: "http://schema.org"
});
Benefits
1. Data Integration
# Merge data from different sources seamlessly
# Source A
ex:John foaf:name "John Smith" .
ex:John ex:age 30 .
# Source B
ex:John ex:worksAt ex:TechCorp .
ex:John foaf:mbox <mailto:john@example.com> .
# Automatically merged
ex:John foaf:name "John Smith" ;
ex:age 30 ;
ex:worksAt ex:TechCorp ;
foaf:mbox <mailto:john@example.com> .
2. Automated Reasoning
# Define rules
ex:Manager rdfs:subClassOf ex:Employee .
ex:Employee rdfs:subClassOf ex:Person .
# Data
ex:John a ex:Manager .
# Inferred automatically
ex:John a ex:Employee . # Because Manager is subclass of Employee
ex:John a ex:Person . # Because Employee is subclass of Person
3. Interoperability
# Use standard vocabularies
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix schema: <http://schema.org/> .
@prefix dbr: <http://dbpedia.org/resource/> .
ex:John foaf:name "John Smith" ;
schema:worksFor ex:TechCorp ;
foaf:knows dbr:Tim_Berners-Lee .
# Any system understanding these vocabularies can process this data
Challenges
1. Complexity
Semantic Web technologies have a learning curve:
# OWL can get complex
ex:Parent a owl:Class ;
owl:equivalentClass [
a owl:Restriction ;
owl:onProperty ex:hasChild ;
owl:someValuesFrom ex:Person
] .
2. Performance
RDF triple stores can be slower than specialized databases for certain queries.
3. Adoption
Despite standards, adoption has been slower than initially hoped.
Modern Evolution
JSON-LD: Making Semantic Web Accessible
{
"@context": {
"name": "http://schema.org/name",
"worksAt": {
"@id": "http://schema.org/worksFor",
"@type": "@id"
}
},
"@id": "http://example.com/people/john",
"@type": "Person",
"name": "John Smith",
"worksAt": "http://example.com/companies/techcorp"
}
More developer-friendly while maintaining RDF semantics.
Property Graphs
Modern Knowledge Graphs often use property graph models (Neo4j, etc.) which are simpler but less standardized:
// Property graph (Cypher)
CREATE (john:Person {name: "John Smith", age: 30})
CREATE (techcorp:Company {name: "TechCorp"})
CREATE (john)-[:WORKS_AT {since: 2020}]->(techcorp)
TrustGraph bridges both worlds:
- Uses property graphs for performance
- Can import/export RDF/OWL for interoperability
Best Practices
1. Reuse Standard Vocabularies
# Good: Use standard vocabularies
@prefix schema: <http://schema.org/> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
ex:John a schema:Person ;
foaf:name "John Smith" .
# Avoid: Creating custom vocabulary for common concepts
ex:John a ex:HumanBeing ;
ex:fullName "John Smith" .
2. Use HTTP URIs
# Good: Resolvable URIs
<http://example.com/people/john> a foaf:Person .
# Avoid: Non-HTTP URIs
<urn:uuid:123-456> a foaf:Person .
3. Provide Multiple Serializations
# Offer data in multiple formats
@app.route('/people/john')
def get_person():
if request.headers['Accept'] == 'text/turtle':
return render_turtle(person)
elif request.headers['Accept'] == 'application/ld+json':
return render_json_ld(person)
else:
return render_html(person)
Future Vision
The Semantic Web continues to evolve:
- Decentralized Web: Solid project for personal data pods
- AI Integration: LLMs understanding semantic data
- IoT: Semantic descriptions of devices and sensors
- Enterprise Knowledge: Corporate knowledge graphs
- Scientific Data: Linked research data
See Also
Examples
- •Using RDF triples to represent that 'John works_at TechCorp' in a machine-readable format
- •Publishing linked open data that other systems can automatically discover and use
- •Semantic annotations that help search engines understand page content