580 likes | 599 Views
Delve into different types of reasoning - inductive, deductive, abductive- and explore the Semantic Web Rule Language (SWRL) through clear examples and exercises. Discover how rules form the basis of logical conclusions.
E N D
Reasoning with RulesSWRL as Example Jan Pettersen Nytun, UIA
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
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 Agenda
Inductive ReasoningFrom 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
Inductive ReasoningFrom 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
Inductive Reasoning Example Many observations indicate that humans eventually dies, i.e., humans are mortals. Human(x) Mortal(x) JPN, UiA
Deductive Reasoningalso 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
Deductive Reasoning Example All men are mortal. Socrates is a man. ------------------------------ Therefore, Socrates is mortal. JPN, UiA
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
[https://explorable.com/inductive-reasoning] Theories have to be tested and hypotheses answered before the scientific community accepts them as truth. JPN, UiA
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. 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 SprinklerWasOnGrassIsWeet JPN, UiA
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
Abductive Reasoning Exampleref.: 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
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 Agenda
Example of rule using TheSemantic 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
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 Agenda
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
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) • pis a predicate symbol; arg1, arg2, ..., argn are the terms of the expression. JPN, UiA
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
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 Agenda
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
Ref.: https://github.com/protegeproject/swrlapi/wiki/SWRLLanguageFAQ Class AtomOWL named class or class expression and a single argument representing an OWL individual Examples: Person(?p) Man(Fred) Man(?p) -> Person(?p) JPN, UiA
Example of Class Expression (hasChild >= 1)(?x) -> Parent(?x) JPN, UiA
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
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
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
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
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
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
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
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 Agenda
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 andauthorOfsome Book SWRL: Person(?x) ^ authorOf(?x, ?y) ^Book(?y) -> BookAuthor(?x) JPN, UiA
Examplein Protégé JPN, UiA
:authorOfrdf:typeowl:ObjectProperty . :Book rdf:typeowl:Class . :Person rdf:typeowl:Class . :BookAuthorrdf:typeowl:Class ; owl:equivalentClass [ owl:intersectionOf ( :Person [ rdf:typeowl:Restriction ; owl:onProperty :authorOf ; owl:someValuesFrom :Book ] ) ; rdf:typeowl:Class ] . :aDollsHouserdf:typeowl:NamedIndividual , :Book . :ibsenrdf:typeowl:NamedIndividual , :Person ; :authorOf :aDollsHouse , :peerGynt . :notAnAuthorPersonrdf:typeowl:NamedIndividual , :Person . :peerGyntrdf:typeowl:NamedIndividual , :Book . Ontology Used JPN, UiA
Make SWRL rule in Protégé JPN, UiA
Transfer SWRL rule to rule engine Afterpressing JPN, UiA
Run SWRL rule JPN, UiA
See result of reasoning JPN, UiA
Result of SWRL reasoning JPN, UiA
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 Agenda
@prefix : <http://www.uia.no/veggi#> . @prefixowl: <http://www.w3.org/2002/07/owl#> . @prefixrdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . @prefixxml: <http://www.w3.org/XML/1998/namespace> . @prefixxsd: <http://www.w3.org/2001/XMLSchema#> . @prefixrdfs: <http://www.w3.org/2000/01/rdf-schema#> . @base <http://www.uia.no/veggi> . <http://www.uia.no/veggi> rdf:typeowl:Ontology . ################################################################# # Object Properties ################################################################# ### http://www.uia.no/veggi#contains :containsrdf:typeowl:ObjectProperty . ### http://www.uia.no/veggi#dislikes :dislikesrdf:typeowl:ObjectProperty . ### http://www.uia.no/veggi#ordered :orderedrdf:typeowl:ObjectProperty . ################################################################# # Classes ################################################################# ### http://www.uia.no/veggi#BakedSalmon :BakedSalmonrdf:typeowl:Class ; rdfs:subClassOf :Dish , [ rdf:typeowl:Restriction ; owl:onProperty :contains ; owl:someValuesFrom :SalmonProduct ] . ### http://www.uia.no/veggi#Chickpeas :Chickpeasrdf:typeowl:Class ; rdfs:subClassOf :VeggiProduct . ### http://www.uia.no/veggi#Dish :Dishrdf:typeowl:Class . ### http://www.uia.no/veggi#Falafel :Falafelrdf:typeowl:Class ; rdfs:subClassOf :Dish , [ rdf:typeowl:Restriction ; owl:onProperty :contains ; owl:someValuesFrom :Chickpeas ] . ### http://www.uia.no/veggi#FishProduct :FishProductrdf:typeowl:Class ; rdfs:subClassOf :Product . ### http://www.uia.no/veggi#Person :Person rdf:typeowl:Class . ### http://www.uia.no/veggi#Product :Product rdf:typeowl:Class . ### http://www.uia.no/veggi#SalmonProduct :SalmonProductrdf:typeowl:Class ; rdfs:subClassOf :FishProduct . ### http://www.uia.no/veggi#Unhappy :Unhappyrdf:typeowl:Class . ### http://www.uia.no/veggi#Vegetarian :Vegetarianrdf:typeowl:Class . ### http://www.uia.no/veggi#VeggiProduct :VeggiProductrdf:typeowl:Class ; rdfs:subClassOf :Product . ################################################################# # Individuals ################################################################# ### http://www.uia.no/veggi#chickpeas1 :chickpeas1 rdf:typeowl:NamedIndividual , :Chickpeas . ### http://www.uia.no/veggi#dish1BakedSalmon :dish1BakedSalmon rdf:typeowl:NamedIndividual , :BakedSalmon ; :contains :salmon1 . ### http://www.uia.no/veggi#disk2BakedSalmon :disk2BakedSalmon rdf:typeowl:NamedIndividual , :BakedSalmon ; :contains :salmon2 . ### http://www.uia.no/veggi#disk3Falafel :disk3Falafel rdf:typeowl:NamedIndividual , :Falafel ; :contains :chickpeas1 . ### http://www.uia.no/veggi#janeNotVeggi :janeNotVeggirdf:typeowl:NamedIndividual , :Person ; :ordered :dish1BakedSalmon . ### http://www.uia.no/veggi#salmon1 :salmon1 rdf:typeowl:NamedIndividual , :SalmonProduct . ### http://www.uia.no/veggi#salmon2 :salmon2 rdf:typeowl:NamedIndividual , :SalmonProduct . ### http://www.uia.no/veggi#tomVeggi :tomVeggirdf:typeowl:NamedIndividual , :Person , :Vegetarian ; :ordered :disk2BakedSalmon , :disk3Falafel . ### Generated by the OWL API (version 4.2.5.20160517-0735) https://github.com/owlcs/owlapi Exercise this ontology is given JPN, UiA
Ontology loaded into Protégé JPN, UiA