====== Reasoning with Ontologies ====== ^ Last verification: | 20180914 | ^ Tools required for this lab: | [[http://protege.stanford.edu/products.php#desktop-protege|Protégé Desktop 5.0]] | ^ ::: | [[http://semanticweb.org/wiki/Pellet|Pellet 2.3.1]] ({{http://krzysztof.kutt.pl/didactics/semweb/pellet-2.3.1.zip|pellet-2.3.1.zip}}) | ===== Introduction ===== * Lecture: {{.:2014:eis2014semweb-ontology-logic.pdf|Ontology engineering and reasoning in Semantic Web}} (2014) * OPTIONAL: [[https://www.cambridgesemantics.com/blog/semantic-university/intro-semantic-web/semantic-web-misconceptions/|Semantic Web Misconceptions]] (this is our last lab, so this is the right moment for this text :-) ) * [[#if_you_want_to_know_more|If you want to know more...]] * OWL is based on Description Logics formalism -- if you want to know more about it, you can familiarize yourself with optional [[lab-desc-logic|Intro to Description Logics]] lab. ===== Lab instructions ===== ==== - 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?]] * 8-) Let's check if you understand this difference properly: Take your [[lab-owl|ontology from Protégé lab]]. Identify which statements belong to Terminology (TBox) and World Description (ABox). Put them in the report divided into two sections: TBox and ABox (5 statements for each section). ==== - 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?w200|}} \\ - and ObjectProperties: \\ {{.:protege-reasoning2.png?w200|}} \\ - Define the BusDriver class with ''Equivalent classes'' button \\ {{.:protege-reasoning3.png?w200|}} - Build the second axiom analogously: \\ {{.:protege-reasoning4.png?w200|}} \\ - Build the third axiom using the ''SubClass of'' button: \\ {{.:protege-reasoning5.png?w200|}} \\ - Start the reasoner (''Reasoner -> start reasoner'') and observe the inferred class hierarchy. What conclusions have been drawn? \\ {{.:protege-reasoning6.png?w200|}} \\ - 8-) Include the modified ontology in the report. - 8-) 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. ==== - 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. [[http://en.wikipedia.org/wiki/White_van_man|Wikipedia]] provides an entry with some additional information and references.// \\ Hints: - Create appropriate instances in ''Individuals'' tab \\ {{.:protege-reasoning7.png?w200|}} - If the instance is of 2 types, create it only once and then add the second type: \\ {{.:protege-reasoning8.png?w200|}} - Add object properties to connect individuals: \\ {{.:protege-reasoning9.png?w200|}} - Define the class: \\ {{.:protege-reasoning10.png?w200|}} - Start the reasoner (''Reasoner -> start reasoner'') and observe the inferred class hierarchy. Where is the ''white_van_man''? What conclusions have been drawn? - 8-) Include the modified ontology in the report. - 8-) 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. ==== - OWL Reasoning - Reasoners [5 minutes] ==== 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://krzysztof.kutt.pl/didactics/semweb/pellet-2.3.1.zip|Pellet}} reasoner. - Unpack the zip. - Run ''pellet.sh help'' to get familiar with available commands. - Try ''pellet.sh consistency '' where the '''' is: - Your ontology from [[.:lab-owl|previous lab]] - ''people+pets.owl'' ontology provided with Pellet in ''examples/data/'' directory \\ and observe the results. - Try ''pellet.sh classify '' with the two above mentioned ontologies and observe the results. - 8-) What are the results? Write them down or provide a screenshot of the answer in the report. ==== - 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 {{.:ontologies.zip|}} pack. - Open Protege (type ''protege'' in command line on lab316 laptop). === - Warm up === - Open (''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 classes''): ''Man EquivalentTo Person that hasSex some Male'' etc. \\ {{.:owl-man.png?180|}} - Import plain-individuals, 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?300|}} - Using the ''Reasoner'' menu in Protege (''Reasoner -> Start/Synchronize reasoner''), classify the ontology. What inferences are made? Write them in the report 8-) === - 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?200|}} - Create restrictions on Person: ''has Mother some Woman'', ''hasFather some Man'' \\ {{.:owl-hasparents.png?200|}} - Load ''individuals-1-parantage.owl'' file. - Classify the ontology. What inferences are made? Write them in the report 8-) === - Datatype properties === - Close the previous ontology. Load ''Family-tree-2.owl''. - Create or find datatype properties: ''birthYear'', ''deathYear'', make them //functional//. \\ {{.:owl-datatypes.png?200|}} - Create ''Victorian'' class: ''Person and birthYear some integer[>=1837, <=1901]'' - Classify the ontology. How many individuals have been classified as Victorians? 8-) === - 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? 8-) - Close the previous ontology. Load ''Family-tree-4.owl''. - Model the information about David: \\ {{.:owl-david.png?300|}} - Classify the ontology. Answer the questions: - What type does David_bright_1934 have? 8-) - How many children does he have? 8-) === - Property chains === - Close the previous ontology. Load Family-tree-5.owl. - Add hasGrandParent sub prop of hasAncestor (inverse grandparentOf) - Add domain and ranges - Add sub properties ''hasGrandMother/Father'' + domains and ranges - Add property chain ''hasParent o hasFather/Mother -> hasGrandFather/Mother'' \\ {{.:owl-grandpa.png?300|}} - Classify the ontology. What do we learn about Robert? 8-) === - 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?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? 8-) - How to really find parents that have 3 children? 8-) - How to make individuals different from each other? 8-) ===== Materials ===== {{section>.:lab-ontologies#if_you_want_to_know_more}}