most material was taken from the following source: – grigoris antoniou, frank van harmelen, a...
TRANSCRIPT
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. Introduction
2. Rules: Example
3. Rules: Syntax & Semantics
4. RuleML & RIF: XML Representation for Rules
5. 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
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
Logic and Rules
Monotonic vs. Non-monotonic Rules
Example: An online vendor wants to give a special discount if it is a customer’s birthday
Solution 1
R1: If birthday, then special discount
R2: If not birthday, then not special discount But what happens if a customer refuses to
provide his birthday due to privacy concerns?
6-10
Logic and Rules
Monotonic vs. Non-monotonic Rules (2)
Solution 2
R1: If birthday, then special discount
R2’: If birthday is not known, then not special discount
Solves the problem but:– The premise of rule R2' is not within the expressive
power of predicate logic– We need a new kind of rule system
6-11
Logic and Rules
Monotonic vs. Non-monotonic Rules (3)
The solution with rules R1 and R2 works in case we have complete information about the situation
The new kind of rule system will find application in cases where the available information is incomplete
R2’ is a nonmonotonic rule
6-12
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-13
Logic and Rules
Lecture Outline
1. Introduction
2. Rules: Example
3. Rules: Syntax & Semantics
4. RuleML & RIF: XML Representation for Rules
5. Rules & Ontologies: OWL 2 RL & SWRL
6-14
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-15
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-16
Logic and Rules
A More Complex Rule ExampleBrokered Trade
Brokered trades take place via an independent third party, the broker
The broker matches the buyer’s requirements and the sellers’ capabilities, and proposes a transaction when both parties can be satisfied by the trade
The application is apartment renting an activity that is common and often tedious and time-consuming
6-17
Logic and Rules
The Potential Buyer’s Requirements
– At least 45 m2 with at least 2 bedrooms – Elevator if on 3rd floor or higher– Pet animals must be allowed
Carlos is willing to pay:– 300 € for a centrally located 45 m2 apartment– 250 € for a similar flat in the suburbs– An extra 5 € per m2 for a larger apartment– An extra 2 € per m2 for a garden– He is unable to pay more than 400 € in total
6-18
Logic and Rules
The Potential Buyer’s Requirements (2)
If given the choice, he would go for the cheapest option
His second priority is the presence of a garden His lowest priority is additional space
6-19
Logic and Rules
Formalization of Carlos’s Requirements – Predicates Used
apartment(x), x is an apartment
size(x,y), y is the size of apartment x (in m2)
bedrooms(x,y), x has y bedrooms
price(x,y), y is the price for x
floor(x,y), x is on the y-th floor
gardenSize(x,y), x has a garden of size y
6-20
Logic and Rules
Formalization of Carlos’s Requirements – Predicates Used (2)
lift(x), there is an elevator in the house of x
pets(x), pets are allowed in x
central(x), x is centrally located
acceptable(x), flat x satisfies Carlos’s
requirements
offer(x,y), Carlos is willing to pay y € for flat x
6-21
Logic and Rules
Formalization of Carlos’s Requirements – Rules
acceptable(X):-
apartment(X),
not(incompatible(X)).
incompatible(X):- bedrooms(X,Y), Y < 2.
incompatible(X):- size(X,Y), Y < 45.
incompatible(X):- not(pets(X)).
incompatible(X):- floor(X,Y), Y > 2, not(lift(X)).
incompatible(X):- price(X,Y), Y > 400 .6-22
Logic and Rules
Formalization of Carlos’s Requirements – Rules (2)
offer(X,O) :-
size(X,Y), Y ≥ 45, garden(X,Z), central(X),
O = 300 + 2*Z+5*(Y-45).
offer(X,O) :-
size(X,Y), Y ≥ 45, garden(X,Z), not(central(X)),
O = 250+ 2*Z+5*(Y-45).
incompatible(X):-
offer(X,Y), price(X,Z), Y < Z.6-23
Logic and Rules
Selecting an ApartmentAuxiliary predicates
cheapest(X) :-
acceptable(X), price(X,P1),
not( (acceptable(Y), price(Y,P2), P2 < P1) ).
largestGarden(X):-
acceptable(X), gardenSize(X,G1),
not( (acceptable(Y), gardenSize(Y,G2), G2 > G1) ).
largest(X):-
acceptable(X), size(X,S1),
not( (acceptable(Y), size(Y,S2), S1<S2) ).6-24
Logic and Rules
Selecting an Apartment
cll(X):-
cheapest(X), largestGarden(X), largest(X).
cl(X) :- cheapest(X), largestGarden(X).
c(X) :- cheapest(X).
rent(X):- cll(X).
rent(X):- cl(X), not(cll(Y)).
rent(X):- c(X), not(cl(Y)).6-25
Logic and Rules
Representation of Available Apartments
apartment(a1)
bedrooms(a1,1)
size(a1,50)
central(a1)
floor(a1,1)
pets(a1)
garden(a1,0)
price(a1,300)
6-26
Logic and Rules
Representation of Available Apartments (2)
Flat Bed-rooms
Size Central Floor Lift Pets Garden Price
a1 1 50 yes 1 no yes 0 300
a2 2 45 yes 0 no yes 0 335
a3 2 65 no 2 no yes 0 350
a4 2 55 no 1 yes no 15 330
a5 3 55 yes 0 no yes 15 350
a6 2 60 yes 3 no no 0 370
a7 3 65 yes 1 no yes 12 375
6-27
Logic and Rules
Lecture Outline
1. Introduction
2. Rules: Example
3. Rules: Syntax & Semantics
4. RuleML & RIF: XML Representation for Rules
6-28
Logic and Rules
Rules – Syntax
loyalCustomer(X), age(X) > 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, >– Function symbols which return a value for certain
arguments: age
6-29
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) > 60 discount(X)– Implicitly universally quantified
6-30
Logic and Rules
Facts and Logic Programs
A fact is an atomic formula E.g. loyalCustomer(a345678) The variables of a fact are implicitly universally
quantified. A logic program P is a finite set of facts and rules. Its predicate logic translation pl(P) is the set of all
predicate logic interpretations of rules and facts in P
6-31
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-32
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-33
Logic and Rules
An Example
p(a)
¬X p(X)The 2nd formula says that no element
has the property pThe 1st formula says that the value of a
does have the property p Thus X p(X) follows from p(a)
6-34
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-35
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-36
Logic and Rules
Carlo ExampleDetermining Acceptable Apartments
If we match Carlos’s requirements and the available apartments, we see that
flat a1 is not acceptable because it has one bedroom only
flats a4 and a6 are unacceptable because pets are not allowed
for a2, Carlos is willing to pay $ 300, but the price is higher
flats a3, a5, and a7 are acceptable
6-37
Logic and Rules
Inference for room a1
apartment(a1). bedrooms(a1,1).
acceptable(X):-
apartment(X), not(incompatible(X)).
incompatible(X):- bedrooms(X,Y), Y < 2.
?- acceptable(a1). FALSE
apartment(a1), not(incompatible(a1)) FALSE bedrooms(a1,1), 1 < 2 TRUE
6-38
Logic and Rules
Inference for room a3
apartment(a3). bedrooms(a3,2). size(a3,65). floor(a3,2).
pets(a3). garden(a3,0). price(a3,350).
acceptable(X):-
apartment(X), not(incompatible(X)).
?- acceptable(a3).
apartment(a3), not(incompatible(a3))
In order for «not» to become true, all alternative ways to prove incompatibility must be proven false6-39
Logic and Rules
Formalization of Carlos’s Requirements – Rules
incompatible(a3):- bedrooms(a3,2), 2 < 2. FALSE
incompatible(a3):- size(a3,65), 65 < 45. FALSE
incompatible(a3):- not(pets(a3)). FALSE
incompatible(a3):- floor(a3,2), 2 > 2, not(lift(a3)). FALSE
incompatible(a3):- price(a3,350), 350 > 400. FALSE
incompatible(a3):-
offer(a3,350), price(a3,350), 350 < 350. FALSE
offer(a3,350) :-
size(a3,65), 65 ≥ 45, garden(a3,0), not(central(a3)),
350 = 250+ 2*0+5*(65-45).6-40
Logic and Rules
Selecting the “best” apartment
Among the acceptable (compatible) apartments a3, a5, a7, apartments a3 and a5 are cheapest. – Of these, a5 has the largest garden.
Thus a5 is suggested for renting.
?- rent(a5).
Yes
?- rent(a7).
No
?- rent(a3).
No
6-41
Logic and Rules
Lecture Outline
1. Introduction
2. Rules: Example
3. Rules: Syntax & Semantics
4. RuleML & RIF: XML Representation for Rules
5. Rules & Ontologies: OWL 2 RL & SWRL
6-42
Logic and Rules
Rule Markup Language (RuleML)
RuleML is an effort to develop markup of rules on the web It is 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-43
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-44
Logic and Rules
Atomic Formulas
p(X, a, f(b, Y))
<Atom><Rel>p</Rel><Var>X</Var><Ind>a</Ind><Expr> <Fun>f</Fun>
<Ind>b</Ind><Var>Y</Var>
</Expr></Atom>
6-45
Logic and Rules
Rules
<Implies><Then>
<Atom>
<Rel>r</Rel>
<Var>X</Var>
<Var>Y</Var>
</Atom></Then>
<If><And>
<Atom><Rel>p</Rel>
<Var>X</Var>
<Ind>a</Ind>
</Atom>
<Atom><Rel>q</Rel>
<Var>Y</Var>
<Ind>b</Ind></
Atom></And>
</If></Implies>
p(X,a), q(Y,b) r(X,Y)
6-47
Logic and Rules
RuleML: Rule Markup LanguageDTD (one of the many variations)
<!ELEMENT rulebase ((Implies|Fact)*)> <!ELEMENT Fact (Atom)> <!ELEMENT Implies ((If,Then)|(Then,If))><!ELEMENT If (Atom)><!ELEMENT Then (Atom|Naf|And|Or)><!ELEMENT Atom (Rel,(Ind|Var|Expr)*)><!ELEMENT Naf (Atom)+)><!ELEMENT And (Atom)+)> <!ELEMENT Or (Atom)+)><!ELEMENT Rel (#PCDATA)><!ELEMENT Var (#PCDATA)> <!ELEMENT Ind (#PCDATA)><!ELEMENT Expr (Fun, (Ind|Var|Expr)*)><!ELEMENT Fun (#PCDATA)>
6-48
Logic and Rules
Carlo – RuleML equivalent
<Implies><Then>
<Atom><Rel>incompatible</Rel><Var>x</Var>
</Atom></Then><If>
<Naf><Atom>
<Rel>pets</Rel><var>x</var>
</Atom></Naf>
</If></Implies>
incompatible(X):- not(pets(X)).
Negation As Failure
6-49
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-50
Logic and Rules
RIF-BLD
Corresponds to Horn logic with equality plus– Data types and built ins, and– Frames.
Data Types– integer, boolean, string, date,
“Built-in” Predicates – numeric-greater-than, startswith, date-less-than
Functions – numeric-subtract, replace, hours-fromtime
6-51
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-52
Logic and Rules
RIF – use of frames
The use of frames has a long tradition in OO languages and knowledge representation, – Has also been prominent in rule languages (e.g.
FLogic). The basic idea is to represent objects as
frames, and their properties as slots.– E.g., a class professor with slots name, office, phone,
department etc.
oid[slot1 -> value1 … slotn -> valuen]
6-53
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] Example
ex:GoneWithTheWind ex:FilmYear ex:1939
ex:GoneWithTheWind[ex:FilmYear -> ex:1939]
6-54
Logic and Rules
Inference in RIF and RDF
RIF rule: the Hollywood Production Code was in place between 1930 and 1968
Group(Forall ?Film (
If And( ex:?Film[ex:Year -> ?Year]External(pred:dateGreaterThan(?Year 1930))External(pred:dateGreaterThan(1968 ?Year)))
Then ?Filmex:HollywoodProductionCode -> ex:True])) Conclusionex:GoneWithTheWind[ex:HollywoodProductionCode -> ex:True]
RIFex:GoneWithTheWind ex:HollywoodProductionCode ex:True
RDF6-55
Logic and Rules
Summary
Horn logic is a subset of predicate logic that allows efficient reasoning, orthogonal to description logics
Horn logic is the basis of monotonic rules Nonmonotonic rules are useful in situations where the
available information is incomplete Representation of rules using XML-like languages is
straightforward– Standardization must cope with all the different forms and
types of rules
6-56
Logic and Rules
Lecture Outline
1. Introduction
2. Rules: Example
3. Rules: Syntax & Semantics
4. RuleML & RIF: XML Representation for Rules
5. Rules & Ontologies: OWL 2 RL & SWRL
6-57
Logic and Rules
Description Logic Programs (DLP)
Horn logic (rules) and description logics (ontologies) are orthogonal
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-59
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-60
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-61
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-62
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-63
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-64
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-65
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-66
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-67
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-68
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-69
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-70
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 D
C(X) → D(X) Similarly for subproperty
P(X,Y) → Q(X,Y)
6-71
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-72
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-73
Logic and Rules
More OWL Constructs
Transitive Properties
P(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)– the opposite is outside the expressive power of Horn
logic6-74
Logic and Rules
Union (1)
The union of C1 and C2 is a subclass of D
C1(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
6-75
Logic and Rules
Union (2)
There are cases where the translation is possible– when D1 is a subclass of D2, then the rule
C(X) → D2(X) – is sufficient to express that C is a subclass of the
union of D1 and D2 There is not a translation that works in all
cases
6-76
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)
C(X), P(X, Y) → D(Y) The opposite direction cannot in general be
expressed
6-77
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
P(X,Y), D(Y) → C(X) The opposite direction cannot in general be
expressed.
6-78
Logic and Rules
Non-expressible constructs
Cardinality constraints and Complement of classes cannot be expressed in Horn logic in the general case.
6-79
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-80
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-81
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-82
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-83
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-84
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-85
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
6-86
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-87
Logic and Rules
Example SWRL Rules: Named Individuals
Person(Fred) hasSibling(Fred, ?s) Man(?s)
→ hasBrother(Fred, ?s)
6-88
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-89
Logic and Rules
Example SWRL Rules:String Built-ins
Person(?p) hasNumber(?p, ?number)
swrlb:startsWith(?number, "+")
→ hasInternationalNumber(?p, true)
6-90
Logic and Rules
Example SWRL Rules: Built-ins / Argument Binding
Person(?p) hasSalaryInPounds(?p, ?pounds) swrlb:multiply(?dollars, ?pounds, 2.0)
→ hasSalaryInDollars(?p, ?dollars)
Person(?p) hasSalaryInPounds(?p, ?pounds) swrlb:multiply(2.0, ?pounds, ?dollars)
→ hasSalaryInDollars(?p, ?dollars)
– Arguments can bind in any position – Usually implementations support binding of the 1st arg
6-91
Logic and Rules
Can define new Built-in Libraries
Temporal built-ins:– temporal:before("1999-11-01T10:00", "2000-02-
01T11:12:12.000")– temporal:duration(2, "1999-11-01", "2001-02-01",
temporal:Years) • TBox built-ins:
– tbox:isDatatypeProperty(?p)– tbox:isDirectSubPropertyOf(?sp, ?p)
• Mathematical built-ins:– swrlm:eval(?circumference, "2 * pi * r", ?r)
6-92
Logic and Rules
SWRLTab Built-in Librarieshttp://protege.cim3.net/cgi-bin/wiki.pl?SWRLTabBuiltInLibraries
6-93
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-94
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-95
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-96
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-97
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-98
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-100
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
6-103