====== Ontology engineering with Protégé ====== ^ Last verification: | 20180914 | ^ Tools required for this lab: | [[http://protege.stanford.edu/products.php#desktop-protege|Protégé Desktop 5]] | ===== Before the lab ===== Reading: * **[[http://protege.stanford.edu/publications/ontology_development/ontology101-noy-mcguinness.html|Build your first ontology]]** * [[http://www.cs.uu.nl/docs/vakken/smw/lectures/Semantic%20Web%20Languages.pdf|Ontology, SW languages]] * [[http://www.slideshare.net/ocorcho/ekaw2014-keynote-ontology-engineering-for-and-by-the-masses-are-we-already-there-42068683|Ontology Engineering for and by the Masses: are we already there?]] Tutorials: * [[http://owl.cs.manchester.ac.uk/publications/talks-and-tutorials/protg-owl-tutorial/|Protégé OWL tutorial]] * [[#if_you_want_to_know_more|If you want to know more...]] ===== Lab instructions ===== This lab aims to get you familiar with the Protégé ontology editor and chosen OWL constructs. You are encouraged to continue developing and refining your ontology at home. **NOTES:** - The lab is divided into sections. You should allow aprox. 10 minutes for each section. - As you follow the instructions, do all the tasks on your [[.:lab-ontologies|ontology started in WebProtégé]] or prepare the new one accordingly to the instructions. - If you work with your own ontology, mark in the report which class corresponds to: - JazzMusicCD,​ ClassicalMusicCD,​ RockMusicCD,​ MetalMusicCD - BaroqueOrganMusicCD - ACapellaMusicCD ==== 0 Using Protégé on lab316 notebooks/PCs ==== To run Protégé: * select it from Programs -> Favourites menu * or type:$ protege in terminal ==== - Protégé. Primitive class hierarchy ==== - Start Protégé. - You will now have an empty ontology. \\ {{.:protege5_empty_onto.png?w500|}} \\ Firstly, let's specify URI for our new ontology using menu ''Refactor'' -> ''Change ontology IRI...'', e.g. ''http://your-name/multimedia''. This will be a prefix for all concepts that we will define in our ontology. - Begin to create the primitive classes in your model. This begins with a couple of top-level concepts. Create the following tree by using the Create Subclass and Create Sibling Class buttons in the Asserted Hierarchy on Entities tab. \\ {{.:protege5_class_hierarchy.png|}} \\ - Create further subclasses of the library item categories producing a hierarchy. We recommend suffixing each book with ...Book, each CD with CD and so on. Make sure you have at least included the following as they will be used later: ''JazzMusicCD, ClassicalMusicCD, RockMusicCD, MetalMusicCD''. Notice that we are adding a suffix of MusicCD to all the subclasses of MusicCD – this is to allow for the later possibility of extending our ontology to talk about other types of multimedia such as computer games, where ''FrenchArtistMusicCD'' might be different from ''FrenchArstistMovie'' - Where required, add additional superclasses using the ''SubClass of'' button and the ''Class hierarchy'' tab. \\ {{.:protege5_add_superclass.png|}} \\ {{.:protege5_class_hierarchy2.png?w400|}} \\ Notice that classes with multiple parents appear in several places in the asserted hierarchy. - Create a ''RiversideBandMusicCD'' class as a subclass of ''BandMusicCD'', ''PolishMusicCD'' and ''ProgressiveRockMusicCD'' (:!: create the class __once__, then choose the class, click on the ''SubClass of'' button in the class description, and choose appropriate classes from ''Class hierarchy'' tab). \\ {{.:protege5_multiple_superclasses.png?w500|}} \\ - You should now have a small hierarchy of MusicCDs/Movies/Books. Add to these whenever you have a few minutes as they will allow you to create a larger ontology of multimedia later on. ==== - 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 (eg. Book) - Select ''Make primitive siblings disjoint'' in the ''Edit'' Menu - Repeat this where appropriate, for each level of your ontology, selecting a class and making all of its siblings disjoint. \\ {{.:protege5_disjoint_classes.png|}} \\ - In ''Reasoner'' Menu choose HermiT. Start the reasoner. Once your reasoner is running, periodically classify your ontology by pressing the ''Synchronize reasoner'' button on the toolbar. Inferred hierarchy can be seen in "Class hierarchy (inferred)" tab: \\ {{.:protege5_inferred_hierarchy.png|}} \\ - :!: 8-) If you get inconsistencies (some classes are highlighted red in the hierarchy), check what to do [[#property_domain|here]]. Take a screenshot of the inconsistent class hierarchy, see what is wrong with ''Explanation button'' and repair the ontology. Write in the report how you repaired it. - Add more multimedia categories if you have time, making sure these are disjoint where necessary. ==== - 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. * For this exercise create classes as in the picture: (//note the new class: ''Artist''// :!:) \\ {{.:protege5_class_hierarchy3.png|}} \\ - Step 1: Create Properties - Select the ''Object Properties'' tab - Create a new Object Property, ''containsMusicPerformedBy'' \\ {{.:protege5_objectproperty.png?w400|}} \\ - Create 2 more properties: ''containsMusic'' and ''containsMusicPerformedOn'' - Step 2: Create restrictions - Select the Classes Tab - Select the MusicCD class - In the rigth panel for this class, select ''SubClass of'' (click the circle with + to add new superclass), then choose ''Object restriction creator'' tab - In the left window choose ''containsMusicPerformedBy'' and in the right choose the ''Artist'' class. Make sure that Restriction Type is set to ''Some (existential)''. This means that for every MusicCD there exist an artist who performs the music in this MusicCD. Note that by default, restrictions are created as Necessary Conditions unless the Necessary & Sufficient heading is selected – for creating primitive classes, only create Necessary Conditions. \\ {{.:protege5_restrictions.png?w500|}} \\ - Step 3: Define a class BaroqueOrganMusicCD - Create a new subclass of MusicCD BaroqueOrganMusicCD - Select BaroqueOrganMusicCD (note the superclass inherited from the MusicCD) \\ {{.:protege5_inheritedsuperclass.png?w500|}} \\ - Select ''SubClass of -> Object restriction creator'' - Using Existential restriction choose ''containsMusicPerformedOn'' in the left window and ''OrganInstrument'' in the class hierarchy in the right window. Set another restriction saying that ''BaroqueOrganMusicCD'' - ''containsMusic'' - ''BaroqueMusicGenre''. Eventually you should have a primitive class defined as follows: \\ {{.:protege5_namedclass.png?w500|}} \\ - 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//) ==== - Defined Classes and Additional Modelling Constructs in OWL ==== Creating a defined class is similar to creating a primitive class, but a defined class has one or more Necessary & Sufficient Condition. Classes can easily be migrated between primitive and defined. We wish to model the statement: "Any MusicCD that contains music played on any kind of guitar is a GuitarMusicCD". - Create a new subclass of MusicCD called GuitarMusicCD. In general, defined classes are not disjoint from their siblings - Create a restriction on GuitarMusicCD to state that it contains music performed on guitar. - Select both conditions (the new restriction and the superclass, MusicCD) and in the context menu choose ''Convert selected rows to defined class''. \\ {{.:protege_definedclass.png|}} \\ They should move to the ''Equivalent classes'' section and the class icon (see class hierarchy) should change to contain an equivalence symbol. You can also create restrictions under this heading automatically by selecting it before pressing Create Restriction. The result should be as below: \\ {{.:protege_definedclass1.png|}} \\ - Classify your ontology (Synchronize the reasoner) and check in the ''Class hierarchy (inferred)'' to see what has been classified under the new class. An Inferred Hierarchy panel appears: All MusicCDs that are set to contain music performed on any kind of guitar should now be subclasses of GuitarMusicCD. \\ {{.:protege5_inferredclasshierarchy.png|}} \\ - Click on the JimiHendrixMusicCD which should be classified as a GuitarMusicCD. Choose ''Explain inference'' question mark button and analyze the inference the reasoner did to classify the subclass relationship. * This option may be unavailable if you use a reasoner older than HermiT 1.3.4 :-( \\ {{.:protege5_inferenceexpl.png|}} \\ - If you have time, create several other defined classes of your choosing and classify each time to see if their definition has "captured" the correct named CDs. ==== - 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. * Create the following subclasses of the ''Music'' class: GregorianChant, JewishCantillation, MuslimAnaseheed. - Create a new subclass of Music called ACapellaMusic - Click on the ''Equivalent to'' Add button - Click the ''Class expression editor'' - In the expression editor that appears type a list of the Music you would like to be considered ACapella, separated by the union symbol (which can be added by typing "or" (lowercase). \\ {{.:protege5_union.png|}} \\ - Click OK to accept the changes. This can only be done when the expression is correct (e.g. the class names are valid) - Classify your ontology – check that all the expected Music classes are now subsumed by ACapellaMusic. \\ {{.:protege5_inferredclasshierarchy1.png|}} \\ ==== - 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 called ACapellaMusicCD - (With the Add button in ''SubClass of'') create an ''Only (universal)'' restriction on this class along the containsMusic property with a filler of ACapellaMusic. \\ {{.:protege5_universal.png|}} \\ - 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 the MusicCD. - Add restrictions as in the picture: the CD should contain some GregorianChant, JewishCantillation and some MuslimAnasheed music. \\ {{.:protege_universal-example.png|}} \\ - Classify your ontology. Answer the questions: * 8-) What happens? Do you get the expected results? Is the ACapellaMixMusicCD classified as an ACapellaMusicCD? ==== - 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 existing ''Some (existential)'' restrictions using the contains property. Select Add ''SubClass of'' button, then Class expression editor and type the following: \\ {{.:protege5-closing.png|}} \\ - Classify your ontology to check if this class classifies under ACapellaMusicCD. - If you have time, repeat the experiment for other classes. ==== - DataProperties ==== - Create a publishedIn DataProperty in the ''Data Properties'' tab. - Set the property's domain to MusicCD, range to dateTime (or other appropriate datatype if dateTime isn't available), set the property as "functional" \\ {{.:protege5-dataproperty1.png?w500|}} \\ Setting a domain on a property may lead to unexpected classifier results if the property is misused (eg if the domain has been over-constrained). - Go to the Entities tab and add a new existential restriction for the class Book saying that has to be published somewhen \\ {{.:protege5-dataproperty2.png?w550|}} \\ - Run the reasoner: what happens? why? \\ {{.:protege5-nothing.png?w550|}} \\ - Remove the disjoint axioms and run the reasoner again. What happens now? \\ {{.:protege5-wrongsubclass.png?w550|}} \\ - 8-) Take a screenshot of the inconsistent hierarchy and the explanation. Then solve the problem so both MusicCDs and Books can be published in the ontology. ==== - Finish the ontology ==== - Finally, we will check our ontology against the most common pitfalls. We can do this using the [[http://oops.linkeddata.es/|OOPS! (OntOlogy Pitfall Scanner!)]]. - Run the OOPS! and fix your ontology accordingly to the guidelines. 8-) Send the report, the ontology file in Turtle syntax (File -> Save as -> Turtle) to your teacher. ===== Control questions ===== * what is Ontology? * what is an ontology? * what are the ontologies for? * what are the main components of an ontology? * what is OWL and what sublanguages the are? * what RDFS limitations does OWL overcome? * what are Description Logics? * What are the consequences of OWL being grouned in DL? * What is Closed World Assumption, what Open World Assumption? Which is valid in OWL? * what are the reasoning tasks for a DL ontology? ===== Materials ===== {{section>.:lab-ontologies#if_you_want_to_know_more}}