Transformation of UML classes and attributes
In this section are specified transformation rules for UML class and attribute elements. Table 1 provides an overview of the section coverage.
UML element | Rules in core ontology layer | Rules in data shape layer | Rules in reasoning layer |
---|---|---|---|
Class |
|||
Abstract class |
|||
Attribute |
|||
Attribute type |
|||
Attribute multiplicity |
Class
In UML, a Class [uml2.5] is purposed to specify a classification of objects. UML represents atomic classes as named elements of type Class without further features. In OWL, the atomic class, owl:Class
, has no intention. It can only be interpreted by its name that has a meaning in the world outside the ontology. The atomic class is a class description that is simultaneously a class axiom .
Specify an OWL Class declaration axiom for each UML Class, where the URI of the OWL class is deterministically generated from the UML Class name.
Ideally, in the implementation, this rule would be combined with the relevant rules (those for the core ontology layer) in the Transformation of UML descriptors section, to provide labels and documentation for the class at the time of its creation. |
Listing 1. Class declaration in Turtle syntax
|
Listing 2. Class declaration in RDF/XML syntax
|
Specify a SHACL NodeShape declaration axiom for each UML Class. The URIs of the node shape and of the OWL class they refer to, are deterministically generated from the UML Class name.
Ideally, in the implementation, this rule would be combined with the relevant rules (those for the data shape layer) in the Transformation of UML descriptors section, to provide labels and documentation for the node shape at the time of its creation. |
Listing 3. Node shape declaration in Turtle syntax
|
Listing 4. Node shape declaration in RDF/XML syntax
|
Abstract class
In UML, an abstract Class [uml2.5] cannot have any instances and only its subclasses can be instantiated. The abstract classes are declared just like the regular ones (Rule C.01 and Rule C.02) and in addition a constraint validation rule is generated to ensure that no instance of this class is permitted.
OWL follows the Open World Assumption [owl2], therefore, even if the ontology does not contain any instances for a specific class, it is unknown whether the class has any instances. We cannot confirm that the UML abstract class is correctly defined with respect to the OWL domain ontology, but we can detect if it is not using SHACL constraints.
Specify a SHACL NodeShape declaration axiom for each abstract UML Class, with a SPARQL constraint that selects all instances of this class.
Ideally, in the implementation, this rule would be combined with the relevant rules (those for the data shape layer) in the Transformation of UML descriptors section, to provide labels and documentation for the node shape at the time of its creation. |
Listing 5. Instance checking constraint in Turtle syntax
|
Listing 6. Instance checking constraint in RDF/XML syntax
|
Attribute
The UML attributes [uml2.5] are properties that are owned by a Classifier, e.g. Class. Both UML attributes and associations are represented by one meta-model element – Property. OWL also allows one to define properties. A transformation of UML attribute to OWL data property or OWL object property is done based on its type. If the type of the attribute is a primitive type it should be transformed into OWL data property. However, if the type of the attribute is a structured datatype, class or enumeration, it should be transformed into an OWL object property. These cases are illustrated in Figure 3.
Attributes can also be reused across multiple classes (i.e. multiple UML classes can own the same attributes), as illustrated in Figure 4. In such cases there should be special logic applied when defining the domain and range of these properties (see rules Rule C.05, Rule C.07).
Specify declaration axiom(s) for attribute(s) of a UML Class as OWL data or object properties, deciding based on their types. The attributes with primary types should be treated as data properties, whereas those typed with classes or enumerations should be treated as object properties.
Ideally, in the implementation, this rule would be combined with the relevant rules (those for the core ontology layer) in the Transformation of UML descriptors section, to provide labels and documentation for the property at the time of its creation. |
Listing 7. Data property declaration in Turtle syntax
|
Listing 8. Data property declaration in RDF/XML syntax
|
Listing 9. Object property declaration in Turtle syntax
|
Listing 10. Object property declaration in RDF/XML syntax
|
Attribute owner
Specify data (or object) property domains for attribute(s). The domain of properties created for attributes that are reused in multiple classes should be the union of all the classes where the attribute is reused.
Listing 11. Data property domain specification in Turtle syntax
|
Listing 12. Data property domain specification in RDF/XML syntax
|
Listing 13. Object property domain specification in Turtle syntax
|
Listing 14. Object property domain specification in RDF/XML syntax
|
For reused attributes, like the ones depicted in Figure 4, the generated output should have the following form.
Listing 15. Data property domain specification for reused attributes in Turtle syntax
|
Listing 16. Data property domain specification for reused attributes in RDF/XML syntax
|
Listing 17. Object property domain specification for reused attributes in Turtle syntax
|
Listing 18. Object property domain specification for reused attributes in RDF/XML syntax
|
Specify a SHACL PropertyShape declaration axiom for each attribute.
Ideally, in the implementation, this rule would be combined with the relevant rules (those for the core ontology layer) in the Transformation of UML descriptors section, to provide labels and documentation for the property shape at the time of its creation. |
Listing 19. PropertyShape declaration for attributes in Turtle syntax
|
Listing 20. PropertyShape declaration for attributes in RDF/XML syntax
|
Attribute type
Specify data (or object) property range for attribute(s). The range of object properties created for attributes that are reused in multiple classes should be the union of all the classes specified as values for those attributes.
Listing 21. Data property range specification in Turtle syntax
|
Listing 22. Data property range specification in RDF/XML syntax
|
Listing 23. Object property range specification in Turtle syntax
|
Listing 24. Object property range specification in RDF/XML syntax
|
For reused attributes, like the ones depicted in Figure 4, the generated output should have the following form.
Listing 25. Object property range specification for reused attributes in Turtle syntax
|
Listing 26. Object property range specification for reused attributes in RDF/XML syntax
|
Within the SHACL PropertyShape corresponding to an attribute of a UML Class, specify property constraints indicating the range class or datatype.
Listing 27. Property datatype constraint in Turtle syntax
|
Listing 28. Property datatype constraint in RDF/XML syntax
|
Listing 29. Property class constraint in Turtle syntax
|
Listing 30. Property class constraint in RDF/XML syntax
|
Attribute multiplicity
In [uml2.5], multiplicity bounds of multiplicity element are specified in the form of [<lower-bound> .. <upper-bound>]
. The lower-bound, also referred here as minimum cardinality or min
is of a non-negative Integer type and the upper-bound, also referred here as maximum cardinality or max
, is of an UnlimitedNatural type (see Section Primitive datatype). The strictly compliant specification of UML in version 2.5 defines only a single value range for MultiplicityElement. not limit oneself to a single interval. Therefore, the below UML to OWL mapping covers a wider case – a possibility of specifying more value ranges for a multiplicity element. Nevertheless, if the reader would like to strictly follow the current UML specification, the particular single lower..upper bound interval is therein also comprised.
It should be noted that upper-bound of UML MultiplicityElement can be specified as unlimited: ``*''. In OWL, cardinality expressions serve to restrict the number of individuals that are connected by an object property expression to a given number of instances of a specified class expression [owl2]. Therefore, UML unlimited upper-bound does not add any information to OWL ontology, hence it is not transformed.
For each attribute multiplicity of the form ( min .. max ), where min and max are different than ``*'' (any), specify a subclass axiom where the OWL class, corresponding to the UML Class, specialises an anonymous restriction of properties formulated according to the following cases.
-
exact cardinality, e.g. [2..2]
-
minimum cardinality only, e.g. [1..*]
-
maximum cardinality only, e.g. [*..2]
-
maximum and maximum cardinality , e.g. [1..2]
Listing 31. Exact cardinality constraint in Turtle syntax
|
Listing 32. Exact cardinality constraint in RDF/XML syntax
|
Listing 33. Min cardinality constraint in Turtle syntax
|
Listing 34. Min cardinality constraint in RDF/XML syntax
|
Listing 35. Max cardinality constraint in Turtle syntax
|
Listing 36. Max cardinality constraint in RDF/XML syntax
|
Listing 37. Min and max cardinality constraint in Turtle syntax
|
Listing 38. Min and max cardinality constraint in RDF/XML syntax
|
Attributes with multiplicity exactly one correspond to functional object or data properties in OWL. If we apply the previous rule specifying min and max cardinality will lead to inconsistent ontology. To avoid that it is important that min and max cardinality are not generated from [1..1] multiplicity but only functional property axiom.
For each attribute that has multiplicity exactly one, i.e. [1..1], specify a functional property axiom.
Listing 39. Declaring a functional property in Turtle syntax
|
Listing 40. Declaring a functional property in RDF/XML syntax
|
Within the SHACL PropertyShape corresponding to an attribute of a UML Class, specify property constraints indicating the minimum and maximum cardinality, only where min and max are different from ``*'' (any) and multiplicity is not [1..1]. The expressions are formulated according to the following cases.
-
exact cardinality, e.g. [2..2]
-
minimum cardinality only, e.g. [1..*]
-
maximum cardinality only, e.g. [*..2]
-
minimum and maximum cardinality , e.g. [1..2]
Listing 41. Exact cardinality constraint in Turtle syntax
|
Listing 42. Exact cardinality constraint in RDF/XML syntax
|
Listing 43. Min cardinality constraint in Turtle syntax
|
Listing 44. Min cardinality constraint in RDF/XML syntax
|
Listing 45. Max cardinality constraint in Turtle syntax
|
Listing 46. Max cardinality constraint in RDF/XML syntax
|
Listing 47. Min and max cardinality constraint in Turtle syntax
|
Listing 48. Min and max cardinality constraint in RDF/XML syntax
|