Ontologies and the semantic web
Clear, exam-focused notes on ontologies and the Semantic Web: definitions (RDF, RDFS, OWL, triples, graphs, SPARQL), formal entailment rules, common inferences, worked examples, and exam guidance.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Ontologies and the Semantic Web give machines a standard way to describe the meaning of data so software can combine, search and reason over data from many sources. Engineers use ontologies when designing knowledge graphs, linked data, semantic search, or when integrating heterogeneous datasets (for example, in web search, recommender systems or biomedical data integration).
Key ideas
Start with simple terms and build up.
Ontology: a formal, explicit specification of a shared conceptualisation. "Formal" means machine-readable (e.g. OWL), "explicit" means all concepts and relations are stated, "shared" means used by a community, and "conceptualisation" means a model of entities and relations in a domain. (Definition appears as a standard in knowledge representation literature.)
Taxonomy: a hierarchical classification (often a tree or DAG) of concepts. A taxonomy is a simple form of ontology; richer ontologies may also include other relations, constraints or axioms.
URI/IRI: a Uniform Resource Identifier (or, in RDF 1.1, an Internationalized Resource Identifier), a string used to name resources (classes, properties, individuals). RDF/OWL use IRIs; "URI" appears historically.
RDF (Resource Description Framework): a standard model for data as triples. A triple is an ordered triple (subject, predicate, object) where subject is a resource (IRI) or blank node, predicate is an IRI (property), and object is a resource (IRI), blank node or literal. RDF data is a directed labeled graph. Literals may be typed (e.g., "42"^^xsd:int) or language-tagged strings (e.g., "color"@en).
Exact statement (university style): An RDF triple t is an element of (U ∪ B) × U × (U ∪ B ∪ L), where U = set of IRIs (historically called URIs), B = set of blank nodes, L = set of literals. An RDF graph G is a finite set of triples. Assumption: blank nodes are existential variables.
RDF graph drawing: draw each IRI or blank node as a circle or rectangle labeled with its local name; draw directed edges labeled with properties (predicates); draw literal objects as rectangles with quotes. Example: (ex:Alice, ex:knows, ex:Bob) is a node ex:Alice with an arrow labeled ex:knows to node ex:Bob.
RDFS (RDF Schema): a lightweight vocabulary for classes and properties. Important terms defined: rdfs:Class, rdfs:subClassOf, rdfs:subPropertyOf, rdfs:domain, rdfs:range.
Key RDFS entailment rules (exact form, used in exams):
- If (C rdfs:subClassOf D) and (x rdf:type C) then (x rdf:type D). (Subclass inheritance)
- If (p rdfs:subPropertyOf q) and (s p o) then (s q o). (Subproperty inheritance)
- If (p rdfs:domain C) and (s p o) then (s rdf:type C). (Domain entails subject type)
- If (p rdfs:range C) and (s p o) then (o rdf:type C). (Range entails object type)
Assumptions: these rules follow RDFS entailment semantics; triples can be instantiated multiple times; blank nodes are existential — they do not denote the same resource unless linked.
OWL (Web Ontology Language): a richer ontology language based on Description Logics (DL) that allows class constructors (union, intersection, complement), restrictions (existential ∃, universal ∀), property characteristics (functional, inverse, transitive, symmetric), equality (owl:sameAs) and disjointness (owl:disjointWith). OWL 2 defines profiles (OWL 2 EL, OWL 2 QL, OWL 2 RL) for tractable reasoning; OWL 2 DL corresponds closely to decidable Description Logics and is commonly taught; OWL Full is undecidable; OWL Lite (from OWL 1) is deprecated.
Formal DL notation (common in university answers):
- Subsumption:
C ⊑ Dmeans every instance of class C is also an instance of class D. - Equivalence:
C ≡ Dmeans classes have identical instances. - Existential restriction:
∃R.Cmeans those individuals that have at least one R-successor in class C. - Universal restriction:
∀R.Cmeans those individuals all of whose R-successors are in C. - Cardinality restrictions:
≤ n R.C,≥ n R.C, and= n R.Cconstrain the number of R-successors in class C (exactly n is often written= n R.C).
Important property axioms (declare as exact statements):
TransitiveProperty(R)means if (x R y) and (y R z) then (x R z) is entailed.SymmetricProperty(R)means if (x R y) then (y R x).FunctionalProperty(R)means for a given subject x, there is at most one object y such that (x R y).InverseOf(R,S)means (x R y) iff (y S x).InverseFunctionalProperty(R)means if (x R y) and (z R y) then x = z.
- Subsumption:
Open World Assumption (OWA): the truth of a statement is not assumed false just because it is not known. Formally: absence of a triple does not entail its negation. This contrasts with the Closed World Assumption (CWA) used in databases. OWL does not adopt the Unique Name Assumption (UNA): different IRIs may denote the same individual unless asserted different (e.g., with owl:differentFrom or owl:AllDifferent).
Reasoner / Inference: a software that computes entailments from an ontology (RDFS or OWL). Key reasoning tasks: classification (compute subclass hierarchy), consistency/satisfiability checking (is any class declared unsatisfiable or any ontology inconsistent?), realization (determine most specific classes for an individual).
SPARQL: a query language for RDF. SPARQL queries match graph patterns against an RDF graph and return variable bindings. Result sets are multisets; use SELECT DISTINCT to eliminate duplicates.
Formulas
(Here we list syntax to remember for RDF/RDFS/OWL/SPARQL and a few DL notations.)
<subject> <predicate> <object> . — RDF triple in N-Triples/Turtle; subject is an IRI or blank node, predicate is an IRI, object is an IRI, blank node, or literal.
@prefix ex: <http://example.org/> . — Turtle prefix declaration.
ex:Alice ex:knows ex:Bob . — example triple in Turtle.
?s ?p ?o — basic triple pattern in SPARQL; ? marks variables.
SELECT ?s WHERE { ?s a ex:Student . ?s ex:memberOf ex:CSDept . } — SPARQL SELECT skeleton.
C ⊑ D — class subsumption in Description Logic: every instance of C is an instance of D.
C ≡ D — class equivalence.
∃R.C — existential restriction: has an R-successor in class C.
∀R.C — universal restriction: all R-successors are in C.
TransitiveProperty(R), SymmetricProperty(R), FunctionalProperty(R) — property characteristics.
Note: there are no SI units; these are syntactic forms to memorise.
Worked examples
Example 1 — Represent simple facts as RDF and draw the graph.
Problem: "Alice is a Student, Alice is memberOf CSDept, CSDept partOf UniX". Give RDF triples and describe the graph.
Solution (model answer):
- Declare URIs:
ex:Alice,ex:Student,ex:CSDept,ex:partOf,ex:memberOf,ex:UniX. - Triples (Turtle):
ex:Alice a ex:Student .ex:Alice ex:memberOf ex:CSDept .ex:CSDept ex:partOf ex:UniX .
- Graph to draw: draw node labeled ex:Alice; arrow labeled "a (rdf:type)" pointing to node ex:Student; arrow from ex:Alice labeled ex:memberOf to node ex:CSDept; arrow from ex:CSDept labeled ex:partOf to ex:UniX. Literal values (none here) would be drawn as rectangles with quotes.
Final check: graph shows directed labeled edges representing the three triples. This is sufficient RDF.
Example 2 — SPARQL query on the above graph.
Problem: List names (URIs) of students who are members of ex:CSDept.
Model answer with exact query and expected result:
SPARQL query:
SELECT ?s WHERE { ?s a ex:Student . ?s ex:memberOf ex:CSDept . }
Given the triples in Example 1, results (one row) are:
?s = ex:Alice
State the binding exactly: the query returns one solution with ?s bound to http://example.org/Alice (or ex:Alice if prefix used).
Example 3 — OWL reasoning and inconsistency detection (description-logic style).
Problem: Given axioms: Professor ⊑ Person, Student ⊑ Person, Professor owl:disjointWith Student, and individuals: ex:Bob rdf:type Professor and ex:Bob rdf:type Student. Is the ontology consistent? Show reasoning.
Model answer (step-by-step):
- From
ex:Bob rdf:type ProfessorandProfessor ⊑ Personwe can entailex:Bob rdf:type Person(by subsumption rule). - From
ex:Bob rdf:type StudentandStudent ⊑ Personwe can entailex:Bob rdf:type Person(again). That duplicates the Person type but is not a problem. Professor owl:disjointWith StudentmeansProfessor ⊓ Student ⊑ ⊥(the intersection of Professor and Student is unsatisfiable; no individual can be both).- Because ex:Bob is asserted to be both Professor and Student, ex:Bob is an instance of
Professor ⊓ Student. - From step 3 this implies ex:Bob is an instance of ⊥ (the empty class), which is impossible in OWL DL; thus the ontology is inconsistent.
Conclusion: The ontology is inconsistent; a reasoner will report inconsistency. This is the expected model answer.
Common mistakes
- Thinking rdfs:subClassOf is symmetric; it is not (students often invert it but inheritance is one-way).
- Using
owl:sameAscarelessly:owl:sameAsasserts identity; it is stronger than "equivalent" in loose sense. Mistaken use can merge data incorrectly. - Expecting OWL to do arithmetic or complex numeric inference; OWL handles class/property reasoning, not general computation.
- Not distinguishing classes vs individuals vs properties: e.g., confusing an instance URI with a class URI.
- Forgetting that domain/range in RDFS are entailments that add rdf:type triples — they do not constrain all uses the way database schemas do.
For your exam
Question types you will see:
- Definitions: define RDF triple, ontology, OWA, RDFS, OWL, subclass, entailment. Full marks require the formal statement (e.g., triple ∈ (U ∪ B) × U × (U ∪ B ∪ L)).
- Short notes: compare RDF vs relational DB, OWA vs CWA, RDFS inference rules. Full marks include examples and consequences.
- Derivations / proofs: apply RDFS or DL entailment rules to derive new triples or show inconsistency. Full marks require step-by-step rule applications and mention of assumptions (blank nodes existential, OWA).
- Numericals: usually not numeric, but small graph reasoning problems — give all derived triples.
- Programs: write a SPARQL query and give expected bindings.
- Diagrams: draw an RDF graph for given triples; label nodes and edges precisely.
What a full-marks answer includes: precise definitions (bold the term), formal notation where appropriate, stepwise application of entailment rules, a small example showing the idea, and concluding sentence stating the result (e.g., ontology consistent / inconsistent). When asked to draw, label subjects, predicates, objects and mark literals.
Quick check
- What is a triple in RDF? 2. State the RDFS rule for rdfs:domain. 3. What does
owl:disjointWithimply about a pair of classes?
Answers: A triple is (subject, predicate, object) ∈ (U ∪ B) × U × (U ∪ B ∪ L); rdfs:domain rule: if (p rdfs:domain C) and (s p o) then (s rdf:type C); owl:disjointWith implies the intersection of the two classes is unsatisfiable (no individual can be instance of both).
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?