Reasoning with Rules SWRL as Example. Jan Pettersen Nytun, UIA

Similar documents
SWRL Semantic Web Rule Language. Susana R. Novoa UNIK4710

Knowledge Representation RDF Turtle Namespace

Comparison of Semantic Web serialization syntaxes

logic importance logic importance (2) logic importance (3) specializations of logic Horn logic specializations of logic RDF and OWL

Knowledge Representation VII - IKT507. SPARQL stands for SPARQL Protocol And RDF Query Language

Knowledge Representation. Apache Jena Part II. Jan Pettersen Nytun, UiA

1. Introduction to SWRL

SPARQL: An RDF Query Language

Lecture 4: Reasoning

Short notes about OWL 1

Semantics. KR4SW Winter 2011 Pascal Hitzler 1

SADI Semantic Web Services

The ISO D approach

Knowledge Representation for the Semantic Web

Reasoning with the Web Ontology Language (OWL)

Knowledge Representation for the Semantic Web

Appendix B: The LCA ontology (lca.owl)

FHIR RDF Sample side by side comparisons

COMBINING X3D WITH SEMANTIC WEB TECHNOLOGIES FOR INTERIOR DESIGN

Ontology-based Virtual IoT Devices for Edge Computing

Linking Data with RDF

Ontological Modeling: Part 15

Web Ontology Language: OWL

Table of Contents. iii

Section 2.4: Arguments with Quantified Statements

Tony Mallia Edmond Scientific

Ontological Modeling: Part 7

Semantic Technologies

An Introduction to the Semantic Web. Jeff Heflin Lehigh University

OWL DL / Full Compatability

Chapter 2 AN INTRODUCTION TO THE OWL WEB ONTOLOGY LANGUAGE 1. INTRODUCTION. Jeff Heflin Lehigh University

Lecture 4: January 12, 2015

SPARQL. Part III. Jan Pettersen Nytun, UiA

FOUNDATIONS OF SEMANTIC WEB TECHNOLOGIES

SRM UNIVERSITY. : Batch1: TP1102 Batch2: TP406

Semantic Web Modeling Languages Part I: RDF

THE LOGIC OF QUANTIFIED STATEMENTS

Description Logic. Eva Mráková,

Publishing OWL ontologies with Presto

For return on 19 January 2018 (late submission: 2 February 2018)

An RDF-based Distributed Expert System

Semantic Web Technologies: Web Ontology Language

Deep integration of Python with Semantic Web technologies

Knowledge Representation for the Semantic Web

Lecture 7: January 15, 2014

RDF /RDF-S Providing Framework Support to OWL Ontologies

Deep Integration of Scripting Languages and Semantic Web Technologies

Modeling LMF compliant lexica in OWL-DL

INF3580 Semantic Technologies Spring 2012

FOUNDATIONS OF SEMANTIC WEB TECHNOLOGIES

Exercise 3.1 (Win-Move Game: Draw Nodes) Consider again the Win-Move-Game. There, WinNodes and LoseNodes have been axiomatized.

Knowledge Representation for the Semantic Web Lecture 4: Description Logics III

KDI OWL. Fausto Giunchiglia and Mattia Fumagallli. University of Trento

INF3580/4580 Semantic Technologies Spring 2017

Contents. G52IWS: The Semantic Web. The Semantic Web. Semantic web elements. Semantic Web technologies. Semantic Web Services

RuleML and SWRL, Proof and Trust

Extending OWL with Finite Automata Constraints

Abstract. The report is written in english. Keywords: Linked Data, Clinical Data, Semantic Web, AstraZeneca, RDF, OWL, SPARQL, Jena

a paradigm for the Introduction to Semantic Web Semantic Web Angelica Lo Duca IIT-CNR Linked Open Data:

Schema-Agnostic Query Rewriting in SPARQL 1.1

Semantic Web Ontologies

DEVELOPING AN OWL ONTOLOGY FOR E- TOURISM

OWL Tutorial. LD4P RareMat / ARTFrame Meeting Columbia University January 11-12, 2018

Building Blocks of Linked Data

Semantic Services. Michael Wollowski

THE PREDICATE CALCULUS

Integrating OWL and Rules: A Syntax Proposal for Nominal Schemas

Semantic Web. Ontology and OWL. Morteza Amini. Sharif University of Technology Fall 95-96

LINKING BACKGROUND INFORMATION

Web Ontology Language (OWL)

Lecture 8 OWL: Web Ontology Language

What is the study of logic?

OWL 2 Profiles. An Introduction to Lightweight Ontology Languages. Markus Krötzsch University of Oxford. Reasoning Web 2012

BUILDING THE SEMANTIC WEB

3. Queries Applied Artificial Intelligence Prof. Dr. Bernhard Humm Faculty of Computer Science Hochschule Darmstadt University of Applied Sciences

Querying the Semantic Web

12th ICCRTS. On the Automated Generation of an OWL Ontology based on the Joint C3 Information Exchange Data Model (JC3IEDM)

Chapter 2 & 3: Representations & Reasoning Systems (2.2)

Knowledge Engineering with Semantic Web Technologies

Semantic Web. Rules in Semantic Web. Morteza Amini. Sharif University of Technology Fall 94-95

OWL 2 Rules (Part 2) Tutorial at ESWC2009 May 31, Pascal Hitzler. AIFB, Universität Karlsruhe (TH) Markus Krötzsch

Describing the P3P base data schema using OWL

Ontological Modeling: Part 2

The Semantic Web RDF, RDF Schema, and OWL (Part 2)

ISWC 2017 Tutorial: Semantic Data Management in Practice

Defining Several Ontologies to Enhance the Expressive Power of Queries

The OWL API: An Introduction

OWL and tractability. Based on slides from Ian Horrocks and Franz Baader. Combining the strengths of UMIST and The Victoria University of Manchester

Semantic Web. Rules in Semantic Web. Morteza Amini. Sharif University of Technology Spring 91-92

FOUNDATIONS OF SEMANTIC WEB TECHNOLOGIES

Limitations of the WWW

Forward Chaining Reasoning Tool for Rya

Semantic Web Rules. - Tools and Languages - Holger Knublauch. Tutorial at Rule ML 2006, Athens, GA

Semantic reasoning for dynamic knowledge bases. Lionel Médini M2IA Knowledge Dynamics 2018

Ontological Modeling: Part 11

2. Knowledge Representation Applied Artificial Intelligence

Extracting Ontologies from Standards: Experiences and Issues

Final Exam. Semantic Web Wiltrud Kessler WS 2014/15. Please do not forget to write your name or initials on every sheet you hand in.

Knowledge Representation

Today: RDF syntax. + conjunctive queries for OWL. KR4SW Winter 2010 Pascal Hitzler 3

Transcription:

Reasoning with Rules SWRL as Example Jan Pettersen Nytun, UIA 1

JPN, UiA 2

What is a rule? Consist of premise and a conclusion. Meaning: In any situation where the premise applies the conclusion must also hold. premise conclusion JPN, UiA 3

Agenda Different Types of Reasoning Inductive reasoning Deductive reasoning Abductive reasoning Why rules? The Semantic Web Rule Language (SWRL) SWRL Types of Atoms SWRL Example SWRL Exercise 4

Inductive Reasoning From Wikipedia, the free encyclopedia the premises are viewed as supplying strong evidence for the truth of the conclusion. conclusion of a deductive argument is certain, the truth of the conclusion of an inductive argument is probable, based upon the evidence given. premise conclusion Not as strong as for deductive reasoning JPN, UiA 5

P S O Inductive Reasoning From Wikipedia, the free encyclopedia the premises of an inductive logical argument indicate some degree of support for the conclusion but do not entail it... derives general principles from specific observations based on observations premise conclusion Likely to be true JPN, UiA 6

Inductive Reasoning Example Many observations indicate that humans eventually dies, i.e., humans are mortals. Human(x) Mortal(x) JPN, UiA 7

Deductive Reasoning also Called Deductive Logic, Logical Deduction From Wikipedia, the free encyclopedia If all premises are true, and the rules of deductive logic are followed, then the conclusion reached is necessarily true. In inductive reasoning, the conclusion is reached by generalizing or extrapolating from specific cases to general rules, i.e., there is uncertainty. However, induction used in mathematical proofs is actually a form of deductive reasoning. JPN, UiA 8

Deductive Reasoning Example All men are mortal. Socrates is a man. ------------------------------ Therefore, Socrates is mortal. JPN, UiA 9

Deductive Reasoning Example in First Order Predicate Logic All men are mortal. Socrates is a man. ------------------------------ Therefore, Socrates is mortal. x.man(x) Mortal(x) -- All men are mortal Man(Socrates) -- Socrates is a man -------------------------------------------------------------------------- Man(Socrates) Mortal(Socrates). -- Socrates is mortal JPN, UiA 10

From Wikipedia, the free encyclopedia JPN, UiA 11

[https://explorable.com/inductive-reasoning] Theories have to be tested and hypotheses answered before the scientific community accepts them as truth. JPN, UiA 12

JPN, UiA 13 Abductive Reasoning From Wikipedia, the free encyclopedia Example: The grass is wet; if it rained last night, then it would be unsurprising that the grass is wet. Therefore, by abductive reasoning, the possibility that it rained last night is reasonable. RaindLastNight GrassIsWeet Some other process could have also resulted in a wet grass, such as sprinklers. Consequently, abducing that it rained last night from the observation of wet grass can lead to a false conclusion. SprinklerWasOn GrassIsWeet

Abductive Reasoning Continues Inference to the best explanation. Given a true conclusion and a rule, it attempts to select some possible premises that, if true also, can support the conclusion, though not uniquely. RaindLastNight GrassIsWeet SprinklerWasOn GrassIsWeet Can be used to develop a hypothesis, which in turn can be tested by additional reasoning or data. JPN, UiA 14

Abductive Reasoning Example ref.: https://www.quora.com/what-is-a-good-example-of-abductive-reasoning The doctor hears her patients symptoms, including the regular shortness of breath on cold days and when exercising and abduces that the best explanation of these symptoms is that her patient is an asthma sufferer. The scientist observes the test tube and sees the chemical turn purple. She abduces that either there is potassium in the sample or her colleague is playing yet another prank on her. JPN, UiA 15

Agenda Different Types of Reasoning Inductive reasoning Deductive reasoning Abductive reasoning Why rules? The Semantic Web Rule Language (SWRL) SWRL Types of Atoms SWRL Example SWRL Exercise 16

In some cases we need both Structure and Rules JPN, UiA 17

Example of rule using The Semantic Web Rule Language (SWRL): hasparent(?x,?parent) hasbrother(?parent,?uncle) hasuncle(?x,?uncle) Some statements cannot be expressed in OWL. Modeling constructs of OWL not always adequate or most desirable. Knowledge Representation, Part II, JPN, UiA 18

Agenda Different Types of Reasoning Inductive reasoning Deductive reasoning Abductive reasoning Why rules? The Semantic Web Rule Language (SWRL) SWRL Types of Atoms SWRL Example SWRL Exercise 19

Ref.: https://github.com/protegeproject/swrlapi/wiki/swrllanguagefaq The Semantic Web Rule Language (SWRL) An expressive OWL-based rule language. SWRL allows users to write rules that can be expressed in terms of OWL concepts to provide more powerful deductive reasoning capabilities than OWL alone. JPN, UiA 20

Ref.: https://github.com/protegeproject/swrlapi/wiki/swrllanguagefaq SWRL Rule head body atom ^ atom... atom ^ atom body and head consist of positive conjunctions of atoms (only AND between atoms) Atom p(arg1, arg2,... argn) p is a predicate symbol; arg1, arg2,..., argn are the terms of the expression. JPN, UiA 21

Ref.: https://github.com/protegeproject/swrlapi/wiki/swrllanguagefaq All variables in SWRL are treated as universally quantified ( ), with their scope limited to a given rule. E.g., given: hasparent(?x,?parent) hasbrother(?parent,?uncle) hasuncle(?x,?uncle) This rule applies for all?x, all?parent and all?uncle. JPN, UiA 22

Agenda Different Types of Reasoning Inductive reasoning Deductive reasoning Abductive reasoning Why rules? The Semantic Web Rule Language (SWRL) SWRL Types of Atoms SWRL Example SWRL Exercise 23

Ref.: https://github.com/protegeproject/swrlapi/wiki/swrllanguagefaq SWRL provides seven types of atoms: Class Atoms Individual Property atoms Data Valued Property atoms Different Individuals atoms Same Individual atoms Built-in atoms Data Range atoms JPN, UiA 24

Ref.: https://github.com/protegeproject/swrlapi/wiki/swrllanguagefaq Class Atom OWL named class or class expression and a single argument representing an OWL individual Examples: Person(?p) Man(Fred) Man(?p) -> Person(?p) JPN, UiA 25

Example of Class Expression (haschild >= 1)(?x) -> Parent(?x) JPN, UiA 26

Ref.: https://github.com/protegeproject/swrlapi/wiki/swrllanguagefaq Individual Property Atom OWL object property and two arguments representing OWL individuals. Examples: hasbrother(?x,?y) hassibling(fred,?y) Person(?p) ^ hassibling(?p,?s) ^ Man(?s) -> hasbrother(?p,?s) JPN, UiA 27

Ref.: https://github.com/protegeproject/swrlapi/wiki/swrllanguagefaq Data Valued Property OWL data property and two arguments, the first representing an OWL individual, and the second a data value. Examples: hasage(?x,?age) hasheight(fred,?h) hasage(?x, 232) hasname(?x, "Fred") Person(?p) ^ hascar(?p, true) -> Driver(?p) Person(Fred) ^ hascar(fred, true) -> Driver(Fred) JPN, UiA 28

Ref.: https://github.com/protegeproject/swrlapi/wiki/swrllanguagefaq Different Individuals Atom Arguments representing OWL individuals. Examples: differentfrom(?x,?y) differentfrom(fred, Joe) Same Individual Atom Arguments representing OWL individuals. Examples: sameas(?x,?y) sameas(fred, Freddy) JPN, UiA 29

Ref.: https://github.com/protegeproject/swrlapi/wiki/swrllanguagefaq Data Range Atom A datatype name or a set of literals and a single argument representing a data value. Examples: xsd:int(?x) [3, 4, 5](?x)?x is a variable representing a data value. JPN, UiA 30

Ref.: https://github.com/protegeproject/swrlapi/wiki/swrllanguagefaq Built-In Atom SWRL support user-defined built-ins. A built-in is a predicate that takes one or more arguments and evaluates to true if the arguments satisfy the predicate. SWRL contained many built-ins. Example - Person with an age of greater than 17 is an adult is: : Person(?p) ^ hasage(?p,?age) ^ swrlb:greaterthan(?age, 17) -> Adult(?p) (swrlb is a namespace) JPN, UiA 31

Ref.: https://github.com/protegeproject/swrlapi/wiki/swrllanguagefaq A rule that uses a core SWRL string built-in to determine if a person's telephone number starts with the international access code "+" can be written as follows: Person(?p) ^ hasnumber(?p,?number) ^ swrlb:startswith(?number, "+") hasinternationalnumber(?p, true) JPN, UiA 32

Ref.: https://github.com/protegeproject/swrlapi/wiki/swrllanguagefaq Rectangle(?r) ^ haswidthinmeters(?r,?w) ^ hasheightinmeters(?r,?h) ^ swrlb:multiply(?areainsquaremeters,?w,?h) hasareainsquaremeters(?r,?areainsquaremeters) JPN, UiA 33

Agenda Different Types of Reasoning Inductive reasoning Deductive reasoning Abductive reasoning Why rules? The Semantic Web Rule Language (SWRL) SWRL Types of Atoms SWRL Example SWRL Exercise 34

DL and SWRL has a big overlap Example: If a person is the author of a book then she is a (member of the class) book author. First Order Predicate Logic: x.person(x) y.authorof(x,y) Book(y) Bookauthor(x) Description Logic: Person and authorof some Book SWRL: Person(?x) ^ authorof(?x,?y) ^Book(?y) -> BookAuthor(?x) JPN, UiA 35

Example in Protégé JPN, UiA 36

:authorof rdf:type owl:objectproperty. :Book rdf:type owl:class. :Person rdf:type owl:class. :BookAuthor rdf:type owl:class ; owl:equivalentclass [ owl:intersectionof ( :Person [ rdf:type owl:restriction ; owl:onproperty :authorof ; owl:somevaluesfrom :Book ] ) ; rdf:type owl:class ]. :adollshouse rdf:type owl:namedindividual, :Book. :ibsen rdf:type owl:namedindividual, :Person ; :authorof :adollshouse, :peergynt. Ontology Used :notanauthorperson rdf:type owl:namedindividual, :Person. :peergynt rdf:type owl:namedindividual, :Book. JPN, UiA 37

DL reasoner infer that ibsen is a book author JPN, UiA 38

Make SWRL rule in Protégé JPN, UiA 39

JPN, UiA 40

Transfer SWRL rule to rule engine After pressing JPN, UiA 41

Run SWRL rule JPN, UiA 42

See result of reasoning JPN, UiA 43

JPN, UiA 44 Result of SWRL reasoning

Agenda Different Types of Reasoning Inductive reasoning Deductive reasoning Abductive reasoning Why rules? The Semantic Web Rule Language (SWRL) SWRL Types of Atoms SWRL Example SWRL Exercise 45

@prefix : <http://www.uia.no/veggi#>. @prefix owl: <http://www.w3.org/2002/07/owl#>. @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>. @prefix xml: <http://www.w3.org/xml/1998/namespace>. @prefix xsd: <http://www.w3.org/2001/xmlschema#>. @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>. @base <http://www.uia.no/veggi>. <http://www.uia.no/veggi> rdf:type owl:ontology. ################################################################# # Object Properties ################################################################# ### http://www.uia.no/veggi#contains :contains rdf:type owl:objectproperty. ### http://www.uia.no/veggi#dislikes :dislikes rdf:type owl:objectproperty. ### http://www.uia.no/veggi#ordered :ordered rdf:type owl:objectproperty. ################################################################# # Classes ################################################################# ### http://www.uia.no/veggi#bakedsalmon :BakedSalmon rdf:type owl:class ; rdfs:subclassof :Dish, [ rdf:type owl:restriction ; owl:onproperty :contains ; owl:somevaluesfrom :SalmonProduct ]. ### http://www.uia.no/veggi#chickpeas :Chickpeas rdf:type owl:class ; rdfs:subclassof :VeggiProduct. ### http://www.uia.no/veggi#dish :Dish rdf:type owl:class. ### http://www.uia.no/veggi#falafel :Falafel rdf:type owl:class ; rdfs:subclassof :Dish, [ rdf:type owl:restriction ; owl:onproperty :contains ; owl:somevaluesfrom :Chickpeas ]. Exercise this ontology is given ### http://www.uia.no/veggi#fishproduct :FishProduct rdf:type owl:class ; rdfs:subclassof :Product. ### http://www.uia.no/veggi#person :Person rdf:type owl:class. ### http://www.uia.no/veggi#product :Product rdf:type owl:class. ### http://www.uia.no/veggi#salmonproduct :SalmonProduct rdf:type owl:class ; rdfs:subclassof :FishProduct. ### http://www.uia.no/veggi#unhappy :Unhappy rdf:type owl:class. ### http://www.uia.no/veggi#vegetarian :Vegetarian rdf:type owl:class. ### http://www.uia.no/veggi#veggiproduct :VeggiProduct rdf:type owl:class ; rdfs:subclassof :Product. ################################################################# # Individuals ################################################################# ### http://www.uia.no/veggi#chickpeas1 :chickpeas1 rdf:type owl:namedindividual, :Chickpeas. ### http://www.uia.no/veggi#dish1bakedsalmon :dish1bakedsalmon rdf:type owl:namedindividual, :BakedSalmon ; :contains :salmon1. ### http://www.uia.no/veggi#disk2bakedsalmon :disk2bakedsalmon rdf:type owl:namedindividual, :BakedSalmon ; :contains :salmon2. ### http://www.uia.no/veggi#disk3falafel :disk3falafel rdf:type owl:namedindividual, :Falafel ; :contains :chickpeas1. ### http://www.uia.no/veggi#janenotveggi :janenotveggi rdf:type owl:namedindividual, :Person ; :ordered :dish1bakedsalmon. ### http://www.uia.no/veggi#salmon1 :salmon1 rdf:type owl:namedindividual, :SalmonProduct. ### http://www.uia.no/veggi#salmon2 :salmon2 rdf:type owl:namedindividual, :SalmonProduct. ### http://www.uia.no/veggi#tomveggi :tomveggi rdf:type owl:namedindividual, :Person, :Vegetarian ; :ordered :disk2bakedsalmon, :disk3falafel. ### Generated by the OWL API (version 4.2.5.20160517-0735) https://github.com/owlcs/owlapi JPN, UiA 46

Ontology loaded into Protégé JPN, UiA 47

JPN, UiA 48

JPN, UiA 49

JPN, UiA 50

Even if no rule is specified the inference engine will still do some inferencing: JPN, UiA 51

Task 1: Every vegetarian dislikes all fish products. In effect all individuals of type Vegetarian will dislike all individuals of type FishProduct (and all its subclasses). E.g.: JPN, UiA 52

Task 1 Solution: (1) Every vegetarian dislikes all fish products. Vegetarian(?x) ^ FishProduct(?y) -> dislikes(?x,?y) JPN, UiA 53

Task 2: Anyone who ordered a dish that contains something he or she dislikes is unhappy. JPN, UiA 54

Task 2 solution: Anyone who ordered a dish that contains something he or she dislikes is unhappy. JPN, UiA 55

Task 3: Everything that can be ordered as a dish actually is a dish. Add the following to test: JPN, UiA 56

Task Solution 3: Everything that can be ordered as a dish actually is a dish. JPN, UiA 57

References Foundations of Semantic Web Technologies, Pascal Hitzler, Markus Krötzsch, Sebastian Rudolph, Chapman & Hall/CRC, 2009 http://www.powershow.com/view4/5a7f2a- OGRlM/SWRL_Semantic_Web_Rule_Language_powerpoint_ppt_presentation Help SWRL Protégé 5: https://github.com/protegeproject/swrlapi/wiki Jan Pettersen Nytun, UiA, page 58