axiothOntology Hub

Learn what an ontology is / Part 4. Design and quality · Lesson 19 of 24

Checking quality: common mistakes and automated checks

Find contradictions and empty classes with a reasoner, run competency questions as tests, and go through a list of common design mistakes.

Read first: 14. OWL, one step further: property characteristics and class definitions · 15. SHACL: checking that data has the right shape · 12. SPARQL, one step further: optional parts, filters and unions

An ontology goes wrong just as software does. It never crashes, though, so it tends to stay wrong for a long time. Checking happens at three levels: is the logic sound, does it answer the questions it was built for, and does it follow the conventions that make it easy for others to use.

1. Logic: ask a reasoner

ProblemMeaningExample
InconsistencyNot everything stated can be true at onceNabi is a cat and a dog, and the two are declared disjoint
Unsatisfiable classA class that can never have a memberA subclass of two disjoint classes
Unintended inferenceNot a contradiction, yet not a conclusion you wantedA domain classifies Seoul as a person
ex:Cat owl:disjointWith ex:Dog .

ex:CatDog rdfs:subClassOf ex:Cat , ex:Dog .   # a class that can never have a member
ex:nabi a ex:CatDog .                         # this line makes the whole ontology inconsistent

An unsatisfiable class on its own is not yet a contradiction. The moment one individual is stated to belong to it, the whole ontology becomes inconsistent. Anything at all follows from an inconsistent ontology, so no inference from it can be trusted. A reasoner finds these two. The third row, unintended inference, only shows up when a person reads the results.

2. Requirements: competency questions as tests

Keep the questions written first in the design lesson as SPARQL files, and run them again every time the ontology changes. Written as ASK, the answer is true or false, which is a pass or a fail as it stands.

PREFIX ex: <https://example.org/>
ASK {
  ?d a ex:Dataset ;
     ex:measuredBy ?s .
  ?s a ex:Sensor .
}

"Is there a dataset measured by a sensor" written as an ASK. The answer is false. The file never says that ex:dataset1 is a dataset or that ex:thermo7 is a sensor.

Not a character of the file changed, and the test passes. Domain and range inferred the type of both things. A test result depends on whether inference runs as well as on the ontology, so run it under the same conditions as real use.

The same approach finds things that must not be there. Any row in the result is something to fix.

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?class WHERE {
  ?property rdfs:domain|rdfs:range ?class .
  FILTER NOT EXISTS { ?class rdfs:label ?label . }

This check fails when a row comes out. Of the classes used as a domain or range, ex:Dataset is caught for having no label. ex:Sensor has one and does not appear.

3. Conventions: a list of common mistakes

MistakeWhy it mattersThe fix
Terms with no label or definitionUsers guess at the meaningGive every term a label and a definition
A part written as a subclassIf "wheel is a subclass of car", every wheel is a carConnect them with a property such as ex:partOf
An individual written as a classThere cannot be several "Seoul"sAsk whether there can be many examples of it
Narrow domains and rangesThey infer rather than check, so odd classifications appearKeep them broad or leave them out, and check with SHACL
A hierarchy that loopsIf A is under B and B is under A, the two become the same classIf intended, write owl:equivalentClass
No disjointness declaredMisclassified data never shows up as a contradictionDeclare sibling classes that cannot overlap as disjoint
Re-creating a term that existsMore IRIs for one meaning, and data that does not mergeSearch first, then reuse

Tools check lists like this automatically. OOPS! takes an ontology on the web and reports common mistakes, and ROBOT, widely used for life-science ontologies, has a report command of the same kind.

Data quality is a separate matter

Everything so far checks the blueprint itself. Whether data that follows it has its required values and the right kinds of value is checked with shapes, as in the SHACL lesson. A sound blueprint can have wrong data, and the reverse is true as well.

Common misunderstandings

The reasoner finished without errors, so the ontology is right.
It means only that no declarations clash. Whether it matches reality and answers the questions needed is settled by competency questions and by people reviewing it.
A contradiction only arises when bad data gets in.
Class definitions can clash with each other too. An unsatisfiable class can be found before a single line of data exists.
Disjointness declarations are not really needed.
Without them a reasoner has no clash to catch. Data saying something is both a cat and a dog passes quietly.

A reasoner looks at the logic, competency questions at the requirements, and the mistake list at the conventions. Run all three together on every change.