Ontologies, RDF/OWL and description logics

Intelligent Systems for Robotics · Week 4

Three questions the fetch task asks

  • Where is a drink?
  • Which drink may I bring this person?
  • What is this room?

No sensor answers any of them.

Where knowledge sits

Execution and monitoring Planning World model Skills Robot types, facts, and what follows from them weeks 2 and 3 weeks 6 to 8 weeks 4 and 5

A knowledge graph and a reasoner

  • A knowledge graph is a set of statements. Each links two things by a named relation.
  • An ontology is the vocabulary those statements use, with axioms that relate its terms.
  • A reasoner reads both and adds every statement that follows.

You write that a kitchen sink stands at the counter. The reasoner concludes that the room is a kitchen, and nobody wrote that.

Robots have been built this way

  • KnowRob gives robots the knowledge they need for everyday manipulation tasks, and represents it in OWL.
  • It computes much of that knowledge on demand, when a query asks for it. Its authors call these virtual knowledge bases.
  • This course builds a much smaller version, with one ontology file, one reasoner and queries you can read.

Tenorth & Beetz (2013), KnowRob, IJRR 32(5), 566–590.

RDF and Turtle

A triple


:sink  isfr:objectAt  :counter .
					
:sink :counter isfr:objectAt subject predicate object

A set of triples is a graph. Subjects and objects are its nodes, and each triple is a labelled edge.

IRIs and prefixes

An IRI is a global name. Two files that use the same IRI are talking about the same thing.


@prefix isfr: <https://isfr.tsiogkas.me/ontology/isfr#> .
@prefix :     <https://isfr.tsiogkas.me/ontology/studio#> .

isfr:Room   stands for   <https://isfr.tsiogkas.me/ontology/isfr#Room>
:counter    stands for   <https://isfr.tsiogkas.me/ontology/studio#counter>
					

A prefix abbreviates the start of an IRI. The empty prefix is the example's own namespace.

Literals

  • A literal is a value
  • A string, which may carry a language tag: "studio kitchen", "cuisine"@fr
  • A typed value: "0.8"^^xsd:decimal

:kitchen_corner  rdfs:label  "studio kitchen" .
					

Subjects are IRIs or blank nodes. Predicates are always IRIs. Only objects may be literals.

Blank nodes

  • A node with no global name
  • For something you need to describe and never refer to from outside
  • Written [ ... ] in Turtle

[ owl:intersectionOf ( isfr:Room  [ ... ] ) ]
    rdfs:subClassOf isfr:Kitchen .
					

The base ontology's kitchen axiom needs two of them.

Turtle


@prefix isfr: <https://isfr.tsiogkas.me/ontology/isfr#> .
@prefix :     <https://isfr.tsiogkas.me/ontology/studio#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

:kitchen_corner a isfr:Room ; rdfs:label "studio kitchen" .
:counter isfr:inRoom :kitchen_corner .

:sink a isfr:KitchenSink ; isfr:objectAt :counter .
:orange_1 a :Orange ; rdfs:label "an orange" ; isfr:objectAt :counter .
					
  • a abbreviates rdf:type, which puts a thing in a class
  • A semicolon repeats the subject
  • A comma repeats the subject and the predicate

The :sink line is two triples


<https://isfr.tsiogkas.me/ontology/studio#sink>
    <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>
    <https://isfr.tsiogkas.me/ontology/isfr#KitchenSink> .
<https://isfr.tsiogkas.me/ontology/studio#sink>
    <https://isfr.tsiogkas.me/ontology/isfr#objectAt>
    <https://isfr.tsiogkas.me/ontology/studio#counter> .
					

Prefixes, a and the semicolon are only abbreviations. This is what a parser reads.

The studio, drawn

isfr:Room :kitchen_corner "studio kitchen" :counter :sink :orange_1 isfr:KitchenSink :Orange "an orange" a rdfs:label isfr:inRoom isfr:objectAt isfr:objectAt a a rdfs:label

Ellipses are IRIs and boxes are literals. Eight triples, eight edges.

A graph is a set of triples

  • The set is unordered, and writing a triple twice adds nothing
  • RDF attaches no meaning to any name. A graph that says :sink a isfr:Room is equally valid.
  • Meaning comes from vocabularies built on RDF, starting with RDFS
  • The base ontology, data/ontology/isfr-base.ttl, is itself a set of triples

RDFS

rdfs:subClassOf


isfr:Fridge    rdfs:subClassOf isfr:Appliance .
isfr:Appliance rdfs:subClassOf isfr:PhysicalObject .
:fridge a isfr:Fridge .
					

A reasoner adds


:fridge a isfr:Appliance .
:fridge a isfr:PhysicalObject .
					

Every member of one class is a member of the other. The relation is transitive, so a chain of any length closes.

rdfs:domain and rdfs:range


isfr:objectAt rdfs:domain isfr:PhysicalObject ;
              rdfs:range  isfr:Place .
					
  • A domain types whatever appears as the subject of the property
  • A range types whatever appears as its object

From ?x isfr:objectAt ?y, a reasoner adds ?x a isfr:PhysicalObject and ?y a isfr:Place.

The fridge, typed by a domain

Add one triple to the studio, with no type for the fridge:


:fridge isfr:objectAt :counter .
					

After reasoning, :fridge is an isfr:PhysicalObject and :counter is an isfr:Place.

The reasoner does not conclude isfr:Fridge. The IRI's local name means nothing to it.

A range infers; it does not validate

Put a lamp at a room by mistake:


:lamp isfr:objectAt :kitchen_corner .
					
  • A database schema would reject this triple
  • RDFS reads the range as a premise and concludes :kitchen_corner a isfr:Place
  • On the studio, owlrl adds the type and reports no error

Read the inferred types of your individuals at least once.

Where RDFS stops

  • One more term, rdfs:subPropertyOf, says that every pair related by one property is related by the other
  • It cannot say that two classes are disjoint, or that a thing is not in a class
  • It cannot say that a room containing a kitchen sink is a kitchen. That needs a conjunction and an existential.

Description logics add both.

Description logics

Why a logic

  • A set semantics says exactly which conclusions follow from an ontology
  • More constructors than RDFS, for and, or, not, some and only
  • Built so that the standard questions about classes stay decidable

The basic logic is ALC. OWL 2 DL extends it.

Concepts, roles, individuals

NameDenotesStudio exampleOWL calls it
Concepta set of things\( \mathit{Room} \), \( \mathit{KitchenSink} \)class
Rolea binary relation\( \mathit{contains} \)property
Individuala single thing\( \mathit{sink} \)individual

Five constructors

ConceptNameIts membersExample
\( C \sqcap D \)intersectionin both\( \mathit{Room} \sqcap \mathit{Kitchen} \)
\( C \sqcup D \)unionin either\( \mathit{KitchenSink} \sqcup \mathit{BathroomSink} \)
\( \neg C \)complementnot in \( C \)\( \neg \mathit{Kitchen} \)
\( \exists r.C \)existentialrelated to at least one \( C \)\( \exists \mathit{contains}.\mathit{KitchenSink} \)
\( \forall r.C \)universalrelated only to members of \( C \)\( \forall \mathit{contains}.\mathit{Furniture} \)

From concept names \( A \) and roles \( r \). Add \( \top \) for everything and \( \bot \) for nothing.

An interpretation

\[ \mathcal{I} = (\Delta^\mathcal{I}, \cdot^\mathcal{I}) \]

  • \( \Delta^\mathcal{I} \) is a non-empty set of things
  • Each concept name \( A \) maps to a set \( A^\mathcal{I} \subseteq \Delta^\mathcal{I} \)
  • Each role \( r \) maps to a set of pairs \( r^\mathcal{I} \subseteq \Delta^\mathcal{I} \times \Delta^\mathcal{I} \)
  • Each individual \( a \) maps to one element \( a^\mathcal{I} \in \Delta^\mathcal{I} \)

Set semantics

\[ \begin{aligned} (C \sqcap D)^\mathcal{I} &= C^\mathcal{I} \cap D^\mathcal{I} \\ (C \sqcup D)^\mathcal{I} &= C^\mathcal{I} \cup D^\mathcal{I} \\ (\neg C)^\mathcal{I} &= \Delta^\mathcal{I} \setminus C^\mathcal{I} \\ (\exists r.C)^\mathcal{I} &= \{x \mid \exists y.\,(x,y) \in r^\mathcal{I} \wedge y \in C^\mathcal{I}\} \\ (\forall r.C)^\mathcal{I} &= \{x \mid \forall y.\,(x,y) \in r^\mathcal{I} \rightarrow y \in C^\mathcal{I}\} \end{aligned} \]

\( \forall r.C \) includes every thing related to nothing at all.

TBox and ABox, on the studio

TBox, axioms about concepts

  • \( \mathit{Room} \sqcap \exists \mathit{contains}.\mathit{KitchenSink} \sqsubseteq \mathit{Kitchen} \)
  • A domain is \( \exists r.\top \sqsubseteq C \). A range is \( \top \sqsubseteq \forall r.C \).

ABox, facts about individuals

  • \( \mathit{kitchen\_corner} : \mathit{Room} \) and \( \mathit{sink} : \mathit{KitchenSink} \)
  • \( \mathit{contains}(\mathit{kitchen\_corner}, \mathit{sink}) \)

\( C \sqsubseteq D \) holds when \( C^\mathcal{I} \subseteq D^\mathcal{I} \). A model satisfies every axiom. An axiom is entailed when it holds in every model.

An entailment, by hand

In every model of the studio:

  1. \( \mathit{contains}(\mathit{kitchen\_corner}, \mathit{sink}) \) and \( \mathit{sink} : \mathit{KitchenSink} \), so the corner is in \( \exists \mathit{contains}.\mathit{KitchenSink} \)
  2. It is also in \( \mathit{Room} \), so it is in the intersection
  3. The TBox puts the intersection inside \( \mathit{Kitchen} \)

The ontology entails \( \mathit{kitchen\_corner} : \mathit{Kitchen} \). Nobody asserted it.

Four tasks, one reasoner

For an ontology \( \mathcal{O} \) and a fresh individual \( b \):

TaskQuestionReduces to
ConsistencyDoes \( \mathcal{O} \) have any model?the base case
Instance checkingIs \( a : C \) entailed?\( \mathcal{O} \cup \{ a : \neg C \} \) is inconsistent
SubsumptionIs \( C \sqsubseteq D \) entailed?\( \mathcal{O} \cup \{ b : C \sqcap \neg D \} \) is inconsistent
Concept satisfiabilityDoes some model give \( C \) a member?\( \mathcal{O} \cup \{ b : C \} \) is consistent

A reasoner that decides consistency decides all four.

An open world

  • A model may contain anything the axioms do not rule out
  • Is the sleeping corner a kitchen? The studio does not entail it.
  • It does not entail the opposite either. Some models give the sleeping corner a kitchen sink nobody recorded.

The answer is unknown. The absence of a fact is not its negation.

The reasoner cannot answer no


ASK { :sleeping_corner a isfr:Kitchen }
					
  • On the closure, the answer is false. Here false means not entailed.
  • The reasoner cannot conclude that the sleeping corner is not a kitchen. Nothing in the studio entails it.
  • A SELECT reports an unknown as no row

No unique names

Two IRIs may denote one thing unless the ontology says otherwise. isfr:inRoom is functional, so a place is in at most one room.


:counter isfr:inRoom :kitchen_corner .
:counter isfr:inRoom :cooking_area .
					

The reasoner concludes :kitchen_corner owl:sameAs :cooking_area, and :cooking_area becomes a kitchen too.

owl:differentFrom between the two rooms is one way to make this a contradiction.

The tableau

  • Try to build a model, by breaking assertions into simpler ones
  • Branch at each union
  • A branch closes on a clash, such as \( x : A \) and \( x : \neg A \)
  • Every branch closed means the ontology is inconsistent

You will not run one by hand in this course.

Description logics, in one slide

  • Concepts, roles and individuals, with five constructors and a set semantics
  • The TBox holds axioms about concepts. The ABox holds facts about individuals.
  • Four reasoning tasks, all decided by a consistency check
  • An open world, and no unique names

OWL 2 and its profiles

OWL 2 DL, written in RDF

OWL 2 DL is a description logic, and its ontologies are usually written in RDF.

DLTurtle
\( C \sqcap D \)[ owl:intersectionOf ( C D ) ]
\( C \sqcup D \)[ owl:unionOf ( C D ) ]
\( \neg C \)[ owl:complementOf C ]
\( \exists r.C \)[ a owl:Restriction ; owl:onProperty r ; owl:someValuesFrom C ]
\( \forall r.C \)[ a owl:Restriction ; owl:onProperty r ; owl:allValuesFrom C ]
\( C \sqsubseteq D \)C rdfs:subClassOf D
\( x : C \):x rdf:type C
\( r(x, y) \):x r :y

The kitchen axiom, in the base ontology


[ owl:intersectionOf ( isfr:Room
                       [ a owl:Restriction ;
                         owl:onProperty isfr:contains ;
                         owl:someValuesFrom isfr:KitchenSink ] ) ]
    rdfs:subClassOf isfr:Kitchen .
					

\( \mathit{Room} \sqcap \exists \mathit{contains}.\mathit{KitchenSink} \sqsubseteq \mathit{Kitchen} \), with a blank node for each unnamed concept.

isfr:contains is a property chain, \( \mathit{inRoom}^- \circ \mathit{objectAt}^- \sqsubseteq \mathit{contains} \). A room contains whatever is at one of its places.

The price of OWL 2 DL as a whole

  • Consistency, class satisfiability, subsumption and instance checking are N2EXPTIME-complete
  • Decidable, with no useful bound on how long an answer takes

The profiles restrict the language until reasoning takes polynomial time.

OWL 2 Profiles (W3C, 2012), section 5.

Three profiles

ProfileBuilt for
OWL 2 ELOntologies with very large numbers of classes and properties
OWL 2 QLVery large volumes of instance data, with queries rewritten to run on a relational database
OWL 2 RLScalable reasoning that rule-based engines can implement. This course uses it.

In each, ontology consistency, and instance checking against a named class, take polynomial time.

RL is a set of rules


cax-sco:  T(?c1, rdfs:subClassOf, ?c2)  T(?x, rdf:type, ?c1)  =>  T(?x, rdf:type, ?c2)
					
  • Apply every rule, add what the rules conclude, repeat until a pass adds nothing
  • The result is the closure, the asserted triples with every triple that follows
  • The studio's kitchen takes five rules: prp-inv2, prp-spo2, cls-svf1, cls-int1, cax-sco

OWL 2 Profiles, section 4.3.

What RL gives up

An existential is allowed only on the subclass side of an axiom.

\[ \mathit{BeerBottle} \sqsubseteq \exists \mathit{holds}.\mathit{Beer} \]

In OWL 2 DL, every beer bottle holds some beer. That beer has no name.

RL is designed to avoid inferring the existence of individuals not explicitly present.

OWL 2 Profiles, sections 4.1 and 4.2.3.

What owlrl did with it

  • Given this axiom and one beer bottle, owlrl produced no holds triple at all
  • So the base ontology has no relation from a container to its content
  • A drink is one individual with two types, its container class and its content class

:beer1 a isfr:Bottle, :Beer .
					

owlrl reports an inconsistency as data

  • A Python implementation of the RL rules over an rdflib graph
  • An inconsistency becomes triples of type err:ErrorMessage in the closure

Add a disjointness to the studio with the lamp from slide 17:


isfr:Room owl:disjointWith isfr:Place .
					

"Disjoint classes …#Room and …#Place have a common individual …#kitchen_corner"

If your code does not look for those triples, an inconsistent graph looks like any other.

How long a closure takes

GraphSizeClosure time
A toy graph41 triples, closed to 21235 ms
The base ontology alone104 asserted, 355 inferredabout 0.05 s
The studio example131 asserted, 423 inferred0.087 s
The micro-project's reference apartment649 inferredabout 0.15 s

Measured 2026-10-04 on the instructor's laptop, Apple M4 Max, rdflib 7.6.0, owlrl 7.6.2.

When RL is enough for a robot

  • This week's ontology uses subclasses, domains and ranges, inverse properties, a property chain, a functional property and an existential on the subclass side. RL has all of them, and disjointness too, as slide 39 showed.
  • RL never invents an individual. A robot can only fetch a thing it can name.
  • A closure of about 0.15 s can be recomputed whenever the graph changes

SPARQL

A basic graph pattern


SELECT ?thing WHERE {
    ?room a isfr:Kitchen ; isfr:contains ?thing .
    ?thing a :Fruit .
}
					
  • A set of triple patterns. Any position may be a variable, written with a leading ?
  • A solution binds each variable so that every pattern becomes a triple in the graph
  • Turtle's semicolon works inside a pattern

Before and after reasoning


asserted: 131 triples
closure: 423 triples inferred in 0.087 s

Which rooms are kitchens?
  before reasoning: 0 rows; after: 1 rows
  + studio kitchen

Which things are fruit?
  before reasoning: 0 rows; after: 2 rows
  + an apple
  + an orange

Which fruit is in a kitchen?
  before reasoning: 0 rows; after: 1 rows
  + an orange
					

Query the closure for answers, and the asserted graph to see what was written.

FILTER

Which objects share a place?


SELECT ?a ?b WHERE {
    ?a isfr:objectAt ?place .
    ?b isfr:objectAt ?place .
    FILTER (?a != ?b)
}
					

FILTER keeps the solutions for which a condition holds.

The studio returns the orange with the sink and the apple with the bed, each pair once in each order.

OPTIONAL


SELECT ?thing ?label WHERE {
    ?thing isfr:objectAt ?place .
    OPTIONAL { ?thing rdfs:label ?label }
}
					

OPTIONAL keeps a solution when part of the pattern does not match, and leaves that part's variables unbound.

Every object at a place comes back. The orange and the apple have a label. The sink and the bed have none.

FILTER NOT EXISTS

Which room holds no citrus?


SELECT ?room WHERE {
    ?room a isfr:Room .
    FILTER NOT EXISTS { ?room isfr:contains ?fruit . ?fruit a :Citrus . }
}
					
  • On the closure, the sleeping corner
  • On the asserted graph, both rooms

Ask a negative question of the closure, never of the asserted graph.

Negation as failure

  • NOT EXISTS reads a fact nobody recorded as false
  • Its answer depends on what was written down
  • The reasoner works in the open world and concludes nothing from absence

SELECT ?room WHERE { ?room a isfr:Room . FILTER NOT EXISTS { ?room a isfr:Kitchen } }
					

On the closure, this returns the sleeping corner. The reasoner could not say that on slide 28.

Poole & Mackworth, section 15.9; SPARQL 1.1 Query, section 8.1.1.

Where it misleads

The studio's graph has one person, Sam. Kim and Lee join it. Lee is allergic to citrus, and nothing about allergies is recorded for Sam or Kim.


:sam a isfr:Person .
:kim a isfr:Person .
:lee a isfr:Person ; :allergicTo :Citrus .

SELECT ?person WHERE {
    ?person a isfr:Person .
    FILTER NOT EXISTS { ?person :allergicTo ?anything . }
}
					

This returns Sam and Kim. Perhaps Sam was asked and has no allergies. Nobody asked Kim.

The right question of the right graph

  • Ask every question of the closure
  • Use NOT EXISTS only where a fact nobody recorded can safely count as false
  • If not asked and asked with no answer differ, record the difference as a fact of its own, and query that

A person with no recorded preference raises the same question. Question 6 of the micro-project asks what it means for the robot.

Modelling the apartment

Competency questions

  • Write the questions first, in plain language. They are the specification.
  • Each names the terms the ontology needs and the conclusions it has to support
  • Once the ontology exists, each becomes a query, and the queries are its tests

The three questions on slide 2 are competency questions. The micro-project gives you six.

Grüninger & Fox (1995), IJCAI-95 Workshop on Basic Ontological Issues in Knowledge Sharing.

Class or individual?

  • A class is a kind that many things share, and that you will ask about as a kind, such as fridges, rooms or places
  • An individual is one particular thing. For this robot it is usually something it could drive to or pick up, such as this fridge or the orange on the counter.

When in doubt, ask whether the term could have two members. If it could, it is a class.

A class as a value

Sam prefers citrus, and does not prefer one particular orange.


:sam a isfr:Person ; rdfs:label "Sam" ; isfr:prefers :Citrus .
					
  • :Citrus is a class with :Orange beneath it, used here as an individual
  • OWL 2 admits this. The OWL 2 Primer, section 9, calls it punning.
  • The two uses are separate in the semantics. In the closure, Sam prefers :Citrus and nothing else.

Room types are inferred, never asserted

\[ \mathit{Room} \sqcap \exists \mathit{contains}.\mathit{KitchenSink} \sqsubseteq \mathit{Kitchen} \]

  • Assert every room as an isfr:Room and nothing more
  • An asserted isfr:Kitchen is a second record of the same fact. It can disagree with the room's contents, with nothing to flag it.
  • An inferred type always agrees with the contents, because the contents produce it

One COCO class, two kinds of sink

  • COCO has one class, sink, for every sink
  • The apartment has sinks in the bathroom and the WC as well as the kitchen. An axiom over isfr:Sink would make both of them kitchens.

isfr:Sink a owl:Class ; rdfs:subClassOf isfr:Furniture ; isfr:cocoClass "sink" .
isfr:KitchenSink a owl:Class ; rdfs:subClassOf isfr:Sink .
isfr:BathroomSink a owl:Class ; rdfs:subClassOf isfr:Sink .
					

The ontology now distinguishes what the detector cannot.

No world-frame poses

  • The graph records which place an object is at and which room a place is in, and no coordinates
  • The inventory's coordinates help you read the floor plan. They stay out of your graph.
  • Wheel odometry alone cannot tell the robot where it is, so a world-frame pose would be a number it cannot check

Week 5 gives every place an anchor the robot can perceive, and every edge between places a coarse relative hint.

The base ontology

GroupTerms
SpaceRegion, Room, Place, and inRoom, which is functional
ObjectsPhysicalObject, Furniture, Appliance, objectAt, and contains as a chain
Room typesKitchen and its axiom
DrinksDrink, Container, Bottle, Can, Glass, WineGlass, Carafe
PeoplePerson, prefers, avoids
PerceptioncocoClass, the label YOLO returns for a class

data/ontology/isfr-base.ttl, namespace https://isfr.tsiogkas.me/ontology/isfr#

The micro-project and week 5

Model the apartment

  • Extend the base ontology with a drink taxonomy, room types for bathrooms and bedrooms, the nine rooms, furniture, seven drinks and five people
  • Answer six competency questions with SPARQL, on what you wrote and on the closure
  • Assert every room as an isfr:Room and nothing more

In exercises/04-ontologies/. answer.py runs every query twice. No Webots.

The household

  • Ana prefers water.
  • Ben prefers beer.
  • Chloé prefers non-alcoholic drinks and avoids fizzy ones.
  • Eve prefers wine. The apartment holds wine glasses and no wine.
  • Dev is a guest who has stated nothing.

Seven drinks: three bottles of beer and a can of cola in living_room_1, a bottle of water in the kitchen, and a carafe of water and a carafe of orange juice in living_room_2.

Six questions

  1. Which rooms are kitchens, bathrooms and bedrooms?
  2. Where is each drink, by place and room?
  3. Which alcoholic drinks are in the apartment?
  4. What could the robot bring Chloé?
  5. Who has no preferred drink anywhere in the apartment?
  6. What could the robot bring Dev?

Question 6 has two readings, the drinks Dev prefers and the drinks Dev does not avoid. Two sentences say which the robot should act on.

Next week

  • The same graph gains places with anchors, a doorway as a gap in the lidar scan or an object the detector names
  • Edges between places carry coarse relative poses, and a route is a search over them

Before then, read the Description Logic Primer, sections 1, 2.1, 2.2 and 4, and run the example.