=Paper= {{Paper |id=Vol-428/paper-4 |storemode=property |title=Defining a Subset of OCL for Expressing SWRL Rules |pdfUrl=https://ceur-ws.org/Vol-428/paper4.pdf |volume=Vol-428 |dblpUrl=https://dblp.org/rec/conf/ecai/Lukichev08 }} ==Defining a Subset of OCL for Expressing SWRL Rules== https://ceur-ws.org/Vol-428/paper4.pdf
       Defining a subset of OCL for expressing SWRL rules
                                                                  Sergey Lukichev 1


Abstract. OCL is a rich-syntax language for expressing integrity               2    Translating SWRL rules into OCL invariants
rules and many business rules can be expressed using OCL. On the
other hand, UML/OCL is a mainstream modeling technology and                    First, we remind the SWRL abstract syntax, which is originally
adopting it for expressing rules in the upcoming Semantic Web is a             defined in [3]. By I = Imp(Antec(A), Conseq(C)) we de-
good practical issue: rules can be initially expressed in UML/OCL              note a SWRL rule where A and C are conjunctions of SWRL
and then mapped into OWL/SWRL. Since UML/OCL is more ex-                       atoms. By classAtom(CD, t) we denote a SWRL class atom,
pressive than OWL/SWRL it is good to define a subset of OCL,                   where CD is a class description, as defined in [2] (Section
which can easily be mapped into the SWRL. In this paper we de-                 2.3.2.3. OWL DL Restrictions) and t is an object variable or
fine this subset of OCL, called OCL-Lite, by building a mapping                an individual. By individualPropertyAtom(p, o1, o2) we
from SWRL into OCL. In addition, we briefly sketch the correctness             denote a SWRL individual property atom, where p is a ref-
problem of this mapping in terms of language interpretations.                  erence to a property, and o1 and o2 are object variables.
                                                                               By A = datavaluedPropertyAtom(p, obj, val) we denote a
                                                                               SWRL datatype property atom, where p is a reference to an datatype
                                                                               property, obj is an object variable and val is a data value or a data
1     Introduction                                                             variable.
                                                                                  According to the semantics of SWRL [3], SWRL rules are in-
There are two issues we have to motivate: i). Why the subset of OCL,           tegrity constraints in the form of logical implications.
which can be mapped into SWRL is needed? ii). Why we build the                    Let I = Imp(Antec(A), Conseq(C)) be a SWRL rule, then
mapping from SWRL to OCL in order to define this subset?                       the mapping T transforms it into an OCL invariant as follows:
   UML/OCL [1] is widely used among software engineers, while                      T(I) := context class(X) inv:
                                                                                   T(A) implies T(C)
the area of the Semantic Web lacks for modeling methodologies
and tools, comparable in popularity and maturity with UML/OCL.                    The context class X of the resulting OCL invariant is class of a
Therefore, it is natural to reuse existing UML/OCL methodologies               universally quantified variable in the rule. This variable then is re-
and tools for modeling Semantic Web rules, which are expressed                 named to self. If the rule has more than one universally quantified
in the Semantic Web Rule Language (SWRL) [3]. The first arising                variable, then X.allInstances()->forAll(y|e(y)) expression
problem with mapping OCL constraints into SWRL rules is a rich                 is used recursively, where X is a class of the universally quantified
OCL syntax. It allows variety of expressions and not all of them can           variable and e(y) is the OCL boolean expression, resulted from the
be mapped into SWRL. There are a number of works on sharing                    SWRL rule.
rules between OWL/SWRL and UML/OCL [7], [5], [6]. However,                        In fact, using the SWRL syntax, it is possible to express
these works are mainly focused on the technical side of the mapping,           a rule, which cannot be mapped into a syntactically cor-
in particular on the implementation of the metamodel transforma-               rect OCL invariant. In particular, this is because SWRL
tions using Query View Transformations (QWT). The main question,               supports data variables, which are not explicitly supported
which remains open in these works is what is exact subset of OCL,              in OCL. For instance, if we have a conjunction of two
which can be mapped into SWRL? In this work we bridge this gap                 SWRL atoms: individualPropertyAtom(age, o, x) and
by defining a subset of OCL, called OCL-Lite, which can be mapped              builtinAtom(>, x, 18), where x is a data variable, then this
into SWRL.                                                                     corresponds to the OCL expression o.age>18, i.e. we have one
   In order to define OCL-Lite, we build a mapping from SWRL to                OCL expression from the conjunction of two SWRL atoms. If
OCL. The expressivity of OCL is higher than the first order logic              the built-in atom is dropped, then the SWRL rule still remains
since closures over object relations can be expressed in OCL but not           syntactically correct, while the resulting OCL expression will have
in FOL [4]. Moreover, the syntax of SWRL is simpler than OCL,                  unknown symbol x. We do not define such possible mappings in this
therefore we build the mapping from the less expressive language to            paper and focus on the direct mappings of SWRL atoms.
the more expressive one, which is a natural method in determining                 We do not describe how URIs are mapped into names of UML
the mappable subset of OCL.                                                    classifiers since this task is about the mapping from OWL to UML
   The paper is structured as follows: section 2 contains the mapping          while we define the mapping of SWRL rules into OCL invariants.
                                                                                  The body and the head of a SWRL rule is a conjunction of SWRL
from SWRL to OCL, in section 3 the syntax of OCL-Lite is specified             atoms, therefore if A = A1, ..., An, then
and section 4 defines the problem of the semantical correctness of                 T(A) := T(A1) and ... and T(An)
SWRL to OCL mapping and lists open issues for the further research.
                                                                                   Let us consider the mapping of SWRL atoms.
1 Institute of Informatics, Brandenburg University of Technology at Cottbus,
                                                                               • If A = classAtom(id, t) is a SWRL class atom, where id is
    Email: Lukichev@tu-cottbus.de                                                an URI reference of the class and t is an object variable, then
       T(A) := t.oclIsKindOf(id)                                               Restriction(objProp, mincardinality(n))
• If A = individualPropertyAtom(p, o1, o2) where p is a                     where objProp is a property and n is minimal cardinality, then
  reference to an individual property, o1 and o2 are object vari-
  ables, then                                                                  T(classAtom(CD, t)) := t.objProp->size()>=n
       T(A) := o1.p=o2                                                    The mapping of restrictions with min- and max- cardinalities is
• If                                                                      similar.
  A = datavaluedPropertyAtom(p, obj, val) where p is a                  • If CD = OneOf({obj1,...,objn}) where obj1,...,objn
  reference to an individual property, obj is an object variable and      are object URIs, then
  val is a data value or a data variable, then
                                                                               T(classAtom(CD, t)) := t=obj1 or ... or
       T(A) := obj.p=val                                                       t=objn
• If A = builtinAtom(builtin, {obj}) where builtin is                       An example of the class atom with oneOf description
  a SWRL builtin and {obj} is a list of datatype terms, then                   CA := classAtom(oneOf(White, Red), t)
  the resulting OCL expression is of type Boolean and de-
                                                                            Then
  pends on the built-in, for instance, if builtin is ’+’ then
  A = builtinAtom(’+’, a,b,c) and T(A) := a=b+c.                               T(CA) := t=White or t=Red

                                                                            An OWL enumerated class, which is specified by the direct enu-
If A = classAtom(CD, t) is a SWRL class atom with an OWL                    meration of its instances, can be represented in UML by means of
description CD, then we define the mapping function case wise for           a UML enumeration class. Some additional mapping from OWL
each possible OWL class description CD (the syntax of OWL class             enumerated classes into UML enumeration classes may be needed
descriptions is defined in [2]):                                            in order to produce a syntactically correct OCL expression. How-
• If CD = UnionOf(CD1, CD2) where CD1 and CD2 are OWL                       ever, this is the problem of UML to OWL mapping, which is be-
  class descriptions, then                                                  yond our rules mapping problem.
       T(classAtom(UnionOf(CD1, CD2), t)) :=
       T(classAtom(CD1, t)) or T(classAtom(CD2,                            In order to show how the mapping works, let us consider a rule ”If
       t))                                                              the maker of a liquid is a winery, then the liquid is either a wine or a
                                                                        cognac”. The rule in SWRL is:
  For instance, if CD = UnionOf(Winery, Brewery) then
                                                                            R=Implies(Antec(classAtom(Liquid, t)
       T(classAtom(CD, t)) := t.oclIsKindOf(Winery)                           classAtom(Restriction(hasMaker,
       or t.oclIsKindOf(Brewery)                                                            allValuesFrom(Winery)), t))
• If CD = IntersectionOf(CD1, CD2) where CD1 and CD2 are                              Conseq(classAtom(
  OWL class descriptions, then                                                              UnionOf(Wine, Cognac), t)))
       T(classAtom(CD, t)) := T(classAtom(CD1, t))                          The mapping of R into OCL:
       and T(classAtom(CD2, t))                                             T(R):= context Liquid inv:
• If CD = ComplementOf(CD1) where CD1 is an OWL class de-                       T(classAtom(Restriction(hasMaker,
  scriptions, then                                                                 allValuesFrom(Winery)), t))
                                                                                implies
       T(classAtom(CD, t)) := not T(classAtom(CD1,                              T(classAtom(UnionOf(Wine, Cognac), t)))
       t))
                                                                            Which is finally:
• If     CD = Restriction(oProp, allValuesFrom(CD1))
  where oProp is a property and CD1 is a class description, then            context Liquid inv:
                                                                              self.hasMaker->forAll(x|
       T(classAtom(CD, t)) :=                                                       x.oclIsKindOf(Winery))
       t.oProp->forAll(x|T(classAtom(CD1, x)))                              implies
  The variable x is unified with instances of the property collection         self.oclIsKindOf(Wine) or
  oProp . For instance, if                                                    self.oclIsKindOf(Congnac)
       CD = Restriction(hasMaker,
                        allValuesFrom(Winery))
                                                                        3     The syntax of OCL-Lite
  then
       T(classAtom(CD, t)) :=                                           The syntax of OCL-Lite expressions is defined recursively so that
        t.hasMaker->forAll(x|                                           more complex expressions are built from simple ones. The definition
                   T(classAtom(Winery, x))) :=
        t.hasMaker->forAll(x|                                           below is based on the result of the mapping, defined in the previous
                   x.oclIsKindOf(Winery))                               section. In the syntax definition below we refer to OCL expressions,
• If CD is                                                              which are based on navigation operations, as navigation expressions.
                                                                        For instance, self.father.brothers is a navigation expres-
       Restriction(oProp,
                   someValuesFrom(CD1))                                 sion, which is not a new concept on top of OCL, but just a denotation
                                                                        of the existing OCL expression, also used in the OCL specification
  where oProp is a property and CD1 is a class description, then
                                                                        [1]. A navigation expression may result into a collection of instances.
       T(classAtom(CD, t)) :=
         t.oProp->exists(x|
                                                                        We introduce this denotation in order to simplify the OCL-Lite syn-
                   T(classAtom(CD1, x)))                                tax by eliminating various OCL operations, which are not supported
• If CD is                                                              in SWRL.
       Restriction(dProp, value(d))                                     1. self is a special variable, which type is given by the invariant con-
  where dProp is a datatype property and d is data value, then             text;
       T(classAtom(CD, t)) := t.dProp=d                                 2. For every OCL model type t there is an unlimited number of vari-
• If CD is                                                                 ables vti , which are OCL expressions of type t;
3. If f is an OCL operation symbol with argument types t1 , ..., tn           • T : SI → OI , which maps SWRL interpretations into OCL inter-
   and result type tr , e1 , ..., en are OCL expressions and type of ei         pretations.
   is ti for all 1 ≤ i ≤ n then f (e1 , ..., en ) is OCL expression of
   type tr . The set of operation symbols includes:                           The task is to prove that for any SWRL interpretation J and SWRL
                                                                              rule G if
    • some of predefined data operations: +, −, ∗;                                                            J |= G
    • attribute operations, for instance, self.age, e.salary;
                                                                              then
    • side-effect free operations defined by a class, for instance,                                        T (J ) |= t(G)
      b.rentalDiscount();
                                                                                The solution to this task is currently in our agenda and results will
    • navigation by   role                names,       for       instance,    be published soon.
      self.pickupBranch.
4. If e1 and e2 are OCL expressions of an appropriate type (which             REFERENCES
   provides an order relation, for instance, integer) then e1 > e2 ,
   e1 < e2 , e1 >= e2 , and e1 <= e2 are Boolean OCL expres-                  [1] Object Constraint Language (OCL), v2.0. OMG Final Adopted Specifi-
                                                                                  cation.
   sions. Note, that symbols >, <, >=, and <= are OCL operations              [2] OWL Web Ontology Language Semantic and Abstract Syntax. W3C
   in the OCL metamodel, however here we define OCL expressions                   Recommendation 10 February 2004. http://www.w3.org/2004/OWL.
   with these symbols separately since logically they are predicate           [3] SWRL: A Semantic Web Rule Language Combining OWL
   symbols, while expressions, defined in the previous item are dif-              and RuleML.          W3C Member Submission 21 May 2004.
                                                                                  http://www.w3.org/Submission/SWRL/.
   ferent types of terms;                                                     [4] Luis Mandel and Maria Victoria Cengarle. On the expressive power of
5. If e is an object variable, then e.oclIsKindOf (C), where C is a               ocl. In FM ’99: Proceedings of the Wold Congress on Formal Methods in
   class name, is a Boolean expression;                                           the Development of Computing Systems-Volume I, pages 854–874, Lon-
6. If e1 , e2 are Boolean expressions then e1 and e2 , e1 or e2 , not e1 ,        don, UK, 1999. Springer-Verlag.
   e1 implies e2 are Boolean expressions;                                     [5] Milan Milanovic, Dragan Gasevic, Adrian Giurca, Gerd Wagner, and
                                                                                  Vladan Devedzic. On interchanging between owl/swrl and uml/ocl. In
7. If e1 , e2 are OCL expressions of the same type, then e1 = e2 ,                Proceedings of the OCLApps Workshop, pages 81–95, Genova, Italy, 2
   e1 <> e2 are Boolean expressions.                                              October 2006.
8. If e(x) is a navigation expression, where variable x is bound              [6] Milan Milanovic, Dragan Gasevic, Adrian Giurca, Gerd Wagner, and
   by the quantifier, for instance, self.employee, then e(x) →                    Vladan Devedzic. Sharing owl/swrl and uml/ocl rules. In Proceedings of
                                                                                  ACM/IEEE 9th International Conference on Model-Driven Engineering
   size() op n is Boolean expression, where op is either >, <, =,                 Languages and Systems (MODELS 2006), Genova, Italy, 1-6 October
   >=, <=, or <>. We do not define an expression of the form                      2006.
   e(x).size(), where e is of any OCL collection type, for instance,          [7] Milan Milanovic, Dragan Gasevic, Adrian Giurca, Gerd Wagner, and
   resulted from some operation on collections like includesAll()                 Vladan Devedzic. Towards sharing rules between owl/swrl and uml/ocl.
   since they are not defined in SWRL. The defined expression of                  In Electronic Communications of European Association of Software Sci-
                                                                                  ence and Technology, 2007.
   the form e(x) → size() op n is obtained via the mapping from
   the SWRL class atom with cardinality restriction.
9. If e is a navigation expression, for instance, self.employee,
   then e → f orAll(x|e1 (x)) and e → exists(x|e1 (x)) are
   Boolean expressions, where e1 (x) is a Boolean OCL expression
   from variable x, which is bound by universal quantifier or existen-
   tial quantifier.


4     Conclusion and future work
In this paper we described the syntactic mapping from SWRL to
OCL and on the result of this mapping defined the syntax of OCL-
Lite, a simplified subset of the OCL syntax. OCL-Lite can be used for
expressing rules, which later can be mapped into the SWRL. Some
practical experiments with the implementation of this mapping are
available at the REWERSE I1 website2 .
   The main open issue in this work is the semantic correctness of
the defined mapping. Having such mapping it is important to make
sure that the set of models of a SWRL rule f coincides with the set of
models of the OCL invariant t(f ). We describe the problem formally.
   Let I be an interpretation of SWRL rules and |= is a satisfaction
relation between interpretations and SWRL rules and there are the
following mappings:

• t : S → O, which maps SWRL rules into OCL invariants. It is a
  syntactic transformation, which we have defined in this paper.
2     REWERSE I1 Rule Translators:             http://oxygen.informatik.tu-
    cottbus.de/rewerse-i1/?q=node/15