What Is an Ontology?
An ontology is a formal specification of a domain's vocabulary — the classes (types of things), properties (relationships), and the rules governing them. If the knowledge graph is the data, the ontology is the schema that gives that data meaning.
Think of an ontology as a shared dictionary for your domain. Without it, "Person" in one dataset might mean something different from "Person" in another. With a shared ontology, machines can understand and interoperate across datasets.
The Two Levels of a Knowledge Graph
| Layer | Name | Content |
|---|---|---|
| T-Box | Terminological Box | Classes, properties, axioms (the schema) |
| A-Box | Assertional Box | Individual instances and their relationships (the data) |
The T-Box defines what kinds of things exist. The A-Box says what things actually exist.
Nodes
- owl:Thingclass
The root class — every individual is a Thing
- foaf:Agentclass
An agent (person or organization)
- foaf:Personclass
A human person
- ex:Employeeclass
A person employed by an organization
- org:Organizationclass
An organization or company
- aliceinstance
Instance of foaf:Person and ex:Employee
- Acme Corpinstance
Instance of org:Organization
Edges
- Agentrdfs:subClassOfThing
- Personrdfs:subClassOfAgent
- Employeerdfs:subClassOfPerson
- Organizationrdfs:subClassOfThing
- alice_instrdf:typeEmployee
- acme_instrdf:typeOrganization
- alice_instworksForacme_inst
RDFS: RDF Schema
RDFS (RDF Schema) is the simplest ontology language. It provides:
rdfs:Class— declares a classrdfs:subClassOf— declares class inheritancerdf:Property— declares a propertyrdfs:domain— specifies which class a property applies tordfs:range— specifies which class/datatype a property's values must berdfs:label/rdfs:comment— human-readable names and descriptions
RDFS is intentionally simple. For more expressive power, you need OWL.
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix ex: <http://example.org/schema/> .
# Class definitions
ex:Agent a rdfs:Class ;
rdfs:label "Agent" .
ex:Person a rdfs:Class ;
rdfs:subClassOf ex:Agent ;
rdfs:label "Person" ;
rdfs:comment "A human individual." .
ex:Employee a rdfs:Class ;
rdfs:subClassOf ex:Person ;
rdfs:label "Employee" .
ex:Organization a rdfs:Class ;
rdfs:subClassOf ex:Agent ;
rdfs:label "Organization" .
# Property definitions
ex:name a rdf:Property ;
rdfs:domain ex:Agent ;
rdfs:range xsd:string ;
rdfs:label "name" .
ex:age a rdf:Property ;
rdfs:domain ex:Person ;
rdfs:range xsd:integer ;
rdfs:label "age" .
ex:worksFor a rdf:Property ;
rdfs:domain ex:Employee ;
rdfs:range ex:Organization ;
rdfs:label "works for" .OWL: Web Ontology Language
OWL (Web Ontology Language) adds much richer expressiveness on top of RDFS:
| OWL Construct | Meaning |
|---|---|
owl:equivalentClass | Two classes have the same members |
owl:disjointWith | No instance can be in both classes |
owl:inverseOf | A property is the inverse of another |
owl:TransitiveProperty | If A→B→C then A→C |
owl:FunctionalProperty | Each subject has at most one value |
owl:cardinality | Exact number of values required |
OWL is the basis for reasoning — an OWL reasoner can automatically infer new facts from existing ones (covered in Chapter 7).
Well-Known Ontologies
You don't have to write ontologies from scratch. Many reusable vocabularies exist:
- FOAF (Friend of a Friend) — for people and social networks
- Schema.org — Google's vocabulary for web content; covers products, events, reviews, etc.
- Dublin Core — for metadata like title, creator, date
- PROV-O — for provenance and data lineage
- Gene Ontology — for biological processes, functions, and components
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ex: <http://example.org/schema/> .
# Inverse properties
ex:worksFor owl:inverseOf ex:employs .
# Transitive property
ex:locatedIn a owl:TransitiveProperty .
# → if London locatedIn England, England locatedIn UK
# then London locatedIn UK (inferred)
# Functional property — a person has exactly one birth date
ex:birthDate a owl:FunctionalProperty .
# Disjoint classes — nothing can be both a Person and an Organization
ex:Person owl:disjointWith ex:Organization .
# Equivalent classes — ex:Employee ≡ schema:Employee
ex:Employee owl:equivalentClass <https://schema.org/Employee> .
# Cardinality restriction — a Company must have at least 1 employee
ex:Company rdfs:subClassOf [
a owl:Restriction ;
owl:onProperty ex:employs ;
owl:minCardinality 1
] .Knowledge check
Which RDFS construct is used to declare that one class is a specialization of another (inheritance)?
Summary
In this chapter you learned:
- An ontology defines the T-Box (schema) for your knowledge graph — classes, properties, and axioms
- RDFS provides simple class hierarchies and property constraints
- OWL adds richer semantics: inverse properties, transitivity, cardinality, disjoint classes
- The Open World Assumption means missing facts are unknown, not false
Next, we'll learn how to query a knowledge graph using SPARQL.