Advanced ontology engineering
- Last verification: 20220909
- Tools required for this lab:
- OOPS! (OntOlogy Pitfall Scanner!) (web service)
Prepare yourself for the lab
Lab instructions
1. Let's start: Protégé Desktop
During this lab we will continue the development of the ontology started in the previous classes.
During the previous lab you did a lot of conceptual work – you thought about the purpose of an ontology, its scope and basic concepts.
Now, we will focus on the more technical aspects, introducing selected constructs of the OWL language.
NOTES:
- As previously, the lab is divided into several sections. Each of them should take approx. 10 minutes!
- The following tasks will sometimes involve specific situations. Try to implement them analogously in your knowledge graph to best understand the particular aspects.
- The key classes are:
RiversideBandMusicCD
(in Primitive class hierarchy section),BaroqueOrganMusicCD
(in Properties and Restrictions section),GuitarMusicCD
(in Defined Classes section),ACapellaMusic
(in Union in OWL section),ACapellaMixMusicCD
(in Universal Restriction and Open World Assumption section).
- The Build your first ontology tutorial studied in previous classes may be useful as a reference.
Let's start!
- Download your ontology from WebProtégé
- Open the projects list: https://webprotege.stanford.edu/#projects/list
- From hamburger menu (on the right) select Download
- Download and start Protégé Desktop 5
- Load your ontology in Protégé Desktop:
File
→Open…
- You can change the prefix for your ontology using:
File
→Preferences
→New entities
→Entry IRI
, e.g.https://your-name/game-of-thrones
.- This will be a prefix for all concepts/relations/individuals that we will define in our ontology.
- This will not change the existing URIs (generated, e.g., by WebProtégé)
- You can also specify URI for your ontology (ontology is abstract thing in universe we describe, so it also has URI ;) ) using:
Refactor
→Change ontology IRI…
(it CAN be the prefix, e.g.https://your-name/game-of-thrones
)
2. Primitive class hierarchy
- Do you have a simple hierarchy of classes and subclasses in your model? If not, complete it now!
- Use
Classes
→Class hierarchy
tab.
- Create a class that is a subclass of several classes. In media ontology, we declare the
RiversideBandMusicCD
class (Riverside) as a subclass ofBandMusicCD
,PolishMusicCD
andProgressiveRockMusicCD
( create the class once, then choose the class, click on theSubClass of
button in the class description, and choose appropriate classes fromClass hierarchy
tab).
- You should now have a small hierarchy of classes.
3. Disjoints
- To make sure a Book cannot be a MusicCD at the same time, add disjoints into your primitive tree.
- Select one of your top level concepts (e.g., Book)
- Select
Make primitive siblings disjoint
in theEdit
Menu - In
Reasoner
menu chooseHermiT
. Start the reasoner. Once your reasoner is running, periodically classify your ontology by pressing theSynchronize reasoner
button in theReasoner
menu. Inferred hierarchy can be seen in “Class hierarchy (inferred)” tab:
- If you get inconsistencies (some classes will become red in the hierarchy), see what is wrong with
Explain inference
button (question mark inDescription
tab; see picture in Defined Classes section below) and repair the ontology.
4. Properties and Restrictions
In order to describe our classes we need properties, which are used to relate members of a class. We then add restrictions on the class to state logically how these properties are used.
At this stage we are creating Primitive Classes, which only have necessary conditions (in this case, restrictions) on them –- these are conditions that must be satisfied by all members of this class.
-
- The important thing is that we have a class (
MusicInstrument
) and a set of its subclasses. - We will also define another hierarchies, which will be related to the one in the figure (with
Artist
/MusicCD
as a superclass). - In your ontology, these hierarchies can be anything, e.g., different areas and the associated hierarchy of rulers or classes of wizards and the associated hierarchy of schools of magic.
- Step 1: Create Properties
- Select the
Object Properties
tab - Create 2 more properties:
containsMusic
andcontainsMusicPerformedOn
- Step 2: Create restrictions
- Select the Classes Tab
- Select the MusicCD class
- In the right panel for this class, select
SubClass of
(click the circle with + to add new superclass), then chooseObject restriction creator
tab
- Step 3: Define a
BaroqueOrganMusicCD
class- Create a new subclass of
MusicCD
:BaroqueOrganMusicCD
- Select
SubClass of
→Object restriction creator
- Using Existential restriction choose
containsMusicPerformedOn
in the left window andOrganInstrument
in the class hierarchy in the right window. Set another restriction saying thatBaroqueOrganMusicCD
-containsMusic
-BaroqueMusicGenre
. Eventually you should have a primitive class defined as follows:
- Create a class
JimiHendrixMusicCD
as a subclass of the MusicCD, define that it contains music performed on an electric guitar. - Create some other kinds of MusicCD, books or movies (if you haven't exceeded your 10 minutes/section yet)
5. Defined Classes
Creating a Defined Class is similar to creating a primitive class (as in previous step), but a defined class has one or more Necessary & Sufficient Condition. Classes can easily be migrated between primitive and defined.
- In this exercise, we wish to model the statement: “Any MusicCD that contains music played on any kind of guitar is a GuitarMusicCD”.
- What would an analogous statement look like for your ontology? Maybe “Any person who practices fire magic is a fire mage” or “Any person who rules a kingdom is a king”?
- Create a new subclass of
MusicCD
calledGuitarMusicCD
. In general, defined classes are not disjoint from their siblings - Create a restriction on
GuitarMusicCD
to state that it contains music performed on guitar. - Classify your ontology (Synchronize the reasoner) and check the
Class hierarchy (inferred)
to see what has been classified under the new class. - All MusicCDs that are set to contain music performed on any kind of guitar should now be subclasses of GuitarMusicCD.
- Click on the JimiHendrixMusicCD which should be classified as a GuitarMusicCD. Choose
Explain inference
button (with question mark) and analyze the inference the reasoner did to classify the subclass relationship.
- If you have time, create several other defined classes and classify each time to see if their definitions are correct.
6. Union in OWL
In order to define an ACappellaMusicCD, we are going to model the idea of a music performed without instruments. This class is going to be covered by all of the Music that are not InstrumentalMusic. GregorianChant, JewishCantillation, MuslimAnaseheed, etc. are all to be classified as ACapellaMusic.
- Create a
Music
class and the following subclasses of theMusic
:GregorianChant
,JewishCantillation
,MuslimAnaseheed
. - Create a new subclass of
Music
calledACapellaMusic
- Click on the
Equivalent to
add button - Select the
Class expression editor
- Click OK to accept the changes. This can only be done when the expression is correct (e.g., the class names are valid)
7. Universal Restriction and Open World Assumption
To state that members of a class can only have a specific relationship with individuals
from a specific class we use a Universal (AllValuesFrom) restriction. We need to model the fact that:
Any MusicCD that only has music from ACapellaMusic is a ACapellaMusicCD
- Create a new subclass of
MusicCD
calledACapellaMusicCD
- Convert this class into a defined class by selecting the conditions and choosing
Convert selected rows to defined class
- Create a
ACapellaMixMusicCD
as a subclass of theMusicCD
. - Classify your ontology.
- What happens? Do you get the expected results? Is the
ACapellaMixMusicCD
classified as anACapellaMusicCD
?
8. Closing the classes
Why the ACapellaMixMusicCD wasn't classified as a ACapellaMusicCD, although it has only ACapellaMusic on it?
Because reasoning in OWL-DL is based on the Open World Assumption:
- Non-existence cannot be assumed, it has to be stated explicitly
- CD could have additional kinds of music on it
- Definitions in OWL-DL need closure axiom (to explicitly say class has only the referred restrictions)
Therefore, we need to close our MusicCD descriptions in order for them to classify correctly.
- Select the
ACapellaMixMusicCD
- Create a new
Only (universal)
restriction along the containsMusic property. The filler will be a union of all of the music kinds on the CD – ie the union should match all of the music kinds of the existingSome (existential)
restrictions using the contains property. Select AddSubClass of
button, then Class expression editor and type the following:
- Classify your ontology to check if this class classifies under
ACapellaMusicCD
.
9. Data Properties
Data Properties are relations that connect objects and literals.
As a range, you can specify any datatype (most often we use the XSD Datatypes; you have seen them in RDF: Datatypes section of Modeling with RDF and RDFS lab.
Setting a domain on a property may lead to unexpected classifier results if the property is misused (e.g., if the domain has been over-constrained; or we use the property dedicated to other class). We will explore this further in this exercise.
- Create a
publishedIn
data property in theData Properties
tab. - Solve the problem so both MusicCDs and Books can be
published
in the ontology.
10. Finish the ontology
- Finally, we will check our ontology against the most common pitfalls. We can do this using the OOPS! (OntOlogy Pitfall Scanner!).
- Export the ontology to RDF/XML format (used by OOPS!):
File
→Save as
→RDF/XML
- Paste your RDF/XML file in the OOPS! and click
Scanner by RDF
- Fix your ontology accordingly to the guidelines.
- Note: as we are learning how to develop ontologies, there is no need to fix all the issues. Correct the most important errors and see what else should be fixed in ready-to-publish ontology (e.g., Missing annotations or No license declared may be omitted).
- Save the final version of the ontology in a safe place! We will use it during the next two labs.