===== Reasoning in ontologies ===== * Last verification: **20221121** * Tools required for this lab: * [[https://protege.stanford.edu/software.php#desktop-protege|Protégé Desktop 5]] * Reasoner: * [[http://www.hermit-reasoner.com/|HermiT]] (mirror: {{https://krzysztof.kutt.pl/didactics/semweb/HermiT-1.3.8.1099.zip|HermiT-1.3.8.1099.zip}}) * [[http://semanticweb.org/wiki/Pellet|Pellet 2.3.1]] (mirror: {{https://krzysztof.kutt.pl/didactics/semweb/pellet-2.3.1.zip|pellet-2.3.1.zip}}) (works only on Java <= 8) ==== Prepare yourself for the lab ==== * [[https://cambridgesemantics.com/blog/semantic-university/learn-owl-rdfs/flavors-of-owl/|Flavors of OWL @Cambridge Semantics]] * [[https://cambridgesemantics.com/blog/semantic-university/intro-semantic-web/semantic-web-misconceptions/|Semantic Web Misconceptions]] (this is probably the right moment for this text, as you already know something about the ontologies :-) ) * OPTIONAL: OWL is based on Description Logics formalism –- if you want to know more about it, you can familiarize yourself with a [[http://www.cs.man.ac.uk/~horrocks/Slides/IJCAR-tutorial/Display/|Description Logics Tutorial]] ==== Lab instructions ==== === 1. TBox and ABox [10 minutes] === * The knowledge base in OWL (which is based on Description Logics) consists of two types of concepts: * **TBox** -- terminology, intensional representation * **ABox** -- assertions about individuals, extensional representation * [[http://www.mkbergman.com/489/ontology-best-practices-for-data-driven-applications-part-2/|Why should we care about keeping them split?]] * Let's check if you understand this difference properly: Take your [[.:lab_onto2|ontology from previous lab]]. Identify five statements that belong to Terminology (TBox) and five to World Description (ABox). Note: we will **not** use ontology from previous classes during the following exercises (we will only check it using Pellet reasoner in //OWL Reasoning - Reasoners// section). There will be mini-examples for each of them to show particular ideas. === 2. OWL Reasoning - Class Inference [10 minutes] === * In Description Logics on which the OWL language is based there are the following reasoning tasks for classes (terminology, TBox): - Class subsumption (Structuring the knowledge base) - Class equivalence (Are two classes in fact the same class?) - Class disjointness (Do classes A and B have common members?) - Class consistency (Isn't class A empty?) - Model the following ontology axioms in Protege: Class: bus_driver EquivalentTo: person that drives some bus Class: driver EquivalentTo: person that drives some vehicle Class: bus SubClassOf: vehicle Hints: - To build the first axiom: - Create appropriate classes \\ {{.:protege-reasoning1.png?direct|}} \\ - and Object Properties: \\ {{.:protege-reasoning2.png?direct|}} \\ - Define the BusDriver class with ''Equivalent classes'' button \\ {{.:protege-reasoning3.png?direct&w350|}} - Build the second axiom analogously: \\ {{.:protege-reasoning4.png?direct&w350|}} \\ - Build the third axiom using the ''SubClass of'' button: \\ {{.:protege-reasoning5.png?direct&w350|}} \\ - Start the reasoner (''Reasoner -> start reasoner'') and observe the inferred class hierarchy. - What conclusions have been drawn? \\ {{.:protege-reasoning6.png?direct|}} \\ - Explain the inferred relations and conclusions. - Analyze the reasoning examples given [[http://mowl-power.cs.man.ac.uk/2009/07/sssw/people.html#people-class|here]] in "Class Inferences" section. === 3. OWL Reasoning - Instance Inferences [10 minutes] === * In Description Logics on which the OWL language is based there are the following reasoning tasks for instances (world description, ABox): - Class membership (is instance //a// contained in class //C//?) - Instance retrieval (find all (known) individuals belonging to a given class) * and for the whole Knowledge Base (ABox+TBox): - Global consistency of a knowledge base (Is the knowledge base meaningful?) - Download the {{http://krzysztof.kutt.pl/didactics/semweb/people-prep.owl|pre-prepared ontology}} and load it in Protege (**NB:** the ontology classes and those on screenshots may differ a little). - Model the following ontology axioms in Protege: Individual: Daily_Mirror Types: owl:Thing Individual: Q123ABC Types: van, white_thing Individual: Mick Types: man Facts: reads Daily_Mirror, drives Q123ABC Class: white_van_man EquivalentTo: man that drives some (van and white_thing) SubClassOf: reads only tabloid //For those not familiar with UK culture, White Van Man is a stereotype used to describe a particular kind of driver. [[wp>White_van_man|Wikipedia]] provides an entry with some additional information and references.// \\ Hints: - Create appropriate instances in ''Individuals'' tab \\ {{.:protege-reasoning7.png?direct&w350|}} - If the instance is of 2 types, create it only once and then add the second type: \\ {{.:protege-reasoning8.png?direct&w350|}} - Add object properties to connect individuals: \\ {{.:protege-reasoning9.png?direct&w350|}} - Define the class: \\ {{.:protege-reasoning10.png?direct&w350|}} - Start the reasoner (''Reasoner -> Start reasoner'') and observe the inferred class hierarchy. Where is the ''white_van_man''? What conclusions have been drawn? - Explain the inferred relations and conclusions. - Analyze the reasoning examples given [[http://mowl-power.cs.man.ac.uk/2009/07/sssw/people.html#people-instance|here]] in "Instance Inferences" section. === 4. OWL Reasoning - Reasoners [5 minutes] === Description Logics (DL) reasoners may be integrated with other tools -- as in the case of Protege presented before -- as well as run independently via various interfaces. Popular DL reasoners include: FaCT++, Pellet, HermiT, RacerPro and many others. We will use the [[http://www.hermit-reasoner.com/|HermiT]] reasoner (//you can also use Pellet reasoner; the link is at the top of this page//). - Download the reasoner and unpack the zip. - Get familiar with available commands: * For HermiT: ''java -jar HermiT.jar --help'' * For Pellet: ''pellet.sh help'' (use ''pellet.bat'' if you are using Windows) - Check the consistency of the ontology and observe the results: * For HermiT: ''java -jar HermiT.jar -k '' where '''' is: * Your ontology from [[.:lab_onto2|previous lab]] * ''pizza.owl'' ontology provided with HermiT in ''project/examples/ontologies/'' directory * For Pellet: ''pellet.sh consistency '' where the '''' is: * Your ontology from [[.:lab_onto2|previous lab]] * ''people+pets.owl'' ontology provided with Pellet in ''examples/data/'' directory - Classify two above mentioned ontologies and observe the results: * For HermiT: ''java -jar HermiT.jar -cP '' * For Pellet: ''pellet.sh classify '' === 5. Advanced OWL reasoning [50 minutes] === These instructions are based on the [[http://www.cs.man.ac.uk/~stevensr/menupages/fhkb.php|The Family History Knowledge Base Tutorial]]((Updated version of the tutorial is available [[http://owl.cs.manchester.ac.uk/publications/talks-and-tutorials/fhkbtutorial/|here]].)) by The University of Manchester, School of Computer Science. - Download the {{https://krzysztof.kutt.pl/didactics/semweb/fhkb-ontologies.zip|fhkb-ontologies.zip}} pack. - Open Protege === 5.1 Warm up === - Load ''Family-tree-0.owl'' - It contains ''Sex'', ''Female'', ''Male'', ''Person'', ''Man'' and ''Woman'' classes. - Create ''hasSex'' property. Set domain and ranges on ''hasSex'' (Person/Sex). Make it //functional//. - Create restrictions on ''Person'': ''hasSex some Sex''. - Make ''Man'' and ''Woman'' **defined** (use ''Equivalent to''): ''Man EquivalentTo Person that hasSex some Male'', etc. \\ {{.:owl-man.png?direct&180|}} - Import ''plain-individuals.owl'' file. Observe that none of them have any assertions on them (''Active Ontology'' tab -> ''Imported ontologies'' -> ''Direct imports''). - Choose an individual, add ''Types'': ''Person and (hasSex some Male)'' \\ {{.:owl-robert-individual.png?direct&300|}} - Using the ''Reasoner'' menu in Protege (''Reasoner -> Start/Synchronize reasoner''), classify the ontology. What inferences are made? === 5.2 Characteristics of properties === - Close the previous ontology. Load ''Family-tree-1.owl''. Check how ''Man'' and ''Woman'' classes are defined. - Create object properties: ''hasFather'', ''hasMother'', make them //functional//, add //domain// and //range//: ''Person'', ''Man/Woman'', add //inverse properties//: \\ {{.:owl-hasmother.png?direct&200|}} - Create restrictions on Person: ''has Mother some Woman'', ''hasFather some Man'' \\ {{.:owl-hasparents.png?direct&200|}} - Load ''individuals-1-parantage.owl'' file. - Classify the ontology. What inferences are made? === 5.3 Datatype properties === - Close the previous ontology. Load ''Family-tree-2.owl''. - Create or find datatype properties: ''birthYear'', ''deathYear'', make them //functional//. \\ {{.:owl-datatypes.png?direct&200|}} - Create ''Victorian'' class: ''Person and birthYear some integer[>=1837, <=1901]'' * If ''<='' does not work, try: ''Person and (birthYear some xsd:integer[>=1837]) and not (birthYear some xsd:integer[>1901])'' - Classify the ontology. How many individuals have been classified as Victorians? === 5.4 Transitive properties === - Close the previous ontology. Load ''Family-tree-3.owl''. - Create a new super-property of ''hasParent'' called ''hasAncestor'', - Make it transitive and create inverse property. - Clasify, look at property hierarchy. What do we know about Robert? - Close the previous ontology. Load ''Family-tree-4.owl''. - Model the information about David: \\ {{.:owl-david.png?direct&300|}} - Classify the ontology. Answer the questions: - What type does ''David_bright_1934'' have? - How many children does he have? === 5.5 Property chains === - Close the previous ontology. Load ''Family-tree-5.owl''. - Add ''hasGrandParent'' subProperty of ''hasAncestor'' (inverse ''grandparentOf''). - Add domain and ranges. - Add subProperties ''hasGrandMother/Father'' + domains and ranges - Add property chain ''hasParent o hasFather/Mother -> hasGrandFather/Mother'' \\ {{.:owl-grandpa.png?direct&300|}} - Classify the ontology. What do we learn about Robert? === 5.6 Classes with Individuals, Open World Assumption === - Close the previous ontology. Load ''Family-tree-6.owl''. - Make class of all ancestors and class of robert's ancestors. \\ {{.:owl-class-individuals.png?direct&400|}} - Classify. What are the results? - Make class of people with min 3 children. - Classify the ontology, do we find parents with 3 children? Why? - How to really find parents that have 3 children? - How to make individuals different from each other? ==== Learn more! ==== {{section>.:lab_onto101#learn_more&noheader&nofooter}}