Download presentation
Presentation is loading. Please wait.
1
Reasoning with Rules SWRL as Example
Jan Pettersen Nytun, UIA
2
JPN, UiA
3
premise conclusion 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
4
Agenda Different Types of Reasoning Why rules?
Inductive reasoning Deductive reasoning Abductive reasoning Why rules? The Semantic Web Rule Language (SWRL) SWRL Types of Atoms SWRL Example SWRL Exercise
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. … premise conclusion Not as strong as for deductive reasoning JPN, UiA
6
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
7
Inductive Reasoning Example
Many observations indicate that humans eventually dies, i.e., humans are mortals. Human(x) Mortal(x) JPN, UiA
8
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
9
Deductive Reasoning Example
All men are mortal. Socrates is a man Therefore, Socrates is mortal. JPN, UiA
10
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
11
From Wikipedia, the free encyclopedia
JPN, UiA
12
[https://explorable.com/inductive-reasoning]
Theories have to be tested and hypotheses answered before the scientific community accepts them as truth. JPN, UiA
13
Abductive Reasoning RaindLastNight GrassIsWeet
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. 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. RaindLastNight GrassIsWeet SprinklerWasOn GrassIsWeet JPN, UiA
14
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. Can be used to develop a hypothesis, which in turn can be tested by additional reasoning or data. RaindLastNight GrassIsWeet SprinklerWasOn GrassIsWeet JPN, UiA
15
Abductive Reasoning Example ref. : https://www. quora
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
16
Agenda Different Types of Reasoning Why rules?
Inductive reasoning Deductive reasoning Abductive reasoning Why rules? The Semantic Web Rule Language (SWRL) SWRL Types of Atoms SWRL Example SWRL Exercise
17
In some cases we need both Structure and Rules
JPN, UiA
18
Knowledge Representation, Part II, JPN, UiA
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
19
Agenda Different Types of Reasoning Why rules?
Inductive reasoning Deductive reasoning Abductive reasoning Why rules? The Semantic Web Rule Language (SWRL) SWRL Types of Atoms SWRL Example SWRL Exercise
20
The Semantic Web Rule Language (SWRL)
Ref.: 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
21
SWRL Rule Atom p(arg1, arg2, ... argn) head body
Ref.: 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
22
This rule applies for all ?x, all ?parent and all ?uncle.
Ref.: 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
23
Agenda Different Types of Reasoning Why rules?
Inductive reasoning Deductive reasoning Abductive reasoning Why rules? The Semantic Web Rule Language (SWRL) SWRL Types of Atoms SWRL Example SWRL Exercise
24
SWRL provides seven types of atoms:
Ref.: 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
25
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
26
Example of Class Expression
(hasChild >= 1)(?x) -> Parent(?x) JPN, UiA
27
Individual Property Atom
Ref.: 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
28
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
29
Different Individuals Atom
Ref.: 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
30
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
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) JPN, UiA
32
Person(?p) ^ hasNumber(?p, ?number) ^ swrlb:startsWith(?number, "+")
Ref.: 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
33
hasWidthInMeters(?r, ?w) ^ hasHeightInMeters(?r, ?h) ^
Ref.: Rectangle(?r) ^ hasWidthInMeters(?r, ?w) ^ hasHeightInMeters(?r, ?h) ^ swrlb:multiply(?areaInSquareMeters, ?w, ?h) hasAreaInSquareMeters(?r, ?areaInSquareMeters) JPN, UiA
34
Agenda Different Types of Reasoning Why rules?
Inductive reasoning Deductive reasoning Abductive reasoning Why rules? The Semantic Web Rule Language (SWRL) SWRL Types of Atoms SWRL Example SWRL Exercise
35
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
36
Example in Protégé JPN, UiA
37
Ontology Used :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 . :notAnAuthorPerson rdf:type owl:NamedIndividual , :Person . :peerGynt rdf:type owl:NamedIndividual , :Book . Ontology Used JPN, UiA
38
DL reasoner infer that ibsen is a book author
JPN, UiA
39
Make SWRL rule in Protégé
JPN, UiA
40
JPN, UiA
41
Transfer SWRL rule to rule engine
After pressing JPN, UiA
42
Run SWRL rule JPN, UiA
43
See result of reasoning
JPN, UiA
44
Result of SWRL reasoning
JPN, UiA
45
Agenda Different Types of Reasoning Why rules?
Inductive reasoning Deductive reasoning Abductive reasoning Why rules? The Semantic Web Rule Language (SWRL) SWRL Types of Atoms SWRL Example SWRL Exercise
46
Exercise this ontology is given
@prefix : < . @prefix owl: < . @prefix xsd: < . @prefix xml: < . @prefix rdf: < . @base < . @prefix rdfs: < . < rdf:type owl:Ontology . # Object Properties ################################################################# :contains rdf:type owl:ObjectProperty . ### :dislikes rdf:type owl:ObjectProperty . ### :ordered rdf:type owl:ObjectProperty . ### # Classes ### [ rdf:type owl:Restriction ; rdfs:subClassOf :Dish , :BakedSalmon rdf:type owl:Class ; ] . owl:someValuesFrom :SalmonProduct owl:onProperty :contains ; :Chickpeas rdf:type owl:Class ; ### rdfs:subClassOf :VeggiProduct . :Dish rdf:type owl:Class . ### :Falafel rdf:type owl:Class ; ### owl:someValuesFrom :Chickpeas rdfs:subClassOf :Product . :FishProduct rdf:type owl:Class ; ### :Person rdf:type owl:Class . ### ### :Product rdf:type owl:Class . :SalmonProduct rdf:type owl:Class ; ### rdfs:subClassOf :FishProduct . :Unhappy rdf:type owl:Class . ### :Vegetarian rdf:type owl:Class . ### :VeggiProduct rdf:type owl:Class ; ### # Individuals :Chickpeas . :chickpeas1 rdf:type owl:NamedIndividual , ### :dish1BakedSalmon rdf:type owl:NamedIndividual , ### :contains :salmon1 . :BakedSalmon ; :disk2BakedSalmon rdf:type owl:NamedIndividual , ### :contains :salmon2 . :disk3Falafel rdf:type owl:NamedIndividual , ### :Falafel ; :contains :chickpeas1 . :Person ; :janeNotVeggi rdf:type owl:NamedIndividual , ### :ordered :dish1BakedSalmon . ### :SalmonProduct . :salmon1 rdf:type owl:NamedIndividual , :salmon2 rdf:type owl:NamedIndividual , ### :Person , :tomVeggi rdf:type owl:NamedIndividual , ### :disk3Falafel . :ordered :disk2BakedSalmon , :Vegetarian ; ### Generated by the OWL API (version ) Exercise this ontology is given JPN, UiA
47
Ontology loaded into Protégé
JPN, UiA
48
JPN, UiA
49
JPN, UiA
50
JPN, UiA
51
Even if no rule is specified the inference engine will still do some inferencing:
JPN, UiA
52
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
53
Task 1 Solution: “Every vegetarian dislikes all fish products.”
Vegetarian(?x) ^ FishProduct(?y) -> dislikes(?x, ?y) JPN, UiA
54
Task 2: “Anyone who ordered a dish that contains something he or she dislikes is unhappy.” JPN, UiA
55
Task 2 solution: “Anyone who ordered a dish that contains something he or she dislikes is unhappy.” JPN, UiA
56
Task 3: “Everything that can be ordered as a dish actually is a dish.”
Add the following to test: JPN, UiA
57
Task Solution 3: “Everything that can be ordered as a dish actually is a dish.” JPN, UiA
58
References Foundations of Semantic Web Technologies, Pascal Hitzler, Markus Krötzsch, Sebastian Rudolph, Chapman & Hall/CRC, 2009 Help SWRL Protégé 5:
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.