```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.
Lecture Outline
1.
2.
3.
4.
5.
6-2
Introduction
Rules: Example
Rules: Syntax & Semantics
RuleML & RIF: XML Representation for
Rules
Rules & Ontologies: OWL 2 RL & SWRL
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
6-4

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
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
–
6-5
Soundness & completeness
Logic and Rules
The Importance of Logic (3)

Predicate logic is unique in the sense that
sound and complete proof systems do exist.
–

Logic can trace the proof that leads to a
logical consequence.

Logic can provide explanations for answers
–
6-6
Not for more expressive logics (higher-order
logics)
By tracing a proof
Logic and Rules
Specializations of Predicate Logic:
RDF and OWL

RDF/S and OWL (Lite and DL) are
specializations of predicate logic
–

They define reasonable subsets of logic

Trade-off between the expressive power and
the computational complexity:
–
6-7
correspond roughly to a description logic
The more expressive the language, the less efficient
the corresponding proof systems
Logic and Rules
Specializations of Predicate Logic:
Horn Logic

A rule has the form: A1, . . ., An  B
–

There are 2 ways of reading such a rule:
–
–
6-8
Ai and B are atomic formulas
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
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
–

Rules cannot assert the information that a person is
either a man or a woman
–
6-9
This can be done easily using rules:
studies(X,Y), lives(X,Z), loc(Y,U), loc(Z,U) 
homeStudent(X)
This information is easily expressed in OWL using disjoint
union
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

6-10
But what happens if a customer refuses to
provide his birthday due to privacy concerns?
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:
–
–
6-11
The premise of rule R2' is not within the expressive
power of predicate logic
We need a new kind of rule system
Logic and Rules
Monotonic vs. Non-monotonic
Rules (3)



6-12
The solution with rules R1 and R2 works
in case we have complete information
The new kind of rule system will find
application in cases where the available
information is incomplete
R2’ is a nonmonotonic rule
Logic and Rules
Exchange of Rules

Exchange of rules across different applications
–


6-13
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 XMLlike languages (“rule markup languages”)
Logic and Rules
Lecture Outline
1.
2.
3.
4.
5.
6-14
Introduction
Rules: Example
Rules: Syntax & Semantics
RuleML & RIF: XML Representation for
Rules
Rules & Ontologies: OWL 2 RL & SWRL
Logic and Rules
Family Relations

Facts in a database about relations:
–
–
–
–

6-15
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)
Logic and Rules
Inferred Relations
6-16

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)
Logic and Rules
A More Complex Rule Example



6-17
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
The application is apartment renting an activity
that is common and often tedious and timeconsuming
Logic and Rules
–
–
–

Carlos is willing to pay:
–
–
–
–
–
6-18
At least 45 m2 with at least 2 bedrooms
Elevator if on 3rd floor or higher
Pet animals must be allowed
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
Logic and Rules



6-19
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
Logic and Rules
Formalization of Carlos’s
Requirements – Predicates Used
6-20

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
Logic and Rules
Formalization of Carlos’s
Requirements – Predicates Used (2)
6-21

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
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 Apartment
Auxiliary 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)
6-26
pets(a1)
garden(a1,0)
price(a1,300)
Logic and Rules
Representation of Available
Apartments (2)
6-27
Flat Bedrooms
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
Logic and Rules
Lecture Outline
1.
2.
3.
4.
6-28
Introduction
Rules: Example
Rules: Syntax & Semantics
RuleML & RIF: XML Representation for
Rules
Logic and Rules
Rules – Syntax
loyalCustomer(X), age(X) > 60  discount(X)

We distinguish some ingredients of rules:
–
–
–
–
6-29
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
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
–
–
6-30
loyalCustomer(X), age(X) > 60  discount(X)
Implicitly universally quantified
Logic and Rules
Facts and Logic Programs
6-31

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
Logic and Rules
Goals
A goal denotes a query G asked to a
logic program
The form:


–
–
6-32
B1, . . . , Bn 
?- B1, . . . , Bn.
OR
(as in Prolog)
Logic and Rules
Proof Procedure

We use a proof technique from mathematics called
–

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
–
6-33
Prove that A follows from B by assuming that A is false and
deriving a contradiction, when combined with B
E.g., given the following logic program we get a logical
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-34
Logic and Rules
First-Order Interpretation of Goals
p(a)
p(X)  q(X)
q(X) 



6-35
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
Logic and Rules
First-Order Interpretation of Goals (2)
p(a)
p(X)  q(X)
q(b) 

6-36
We must give a negative answer because
q(b) does not follow from the logical
program
Logic and Rules
Carlo Example
Determining Acceptable Apartments





6-37
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
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 false
6-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(a3).
No
6-41
?- rent(a5).
Yes
?- rent(a7).
No
Logic and Rules
Lecture Outline
1.
2.
3.
4.
5.
6-42
Introduction
Rules: Example
Rules: Syntax & Semantics
RuleML & RIF: XML Representation for
Rules
Rules & Ontologies: OWL 2 RL & SWRL
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:
–

The kernel of the RuleML family is Datalog
–

6-43
function-free Horn logic
RuleML is experimental
–

derivation rules, integrity constraints, reaction rules, …
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 RIF
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>
<Var>customer</Var>
</Atom>
<Atom>
<Rel>luxury</Rel>
<Var>product</Var>
The discount for a
a product is 7.5%
if the customer is
product is luxury
</Atom>
</And>
</if>
</Implies>
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
Facts
p(a).
<Fact>
<Atom>
<Rel>p</Rel>
<Ind>a</Ind>
</Atom>
</Fact>
6-46
Logic and Rules
Rules
p(X,a), q(Y,b)  r(X,Y)
<Implies>
<Then>
<Atom>
<Rel>r</Rel>
<Var>X</Var>
<Var>Y</Var>
</Atom>
</Then>
6-47
<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>
Logic and Rules
RuleML: Rule Markup Language
DTD (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
6-49
<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
Logic and Rules
Rule Interchange Format: RIF

Rule technology exhibits a broad variety
–

The aim of the W3C RIF Working Group
–
–
–

–
–
6-50
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. action rules, first order rules, logic programming
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).
Logic and Rules
RIF-BLD

Corresponds to Horn logic with equality plus
–
–

Data Types
–

numeric-greater-than, startswith, date-less-than
Functions
–
6-51
integer, boolean, string, date,
“Built-in” Predicates
–

Data types and built ins, and
Frames.
numeric-subtract, replace, hours-fromtime
Logic and Rules



6-52
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
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.
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]))
 Conclusion
ex:GoneWithTheWind[ex:HollywoodProductionCode -> ex:True]
RIF
ex:GoneWithTheWind ex:HollywoodProductionCode ex:True
6-55
RDF
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
–
6-56
Standardization must cope with all the different forms and
types of rules
Logic and Rules
Lecture Outline
1.
2.
3.
4.
5.
6-57
Introduction
Rules: Example
Rules: Syntax & Semantics
RuleML & RIF: XML Representation for
Rules
Rules & Ontologies: OWL 2 RL & SWRL
Logic and Rules
Rules & Ontologies
OWL 2 RL & SWRL
Description Logic Programs (DLP)


Horn logic (rules) and description logics (ontologies) are
orthogonal
The simplest integration approach is the intersection of
both logics
–

OWL2 RL capture this fragment of OWL (previously
called Description Logic Programs - DLP)
–
–
6-59
The part of one language that can be translated in a semanticspreserving way to the other
Horn-definable part of OWL, or
OWL-definable part of Horn logic
Logic and Rules
OWL 2 RL

OWL 2 is based on Description Logic.
–
–

OWL 2 RL is an interesting sublanguage of
OWL 2 DL
–
6-60
A fragment of first-order logic
Inherits open-world assumption and non-uniquename assumption
Above assumptions do not make a difference
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
–
6-61
In some applications is not the right choice
Logic and Rules
OWA vs. CWA
Examples

Example in favor of OWA
–
–

Example in favor of CWA
–
–
6-62
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.”
Question: “Was there a big earthquake disaster in
Tokyo yesterday?”
disaster, I’d have heard about it. Therefore I conclude
that there wasn’t such a disaster.”
Logic and Rules
Unique-Name Αssumption (UNA)

When two individuals are known by different
names, they are in fact different individuals.
–


6-63
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
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
–
6-64
using owl:allDifferent
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.
–
6-65
Big debate in the literature
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
–
–
6-66
OWL 2 RL is weak enough so that the differences
between the choices don’t show up.
Still large enough to enable useful representation
Logic and Rules


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.
–
6-67
They disagree on the semantics.
Logic and Rules

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.
–

6-68
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.
Logic and Rules
OWL 2 RL constructs

Which constructs of RDF Schema and OWL 2
can be expressed in Horn logic?
–

6-69
They lie within the expressive power of DLP
Some constructs cannot be expressed
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
–
6-70
Union, existential quantification, and arbitrary
cardinality constraints
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),
–
–


6-71
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)
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)
–

6-73
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)
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)
–
6-74
C(X) → D2(X)
the opposite is outside the expressive power of Horn
logic
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.
–
6-75
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
Logic and Rules
Union (2)

There are cases where the translation is
possible
–
–

6-76
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
Logic and Rules
OWL Restrictions allValuesFrom

allValuesFrom(P,D)
–


6-77
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
Logic and Rules
OWL Restrictions someValuesFrom

someValuesFrom(P,D)
–


6-78
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.
Logic and Rules
Non-expressible constructs

6-79
Cardinality constraints and Complement of
classes cannot be expressed in Horn logic in
the general case.
Logic and Rules
OWL 2 RL – Conclusions



6-80
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
Logic and Rules
Semantic Web Rules Language
(SWRL)


6-81
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.
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
–
–
–
6-82
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.
Logic and Rules

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
–

A(X,Y)→ B(X),C(Y)
–
–
6-83
conjunction of atoms without shared variables
A(X,Y)→ B(X)
A(X,Y)→ C(Y)
Logic and Rules
Complexity of SWRL



6-84
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.
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.
–
–
6-85
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
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)
–
–
6-86
Possible in OWL – hasValue (sufficient) restriction
Not all such reclassifications are possible in OWL
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)
–
6-87
Not possible in OWL
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)

Built-ins dramatically increase expressivity
–
–
6-89
most rules are not expressible in OWL 1
Some built-ins can be expressed in OWL 2
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)
–
–
6-91
Arguments can bind in any position
Usually implementations support binding of the 1st arg
Logic and Rules
Can define new Built-in Libraries

Temporal built-ins:
–
–

• TBox built-ins:
–
–

6-92
temporal:before("1999-11-01T10:00", "2000-0201T11:12:12.000")
temporal:duration(2, "1999-11-01", "2001-02-01",
temporal:Years)
tbox:isDatatypeProperty(?p)
tbox:isDirectSubPropertyOf(?sp, ?p)
• Mathematical built-ins:
–
swrlm:eval(?circumference, "2 * pi * r", ?r)
Logic and Rules
SWRLTab Built-in Libraries
http://protege.cim3.net/cgibin/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
–
6-94
Individuals must also be explicitly stated to be
different (using owl:allDifferents restriction)
Logic and Rules
SWRL is Monotonic:
does not Support Negated Atoms
Person(?p)  not hasCar(?p, ?c)
→ CarlessPerson(?p)


6-95
Not possible - language does not support
negation here
Potential invalidation - what if a person later
gets a car?
Logic and Rules
SWRL is Monotonic:
retraction (or modification) not supported
Person(?p)  hasAge(?p,?age)
→ hasAge(?p, ?newage)
 Incorrect:
–

There is no retraction of old value
–
6-96
will run forever and attempt to assign an infinite
number of values to hasAge property
Even if there was, it would run forever
Logic and Rules
SWRL is Monotonic:
counting not supported
Publication(?p)  hasAuthor(?p,?a) 
<has exactly one hasAuthor value in current ontology>
→ SingleAuthorPublication(?p)


6-97
Not expressible - open world applies
Potential invalidation - what if author is
Logic and Rules
SWRLTab





6-98
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
Logic and Rules
SWRLTab Wiki :
http://protege.cim3.net/cgi-bin/wiki.pl?SWRLTab
6-99
Logic and Rules
What is the SWRL Editor?



6100
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.
Logic and Rules
SWRL Editor
6101
Logic and Rules
SWRL Editor
6102
Logic and Rules
Executing SWRL Rules





6103
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
Logic and Rules
SWRL and
RuleML
SWRL is an
extension of
RuleML
brother(X,Y) 
childOf(Z,Y)
 uncle(X,Z)

6104
Logic and Rules
```