5. Raisonning and SWRL Language

Definition

A rule expresses reasoning of the form “if antecedent then consequent. It is formulated as follows: antecedent → consequent, where:

  • antecedent, also called a premise or body of the rule, represents a conjunction of conditions (atoms) for applying the rule,
  • consequent, also called head of the rule, is the the result of applying the rule.

5.1 Rules in propositional logic

Rule : p1 ∧ p2 ∧ … pn → c ≡ ¬p1 ∨ ¬p2 ∨ …∨ ¬pn ∨ c

  • c: is only true if all p₁…pₙ are true.

  • Constraint : ¬p1 ∨ ¬p2 ∨ …∨ ¬pn

  • The symbole ≡ signifies a definition or equivalence

Special rules

  • The fact: →conclusion

     `⊤ → c`  
    
    • : tautology or universal concept, its logical value is always true
  • the constraint: antecedent →

    p1 ∧ p2 ∧ …∧ pn → ⊥
    
    • : contradiction or impossible concept, its logical value is always false.

    • px, x=1, ...,n : atomic concept

    • ¬: negation of a concept/proposition

5.2 Inference with rules

Let a set of rules be given: K = (F, R, C)

F: set of facts, where the set of premises is empty

R: set of rules, where the set of premises is non-empty and the conclusion is non-empty

C: set of constraints, where the conclusion is empty

An inference is expressed as follows:

K |= Q, where Q is a query (a fact)

This means: Does K semantically entail Q?

Inference can be performed either:

  • by forward chaining: starting from K and the premises of the rules
  • by backward chaining: starting from Q and the conclusions of the rules

Forward chaining

Forward chaining is data-driven:

  • allows new facts to be added by applying rules (production or saturation)
  • deductive method
  • based on Modus Ponens: from A and A → B, we deduce B
  • a rule is applicable if its premises are included in the set of facts
  • apply the rule: add its conclusion to the set of facts (if it is not already there)

Principle of forward chaining: apply rules as long as possible or until a certain fact has been obtained.

Backward chaining

Backward chaining is goal-driven:

  • seeks to eliminate the goal by using the rules that produced it
  • inductive method
  • Starting from the conclusion B, we look for the rule A → B that produced it and replace it with A.
  • A goal is produced by applying a rule if it is equal to the conclusion of the rule.

Principle of backward chaining: starting from a goal, search for the rule that produced it, replace it with the list of premises of the rule until an empty list is obtained.

Adding rules to an ontology

  • Enables greater expressiveness.
  • Declarative statements close to users’ natural language
  • Conditional rules: “if … then”
  • Composition of properties

Example: Parent(X,Y) ∧ Brother (Z,X) → uncle (Z,Y)

5.3 SWRL (Semantic Web Rule Language)

  • Rule language based on OWL
  • Provides inference capabilities superior to OWL alone
  • Combination of OWL DL (ontologies) and RuleML (rules)
  • Documentation: https://www.w3.org/Submission/SWRL/

SWRL rule

Antecedent → consequent (if antecedent then consequent)

  • antecedent: conjunctions of atoms
  • consequent: only one atom

An atom in an SWRL rule can be:

  • C(x) where C is a concept owl:Class. C(x) is also called a unary predicate
  • a datatype property owl:DatatypeProperty (e.g., xsd:string(?x))
  • p(x,y) where p is an object property owl:ObjectProperty and x, y are variables. p(x,y) is also called a binary predicate.
  • an SWRL relation such as sameAs(x,y) and differentFrom(x,y)
  • an atom with a predefined “built-in” predicate. There are predefined functions for operations involving:
    • comparisons
    • Booleans
    • mathematics
    • character strings
    • time where x, y are variables, OWL individuals or OWL values.

Example of atoms

Person(?p)
xsd:int(?x)
aChild(?x,?y)
aAge(?x,?age)
aAge(?x, 100)
differentFrom(?x,?y)
sameAs(?x,?y)

Examples of built-in predicates 
   swrlb:greaterThan(?age,18): predefined predicate evaluated as true if the arguments satisfy it
   swrlb:add(?x,2): allows a value to be added

Example of an SWRL rule

hasParent(x, y) ∧ hasSibling(y, z) ∧ hasSexmale(z) → hasUncle(x, z)

The translation of this rule into SWRL:

hasParent(?x1, ?x2) ∧ hasSibling (?x2, ?x3) ∧ hasSexmale(?x3) → hasUncle(?x1, ?x3)

5.5 Built-in predicates

Built-in functions for comparison operations

swrlb :equal
swrlb :notEqual
swrlb :lessThan
swrlb :lessThanOrEqual
swrlb :greaterThan
swrlb :greaterThanOrEqual

Built-in function for Boolean operations

swrlb :booleanNot

Built-in functions for arihmetic operations

swrlb :add
swrlb :sustract
swrlb :multiply
swrlb :divide
swrlb :integerDivide
swrlb :mod
swrlb :pow
swrlb :unaryPlus
swrlb :unaryMinus
swrlb :abs
swrlb :ceiling
swrlb :floor
swrlb :round
swrlb :roundHalfToEven
swrlb :sin
swrlb :cos
swrlb :tan

Built-in functions for operations on characters and strings

swrlb :stringEqualIgnoreCase
swrlb :stringConcat
swrlb :substring
swrlb :stringLength
swrlb :normalizeSpace
swrlb :upperCase
swrlb :lowerCase
swrlb :translate
swrlb :contains
swrlb :containsIgnoreCase
swrlb :startsWith
swrlb :endsWith
swrlb :substringBefore
swrlb :substringAfter
swrlb :matches
swrlb :replace
swrlb :tokenize

Built-in functions for time operations

swrlb :yearMonthDuration
swrlb :dayTimeDuration
swrlb :dateTime
swrlb :date
swrlb :time
swrlb :addYearMonthDurations
swrlb :substractYearMonthDurations
swrlb :multiplyYearMonthDurations
swrlb :divideYearMonthDurations
swrlb :addDayTimeDurations
swrlb :substractDayTimeDurations
swrlb :multiplyDayTimeDurations
swrlb :divideDayTimeDurations
swrlb :substractDates
swrlb :substractTimes
swrlb :addYearMonthDurationToDateTime
swrlb :addDayTimeDurationToDateTime
swrlb :substractYearMonthDurationFromDateTime
swrlb :substractDayTimeDurationFromDateTime
swrlb :addYearMonthDurationToDate
swrlb :addDayTimeDurationToDate
swrlb :substractYearMonthDurationFromDate
swrlb :substractDayTimeDurationFromDate
swrlb :addDayTimeDurationToTime
swrlb :substractDayTimeDurationFromTime
swrlb :substractDayTimesYieldingYearMonthDuration
swrlb :substractDayTimesYieldingDayTimeDuration

Built-in Functions for URI Operations

swrlb :resolveURI
swrlb :anyURI

Built-in functions for operations on lists

swrlb :rlistConcat
swrlb :listIntersection
swrlb :listSubtraction
swrlb :member
swrlb :length
swrlb :first
swrlb :rest
swrlb :sublist
swrlb :empty