Reasoning with Rules SWRL as Example Jan Pettersen Nytun, UIA 1 - - PowerPoint PPT Presentation

reasoning with rules
SMART_READER_LITE
LIVE PREVIEW

Reasoning with Rules SWRL as Example Jan Pettersen Nytun, UIA 1 - - PowerPoint PPT Presentation

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


slide-1
SLIDE 1

Reasoning with Rules

SWRL as Example

Jan Pettersen Nytun, UIA

1

slide-2
SLIDE 2

JPN, UiA 2

slide-3
SLIDE 3

What is a rule?

  • Consist of premise and a conclusion.
  • Meaning: In any situation where the premise

applies the conclusion must also hold.

JPN, UiA 3

premise  conclusion

slide-4
SLIDE 4

Agenda

4

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

slide-5
SLIDE 5

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. …

JPN, UiA 5

premise  conclusion

Not as strong as for deductive reasoning

slide-6
SLIDE 6

S O P

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

JPN, UiA 6

premise  conclusion

based on observations Likely to be true

slide-7
SLIDE 7

Inductive Reasoning Example

JPN, UiA 7

Many observations indicate that humans eventually dies, i.e., humans are mortals.

Human(x) Mortal(x)

slide-8
SLIDE 8

Deductive Reasoning

also Called Deductive Logic, Logical Deduction

  • 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

From Wikipedia, the free encyclopedia

slide-9
SLIDE 9

Deductive Reasoning Example

All men are mortal. Socrates is a man.

  • Therefore, Socrates is mortal.

JPN, UiA 9

slide-10
SLIDE 10

Deductive Reasoning Example in First Order Predicate Logic

All men are mortal. Socrates is a man.

  • Therefore, Socrates is mortal.

JPN, UiA 10

∀x.Man(x)  Mortal(x) -- All men are mortal Man(Socrates) -- Socrates is a man

  • Man(Socrates)  Mortal(Socrates). -- Socrates is mortal
slide-11
SLIDE 11

JPN, UiA 11

From Wikipedia, the free encyclopedia

slide-12
SLIDE 12

JPN, UiA 12

[https://explorable.com/inductive-reasoning]

Theories have to be tested and hypotheses answered before the scientific community accepts them as truth.

slide-13
SLIDE 13

Abductive Reasoning

JPN, UiA 13

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. 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.

From Wikipedia, the free encyclopedia

RaindLastNight GrassIsWeet SprinklerWasOn GrassIsWeet

slide-14
SLIDE 14
  • 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.

  • Can be used to develop a hypothesis, which in

turn can be tested by additional reasoning or data.

JPN, UiA 14

Abductive Reasoning Continues…

RaindLastNight GrassIsWeet SprinklerWasOn  GrassIsWeet

slide-15
SLIDE 15
  • 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

Abductive Reasoning Example

ref.: https://www.quora.com/What-is-a-good-example-of-abductive-reasoning

slide-16
SLIDE 16

Agenda

16

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

slide-17
SLIDE 17

JPN, UiA 17

In some cases we need both Structure and Rules

slide-18
SLIDE 18

Knowledge Representation, Part II, JPN, UiA 18

hasParent(?x,?parent) ∧ hasBrother(?parent,?uncle) ⇒ hasUncle(?x,?uncle)

Example of rule using The Semantic Web Rule Language (SWRL):

  • Some statements cannot

be expressed in OWL.

  • Modeling constructs of

OWL not always adequate or most desirable.

slide-19
SLIDE 19

Agenda

19

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

slide-20
SLIDE 20

JPN, UiA 20

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.

slide-21
SLIDE 21

JPN, UiA 21

atom ^ atom .... → atom ^ atom

SWRL Rule

head body body and head consist of positive conjunctions of atoms (only AND between atoms)

p(arg1, arg2, ... argn)

p is a predicate symbol; arg1, arg2, ..., argn are the terms of the expression.

Atom

Ref.: https://github.com/protegeproject/swrlapi/wiki/SWRLLanguageFAQ

slide-22
SLIDE 22

JPN, UiA 22

All variables in SWRL are treated as universally quantified (), with their scope limited to a given rule.

Ref.: https://github.com/protegeproject/swrlapi/wiki/SWRLLanguageFAQ hasParent(?x,?parent) ∧ hasBrother(?parent,?uncle) ⇒ hasUncle(?x,?uncle)

E.g., given: This rule applies for all ?x, all ?parent and all ?uncle.

slide-23
SLIDE 23

Agenda

23

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

slide-24
SLIDE 24

JPN, UiA 24

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

Ref.: https://github.com/protegeproject/swrlapi/wiki/SWRLLanguageFAQ

slide-25
SLIDE 25

JPN, UiA 25

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)

Ref.: https://github.com/protegeproject/swrlapi/wiki/SWRLLanguageFAQ

slide-26
SLIDE 26

JPN, UiA 26

(hasChild >= 1)(?x) -> Parent(?x) Example of Class Expression

slide-27
SLIDE 27

JPN, UiA 27

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)

Ref.: https://github.com/protegeproject/swrlapi/wiki/SWRLLanguageFAQ

slide-28
SLIDE 28

JPN, UiA 28

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)

Ref.: https://github.com/protegeproject/swrlapi/wiki/SWRLLanguageFAQ

slide-29
SLIDE 29

JPN, UiA 29

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)

Ref.: https://github.com/protegeproject/swrlapi/wiki/SWRLLanguageFAQ

slide-30
SLIDE 30

JPN, UiA 30

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.

Ref.: https://github.com/protegeproject/swrlapi/wiki/SWRLLanguageFAQ

slide-31
SLIDE 31

JPN, UiA 31

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)

slide-32
SLIDE 32

JPN, UiA 32

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)

Ref.: https://github.com/protegeproject/swrlapi/wiki/SWRLLanguageFAQ

slide-33
SLIDE 33

JPN, UiA 33

Rectangle(?r) ^ hasWidthInMeters(?r, ?w) ^ hasHeightInMeters(?r, ?h) ^ swrlb:multiply(?areaInSquareMeters, ?w, ?h)  hasAreaInSquareMeters(?r, ?areaInSquareMeters)

Ref.: https://github.com/protegeproject/swrlapi/wiki/SWRLLanguageFAQ

slide-34
SLIDE 34

Agenda

34

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

slide-35
SLIDE 35

JPN, UiA 35

Description Logic: Person and authorOf some Book

Example:

If a person is the author of a book then she is a (member of the class) book author.

DL and SWRL has a big overlap

First Order Predicate Logic: ∀x.Person(x) ∧ ∃y.authorOf(x,y) ∧ Book(y) →Bookauthor(x) SWRL: Person(?x) ^ authorOf(?x, ?y) ^Book(?y) -> BookAuthor(?x)

slide-36
SLIDE 36

JPN, UiA 36

Example in Protégé

slide-37
SLIDE 37

JPN, UiA 37

:authorOf rdf:type owl:ObjectProperty . :Book rdf:type owl:Class . :Person rdf:type owl:Class . :BookAuthor rdf:type owl:Class ;

  • wl:equivalentClass

[ owl:intersectionOf ( :Person [ rdf:type owl:Restriction ;

  • wl:onProperty :authorOf ;
  • wl:someValuesFrom :Book

] ) ; rdf:type owl:Class ] . :aDollsHouse rdf:type owl:NamedIndividual , :Book . :ibsen rdf:type owl:NamedIndividual , :Person ; :authorOf :aDollsHouse , :peerGynt . :notAnAuthorPerson rdf:type owl:NamedIndividual , :Person . :peerGynt rdf:type owl:NamedIndividual , :Book .

Ontology Used

slide-38
SLIDE 38

JPN, UiA 38

DL reasoner infer that ibsen is a book author

slide-39
SLIDE 39

JPN, UiA 39

Make SWRL rule in Protégé

slide-40
SLIDE 40

JPN, UiA 40

slide-41
SLIDE 41

JPN, UiA 41

Transfer SWRL rule to rule engine

After pressing

slide-42
SLIDE 42

JPN, UiA 42

Run SWRL rule

slide-43
SLIDE 43

JPN, UiA 43

See result of reasoning

slide-44
SLIDE 44

JPN, UiA 44

Result of SWRL reasoning

slide-45
SLIDE 45

Agenda

45

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

slide-46
SLIDE 46

JPN, UiA 46

Exercise this ontology is given

@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 ;
  • wl:onProperty :contains ;
  • wl: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 ;
  • wl:onProperty :contains ;
  • wl:someValuesFrom :Chickpeas
] . ### 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
slide-47
SLIDE 47

JPN, UiA 47

Ontology loaded into Protégé

slide-48
SLIDE 48

JPN, UiA 48

slide-49
SLIDE 49

JPN, UiA 49

slide-50
SLIDE 50

JPN, UiA 50

slide-51
SLIDE 51

JPN, UiA 51

Even if no rule is specified the inference engine will still do some inferencing:

slide-52
SLIDE 52

JPN, UiA 52

“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.:

Task 1:

slide-53
SLIDE 53

JPN, UiA 53

(1)“Every vegetarian dislikes all fish products.”

Vegetarian(?x) ^ FishProduct(?y) -> dislikes(?x, ?y)

Task 1 Solution:

slide-54
SLIDE 54

JPN, UiA 54

“Anyone who ordered a dish that contains something he

  • r she dislikes is unhappy.”

Task 2:

slide-55
SLIDE 55

JPN, UiA 55

“Anyone who ordered a dish that contains something he

  • r she dislikes is unhappy.”

Task 2 solution:

slide-56
SLIDE 56

JPN, UiA 56

“Everything that can be ordered as a dish actually is a dish.”

Task 3:

Add the following to test:

slide-57
SLIDE 57

JPN, UiA 57

“Everything that can be ordered as a dish actually is a dish.”

Task Solution 3:

slide-58
SLIDE 58

References

Jan Pettersen Nytun, UiA, page 58

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