Logic and Rules
description
Transcript of Logic and Rules
Most material was taken from the following source:
– Grigoris Antoniou, Frank van Harmelen, A Semantic Web Primer, 2nd Edition, MIT Press, 2008, ISBN 978-0-262-01242-3.
Logic and Rules
Logic and Rules
Lecture Outline
1. Introduction2. Rules: Example3. Rules: Syntax & Semantics4. RuleML & RIF: XML Representation for
Rules5. Rules & Ontologies: OWL 2 RL & SWRL
6-2
Logic and Rules
Knowledge Representation
The subjects presented so far were related to the representation of knowledge
Knowledge Representation was studied long before the emergence of WWW in AI
Logic is still the foundation of KR, particularly in the form of predicate logic (first-order logic)
6-3
Logic and Rules
The Importance of Logic
High-level language for expressing knowledge High expressive power Well-understood formal semantics Precise notion of logical consequence Proof systems that can automatically derive
statements syntactically from a set of premises
6-4
Logic and Rules
The Importance of Logic (2)
There exist proof systems for which semantic logical consequence coincides with syntactic derivation within the proof system – Soundness & completeness
Soundness: whatever the proof system derives, is also true in the logic semantics
Completeness: whatever is true in the logic semantics, can be derived by the proof system
6-5
Logic and Rules
The Importance of Logic (3)
Predicate logic is unique in the sense that sound and complete proof systems do exist. – Not for more expressive logics (higher-order
logics) Logic can trace the proof that leads to a
logical consequence. Logic can provide explanations for answers
– By tracing a proof
6-6
Logic and Rules
Specializations of Predicate Logic:RDF and OWL
RDF/S and OWL (Lite and DL) are specializations of predicate logic– correspond roughly to a description logic
They define reasonable subsets of logic Trade-off between the expressive power and
the computational complexity: – The more expressive the language, the less efficient
the corresponding proof systems
6-7
Logic and Rules
Specializations of Predicate Logic:Horn Logic
A rule has the form: A1, . . ., An B– Ai and B are atomic formulas
There are 2 ways of reading such a rule:– Deductive rules: If A1,..., An are known to
be true, then B is also true– Reactive rules: If the conditions A1,..., An
are true, then carry out the action B
6-8
Logic and Rules
Description Logics vs. Horn Logic
Neither of them is a subset of the other It is impossible to assert that persons who study and
live in the same city are “home students” in OWL– This can be done easily using rules:
studies(X,Y), lives(X,Z), loc(Y,U), loc(Z,U) homeStudent(X)
Rules cannot assert the information that a person is either a man or a woman– This information is easily expressed in OWL using disjoint
union
6-9
Horn logic vs. Description logics
6-10
FOLHorn LogicDescription logics
Logic and Rules
Logic and Rules
Exchange of Rules
Exchange of rules across different applications– E.g., an online store advertises its pricing, refund,
and privacy policies, expressed using rules The Semantic Web approach is to express the
knowledge in a machine-accessible way using one of the Web languages we have already discussed
We show how rules can be expressed in XML-like languages (“rule markup languages”)
6-11
Logic and Rules
Lecture Outline
1. Introduction2. Rules: Example3. Rules: Syntax & Semantics4. RuleML & RIF: XML Representation for
Rules5. Rules & Ontologies: OWL 2 RL & SWRL
6-12
Logic and Rules
Family Relations
Facts in a database about relations:– mother(X,Y), X is the mother of Y– father(X,Y), X is the father of Y– male(X), X is male– female(X), X is female
Inferred relation parent: A parent is either a father or a mother
mother(X,Y) parent(X,Y)father(X,Y) parent(X,Y)
6-13
Logic and Rules
Inferred Relations
male(X), parent(P,X), parent(P,Y), notSame(X,Y) brother(X,Y)
female(X), parent(P,X), parent(P,Y), notSame(X,Y) sister(X,Y)
brother(X,P), parent(P,Y) uncle(X,Y) mother(X,P), parent(P,Y) grandmother(X,Y) parent(X,Y) ancestor(X,Y) ancestor(X,P), parent(P,Y) ancestor(X,Y)
6-14
Logic and Rules
Lecture Outline
1. Introduction2. Rules: Example3. Rules: Syntax & Semantics4. RuleML & RIF: XML Representation for
Rules
6-15
Logic and Rules
Rules – Syntax
loyalCustomer(X), age(X,Y), Y>60 discount(X)
We distinguish some ingredients of rules:– variables which are placeholders for values: X– constants denote fixed values: 60– Predicates relate objects: loyalCustomer, >
6-16
Logic and Rules
Rules
B1, . . . , Bn A A, B1, ... , Bn are atomic formulas A is the head of the rule B1, ... , Bn are the premises (body of the rule) The commas in the rule body are read conjunctively Variables may occur in A, B1, ... , Bn
– loyalCustomer(X), age(X,Y), Y>60 discount(X)– Variables are implicitly universally quantified ()
6-17
Logic and Rules
Facts and Logic Programs
A fact is an atomic formula E.g. loyalCustomer(a345678) A logic program P is a finite set of facts and rules.
6-18
Logic and Rules
Goals
A goal denotes a query G asked to a logic program
The form: – B1, . . . , Bn OR– ?- B1, . . . , Bn. (as in Prolog)
6-19
Can you prove that B1 AND . . . AND Bn is true given the logic program P?
Logic and Rules
Proof Procedure
We use a proof technique from mathematics called proof by contradiction: – Prove that A follows from B by assuming that A is false and
deriving a contradiction, when combined with B
In logic programming we prove that a goal can be answered positively by negating the goal and proving that we get a contradiction using the logic program– E.g., given the following logic program we get a logical
contradiction
6-20
Logic and Rules
An Example
p(a)¬X p(X)
The 2nd formula says that no element has the property p
The 1st formula says that the value of a does have the property p
Thus X p(X) follows from p(a)6-21
contradiction
Logic and Rules
First-Order Interpretation of Goals
p(a)p(X) q(X) q(X)
q(a) follows from the logical program X q(X) follows from the logical program Thus, “logical program”{¬ Xq(X)} is
unsatisfiable, and we give a positive answer
6-22
Logic and Rules
First-Order Interpretation of Goals (2)
p(a)p(X) q(X)q(b)
We must give a negative answer because q(b) does not follow from the logical program
6-23
Logic and Rules
Lecture Outline
1. Introduction2. Rules: Example3. Rules: Syntax & Semantics4. RuleML & RIF: XML Representation for
Rules5. Rules & Ontologies: OWL 2 RL & SWRL
6-24
Logic and Rules
Rule Markup Language (RuleML) RuleML: effort to develop markup of rules on the web A family of rule languages, corresponding to different
kinds of rule languages: – derivation rules, integrity constraints, reaction rules, …
The kernel of the RuleML family is Datalog– function-free Horn logic
RuleML is experimental – studies various features of rule languages that are far from
being standardized (e.g. nonmonotonic rules)– These efforts may feed into future standards– RuleML results were important in the development of RIF6-25
Logic and Rules
<Implies><then>
<Atom><Rel>discount</Rel><Var>customer</Var><Var>product</Var><Ind>7.5 percent</Ind>
</Atom></then><if>
<And><Atom>
<Rel>premium</Rel>
<Var>customer</Var>
</Atom><Atom>
<Rel>luxury</Rel><Var>product</
Var></Atom>
</And></if>
</Implies>
The discount for a customer buying a product is 7.5% if the customer is premium and the product is luxury
6-26
premium(?customer), luxury(?product) discount(?customer,?product,7.5)
Logic and Rules
Rule Interchange Format: RIF
Rule technology exhibits a broad variety – e.g. action rules, first order rules, logic programming
The aim of the W3C RIF Working Group – not to develop a new rule language that would fit all purposes, – focus on the interchange among the various Web rules – A family of languages, called dialects (2 kinds)
Logic-based dialects. Based on some form of logic– e.g. first-order logic, and various logic programming approaches – RIF Core, essentially corresponding to function-free Horn logic– RIF Basic Logic Dialect (BLD), Horn logic with equality.
Rules with actions (Production systems and reactive rules)– Production Rule Dialect (RIF-PRD).
6-27
Logic and Rules
RIF-BLD
Corresponds to Horn logic with equality plus– Data types and built ins, and– Frames (something like objects in OO programming)
Data Types– integer, boolean, string, date,
“Built-in” Predicates – numeric-greater-than, startswith, date-less-than
Functions – numeric-subtract, replace, hours-fromtime
6-28
Logic and Rules
An actor is a movie star if he has starred in more than 3 successful movies, produced in a span of at least 5 years.
A film is considered successful if it has received critical acclaim (e.g. rating >8) or was financially successful (produced >$100M in ticket sales).
These rules should be evaluated against the DBpedia data set.6-29
Logic and Rules
Compatibility with RDF and OWL
The basic idea of combining RIF with RDF is to represent RDF triples using RIF frame formulas
A triple s p o is represented as s[p -> o] Exampleex:GoneWithTheWind ex:FilmYear ex:1939ex:GoneWithTheWind[ex:FilmYear -> ex:1939]
6-30
Logic and Rules
Lecture Outline
1. Introduction2. Rules: Example3. Rules: Syntax & Semantics4. RuleML & RIF: XML Representation for
Rules5. Rules & Ontologies: OWL 2 RL & SWRL
6-31
Horn logic vs. Description logics
Horn logic (rules) and description logics (ontologies) are orthogonal– Both are subsets of first-order logic (FOL)– Neither is the subset of each other
6-32
FOLHorn LogicDescription logics
OWL 2 RL
SWRL
Description Logic Programs (DLP)OWL2 RL The simplest integration approach is the intersection
of both logics – The part of one language that can be translated in a
semantics-preserving way to the other OWL2 RL capture this fragment of OWL (previously
called Description Logic Programs - DLP)– Horn-definable part of OWL, or – OWL-definable part of Horn logic
6-33 Logic and Rules
Logic and Rules
OWL 2 RL
OWL 2 is based on Description Logic. – A fragment of first-order logic– Inherits open-world assumption and non-unique-
name assumption OWL 2 RL is an interesting sublanguage of
OWL 2 DL – Above assumptions do not make a difference
6-34
Logic and Rules
Open-World Assumption (OWA)
We cannot conclude some statement x to be false simply because we cannot show x to be true.
The opposite assumption (closed world, CWA) would allow deriving falsity from the inability to derive truth.
OWL is strictly committed to the OWA– In some applications is not the right choice
6-35
Logic and Rules
OWA vs. CWAExamples
Example in favor of OWA– Question: “Did it rain in Tokyo yesterday?”– Answer: “I don’t know that it rained, but that’s not
enough reason to conclude that it didn’t rain.” Example in favor of CWA
– Question: “Was there a big earthquake disaster in Tokyo yesterday?”
– Answer: “I don’t know, but if there had been such a disaster, I’d have heard about it. Therefore I conclude that there wasn’t such a disaster.”
6-36
Logic and Rules
Unique-Name Αssumption (UNA)
When two individuals are known by different names, they are in fact different individuals. – Sometimes works well and sometimes not
In favor: when two products in a catalog are known by different codes, they are different
Against: two people in our social environment initially known with different identifiers (e.g., “Prof. van Harmelen” and “Frank”) are sometimes the same person
6-37
Logic and Rules
Unique-Name Αssumption (UNA)
OWL does not make the unique-name assumption
It is possible to explicitly assert of a set of identifiers that they are all unique – using owl:allDifferent
6-38
Logic and Rules
CWA vs. OWA
Databases and logic-programming systems support closed worlds and unique names
Knowledge representation systems and theorem provers support open worlds and non-unique names
Ontologies are sometimes in need of one and sometimes in need of the other.– Big debate in the literature
6-39
Logic and Rules
OWL 2 RL
Debate resolved by OWL 2 RL The largest fragment of OWL 2 on which the
choice for CWA and UNA does not matter– OWL 2 RL is weak enough so that the differences
between the choices don’t show up. – Still large enough to enable useful representation
and reasoning tasks.
6-40
Logic and Rules
OWL 2 RL Advantages (1/2)
Applications that wish to make different choices on these assumptions (CWA, UNA, etc) can still exchange ontologies in OWL 2 RL without harm.
Outside OWL 2 RL, they will draw different conclusions from the same statements. – They disagree on the semantics.
6-41
Logic and Rules
OWL 2 RL Advantages (2/2)
Freedom to use either OWL 2 or rules (and associated tools and methodologies) for modeling purposes
Description logic reasoners or deductive rule systems can be used for implementation. – Extra flexibility - interoperability with tools
Preliminary experience with using OWL 2 has shown that existing ontologies frequently use very few constructs outside the OWL 2 RL language.
6-42
Logic and Rules
OWL 2 RL constructs
Which constructs of RDF Schema and OWL 2 can be expressed in Horn logic?– They lie within the expressive power of DLP
Some constructs cannot be expressed
6-43
Logic and Rules
Allowed OWL constructors
Class and property equivalence Equality- inequality between individuals Inverse, transitive, symmetric and functional
properties Intersection of classes Excluded constructors
– Union, existential quantification, and arbitrary cardinality constraints
6-44
Logic and Rules
Simple RDF constructs
A triple (a, P, b) is expressed as a fact P(a, b) An instance declaration type(a,C),
– a is an instance of class C– expressed as C(a)
C is a subclass of DC(X) → D(X)
Similarly for subpropertyP(X,Y) → Q(X,Y)
6-45
Logic and Rules
More RDF Constructs
Domain and Range Restrictions – C is the domain of property P
P(X, Y) → C(X)– C’ is the range of property P
P(X, Y) → C’(Y)
6-46
Logic and Rules
OWL Constructs
equivalentClass(C,D) – pair of rules
C(X) → D(X)D(X) → C(X)
Similarly for equivalentProperty(P,Q)P(X,Y) → Q(X,Y)Q(X,Y) → P(X,Y)
6-47
Logic and Rules
More OWL Constructs
Transitive PropertiesP(X,Y), P(Y,Z) → P(X,Z)
Boolean operators. – The intersection of C1 and C2 is a subclass of D
C1(X), C2(X) → D(X)– C is a subclass of the intersection of D1 and D2
C(X) → D1(X) C(X) → D2(X)
6-48
Logic and Rules
Union
The union of C1 and C2 is a subclass of DC1(X) → D(X) C2(X) → D(X)
The opposite direction is outside the expressive power of Horn logic. – To express that C is a subclass of the union of D1
and D2 would require a disjunction in the head of the corresponding rule
– C(X) → D1(X) D2(X)
6-49
Logic and Rules
OWL Restrictions allValuesFrom
allValuesFrom(P,D)– the anonymous class of all x such that y must be an
instance of D whenever P(x, y) C subClassOf allValuesFrom(P,D)
– Necessary restrictionC(X), P(X, Y) → D(Y)
– “Local” range constraint: P(X,Y) → D(Y) The opposite direction cannot in general be
expressed6-50
Logic and Rules
OWL Restrictions someValuesFrom
someValuesFrom(P,D) – the anonymous class of all x for which there exists
at least one y instance of D, such that P(x, y). someValuesFrom(P,D) subClassOf C
– Sufficient restriction / Classification ruleP(X,Y), D(Y) → C(X)
The opposite direction cannot in general be expressed.
6-51
Logic and Rules
Non-expressible constructs
Cannot be expressed in Horn logic in the general case– Cardinality constraints – Complement of classes
6-52
Logic and Rules
OWL 2 RL – Conclusions
Allowed constructors allow useful expressivity for many practical cases
Guarantees correct interchange between OWL reasoners independent of CWA and UNA
Allows for translation into efficiently implementable reasoning techniques based on databases and logic programs
6-53
Logic and Rules
Semantic Web Rules Language (SWRL)
A proposed Semantic Web language combining OWL 2 DL with function-free Horn logic, written in Datalog RuleML
It allows Horn-like rules to be combined with OWL 2 DL ontologies.
6-54
Logic and Rules
Rules in SWRL
B1, …,Bn → A1, …,Am
– commas denote conjunction on both sides of the arrow
A1, …,Am ,B1, …,Bn can be – C(x), P(x, y), sameAs(x, y), differentFrom(x,y), – C is an OWL description, P is an OWL property, – x, y are Datalog variables, OWL individuals, or
OWL data values.
6-55
Logic and Rules
Rule Heads
If the head of a rule has more than one atom the rule can be transformed to an equivalent set of rules with one atom in the head in a straightforward way– conjunction of atoms without shared variables
A(X,Y)→ B(X),C(Y)– A(X,Y)→ B(X)– A(X,Y)→ C(Y)
6-56
Logic and Rules
Complexity of SWRL
Arbitrary OWL expressions (e.g. restrictions), can appear in the head or body of a rule.
This adds significant expressive power to OWL, but at the high price of undecidability
There can be no inference engine that draws exactly the same conclusions as the SWRL semantics.
6-57
Logic and Rules
SWRL vs. OWL 2 RL
OWL 2 RL tries to combine the advantages of both languages in their common sublanguage
SWRL takes a more maximalist approach and unites their respective expressivities.
The challenge is to identify sublanguages of SWRL that find the right balance between expressive power and computational tractability. – A candidate is the extension of OWL DL with DL-safe rules– Every variable must appear in a non-description logic atom in the rule
body
6-58
Logic and Rules
Example SWRL Rules: Reclassification
Man(?m) → Person(?m)– Possible in OWL - subclassOf relation– Some rules are OWL syntactic sugar
Person(?m) hasSex(?m,male) → Man(?m)– Possible in OWL – hasValue (sufficient) restriction– Not all such reclassifications are possible in OWL
Man(?m) works_at(?m,?j) hasWife(?m,?w) works_at(?w,?j) → LuckyMan(?m)
6-59
Logic and Rules
Example SWRL Rules: Property Value Assignment
hasParent(?x, ?y) hasBrother(?y, ?z)→ hasUncle(?x, ?z)
– Property chaining– Possible in OWL 2 - Not possible in OWL 1.0
Person(?p) hasSibling(?p,?s) Man(?s)→ hasBrother(?p,?s)
– Not possible in OWL
6-60
Logic and Rules
Example SWRL Rules: Built-ins
Person(?p) hasAge(?p,?age) swrlb:greaterThan(?age,17)
→ Adult(?p)
Built-ins dramatically increase expressivity – most rules are not expressible in OWL 1– Some built-ins can be expressed in OWL 2
6-61
Logic and Rules
Example SWRL Rules:String Built-ins
Person(?p) hasNumber(?p, ?number)
swrlb:startsWith(?number, "+")
→ hasInternationalNumber(?p, true)
6-62
Logic and Rules
Example SWRL Rules: Built-ins / Argument Binding
Person(?p) hasSalaryInPounds(?p, ?pounds)
swrlb:multiply(?dollars, ?pounds, 2.0)
→ hasSalaryInDollars(?p, ?dollars)
6-63
Logic and Rules
SWRLTab Built-in Librarieshttp://protege.cim3.net/cgi-bin/wiki.pl?SWRLTabBuiltInLibraries
6-64
Logic and Rules
SWRL and Open World Semantics:sameAs, differentFrom
Publication(?p) hasAuthor(?p, ?y) hasAuthor(?p, ?z) differentFrom(?y, ?z)
→ cooperatedWith(?y, ?z)
Like OWL, SWRL does not adopt the unique name assumption– Individuals must also be explicitly stated to be
different (using owl:allDifferents restriction)
6-65
Logic and Rules
SWRL is Monotonic: does not Support Negated Atoms
Person(?p) not hasCar(?p, ?c) → CarlessPerson(?p)
Not possible - language does not support negation here
Potential invalidation - what if a person later gets a car?
6-66
Logic and Rules
SWRL is Monotonic: retraction (or modification) not supported
Person(?p) hasAge(?p,?age) swrlb:add(?newage, ?age,1)
→ hasAge(?p, ?newage) Incorrect:
– will run forever and attempt to assign an infinite number of values to hasAge property
There is no retraction of old value– Even if there was, it would run forever
6-67
Logic and Rules
SWRL is Monotonic: counting not supported
Publication(?p) hasAuthor(?p,?a) <has exactly one hasAuthor value in current ontology>→ SingleAuthorPublication(?p)
Not expressible - open world applies Potential invalidation - what if author is
added later?
6-68
SQWRL (Semantic Query-Enhanced Web Rule Language)
Counting and other aggregation operations can be performed by SQWRL
SQWRL (pronounced squirrel) is a SWRL-based language for querying OWL ontologies.
It provides SQL-like operations to retrieve knowledge from OWL.
Book(?x) has-author(?x, ?y) ∧ ∧ sqwrl:makeBag(?x, ?y) sqwrl:count(?y, ?c) ∧ → sqwrl:select(?x, ?c)
6-69 Logic and Rules
Semantics of SQWRL
SQWRL queries operate on known individuals in the currently loaded OWL ontology.
SQWRL provides no way of accessing the information it accumulates from within a rule – Query results cannot be written back to the ontology– Such a mechanism could invalidate OWL's open
world assumption and lead to nonmonotonicity Unlike OWL and SWRL, SQWRL adopts the
unique name assumption when querying.6-70 Logic and Rules
Logic and Rules
SWRLTab
A Protégé-OWL development environment for working with SWRL rules
Supports editing and execution of rules Extension mechanisms to work with third-party
rule engines Mechanisms for users to define built-in method
libraries Supports querying of ontologies
6-71
Logic and Rules
SWRLTab Wiki : http://protege.cim3.net/cgi-bin/wiki.pl?SWRLTab
6-72
Logic and Rules
What is the SWRL Editor?
The SWRL Editor is an extension to Protégé-OWL that permits the interactive editing of SWRL rules.
The editor can be used to create SWRL rules, edit existing SWRL rules, and read and write SWRL rules.
It is accessible as a tab within Protégé-OWL.
6-73
Logic and Rules
SWRL Editor
6-74
Logic and Rules
SWRL Editor
6-75
Logic and Rules
Executing SWRL Rules
SWRL is a language specification Well-defined semantics Developers must implement engine Or map to existing rule engines Hence, a bridge…
– to Jess rule engine (obsolete – needs license)– to Drools rule engine (free, built-in with Protege 3.5)
6-76
Logic and Rules
SWRL and RuleML
SWRL is an extension of RuleML
brother(X,Y) childOf(Z,Y)
uncle(X,Z)
6-77
Rules in SPARQL: SPIN
Rules can be expressed in SPARQL using its CONSTRUCT feature
parent(X,Y), parent(Y,Z) grandparent(X,Z)
CONSTRUCT {?X grandParent ?Z .
}WHERE {
?X parent ?Y .?Y parent ?Z .
}5-78 Logic and Rules
SPIN
Associates rules to classes– Rules may represent behavior of that class, and may not exist on
their own – Global rules can also be defined
Expresses – Rules by SPARQL CONSTRUCT, DELETE and INSERT– Constraints using SPARQL ASK
Provides abstraction mechanisms for rules – Templates: Parameterized SPARQL queries– User-defined SPIN functions– Be able to build higher-level rules (complex SPARQL queries) on top
of simpler5-79 Logic and Rules
OWL2 RL rules in SPIN
C1(X), equivalentClass(C1,C2) C2(X)
CONSTRUCT {?X a ?C2 .
}WHERE {
?X a ?C1.?C1 equivalentClass ?C2.
}5-80
This should become an instance of spin:rule and attached to class owl:Thing to allow the rule to be applied to all possible instances
Logic and Rules