Transformation OWL UML Java, example - universAAL/tools.eclipse-plugins GitHub Wiki
Transformation is a very general word and we first have to clarify what it means in our context. Our main purpose is to make development as easy as possible for you. One possibility here is to allow you to make models in a form you like and create valid universAAL code out of them. Here we will cover several aspects like modelling of services. What we are currently going for is to provide tools that allow you to model your ontologies in UML and/or OWL and transform the result to an universAAL Java-Project. You can use it either directly in other projects or you are going to change details in the created source. Additional details and up-to-date information about aided creating of ontologies can be found on the [Ontology_modelling] of it. The transformation tool is documented [Model_Transformation_Tool].
Note: the example names used in the examples below are inspired by the Lighting example or other examples. To avoid any conflicts with the existing ontologies and examples, please select your own unique identifiers for group id and/or artefact id when creating new ontologies and services.
The tool should be installed by using the update-page from universAAL like shown in the installation chapter. You can currently find it in the group "AAL Studio tools" at the update-page. If not already happens make sure that the appropriate box is checked. Normally Papyrus UML should be installed automatically. If you get into any trouble here you additionally need to install Papyrus UML which can easily be done by using "Help --> Installing Modeling Components" from the main-menu of eclipse. Please check there the appropriate box and install the software by using the "Finish"-Button like shown below:
For further help about how to create and edit UML-Modells we refer to the documentation of Papyrus UML. The important issues in how to create UML-Models that can be transformed to valid universAAL ontologies are shown in this chapter.
An ontology provides a description of the a special purpose or domain. In universAAL we use them to create expressive models of the system that allows a semantic inter-operable layer for the communication between the components of the platform. Since ontological concepts are not as common as using UML, we are currently support a transformation from UML to the Java representation of OWL like used in universAAL. In this chapter we are going to implement a minimalist approach to describe the domain of light-sources. During creation we will explain the features provided by the tool and how this effects the code produced for universAAL.
Now we are going to create a universAAL project that contains the ontology. Therefore a special wizard is available. Best you can start it over the main-menu using AAL Studio --> Create a new Ontology Project. You should see a wizard like in the following figure:
Used values:
Ontology name: LightingOntology
Parent package: org.universAAL.tools.samples
Maven version: 0.1.0-SNAPSHOT
Maven Description: A minimal ontology to describe light-sources
Generate Java to OWL support file: true
Please fill it out with the parameters like given above. Also consider the check-box for the Java to OWL transformation support, we will need this in a subsection below. If you accept the wizard by clicking the finish-button all needed files for the ontology project will be created for you. If everything is done right you should see in the Package Explorer (Window -> Show View -> Package Explorer) a result like in the following:
The wizard creates a full featured new Maven-Eclipse project including the needed base structure and the pom.xml. At this point the pom.xml is nearly empty and no Java-Code is included in the project. For this we first need to create our model in UML. Every model from Papyrus UML brings three files with it. *.notation and *.uml (the resulting XMI-File) are both automatically generated and updated by using the Papyrus Editor for the model-file (*.di). Please make a double-click at the generated LightingOntology.di now. In the now given diagram you can see some prepared classes like in the following:
The modelling approach to ontology design is closely related to the way an ontology is defined in Java. The following list describes the overall concept mappings:
- UML Model: is the topmost modelling level. Using the [Ontology_Project_Wizard] will create the model correctly.
- UML Package: represents an Ontology. A package is marked as a "owlOntology" using stereotypes from the OWL UML Library. Using the [Ontology_Project_Wizard] the package is created and labeled using the names filled in the wizard
- UML Class: represents a ontology concept. A Class can have properties (attributes) that are typed (datatype or object), and associations that are directed. A class will map to a Java class (and file), and will be included in the Ontology and Activator files.
- UML Properties: this is an attribute of the class or interface and represents a property of the ontology concept. There are two types of properties that can be associated with a class: ObjectProperty and DatatypeProperty. Using the elements found in the Ontology Modelling Tool palette, you the types and required stereotypes settings are automatically set to their default values (e.g. isFunctional="true")
- UML Association: an association is simliar to a property and will result in a property in the owner class (assuming only unidirectional associations). The name of the property will be the label on the association end (default by tool is the end class name).
- UML Generalization: a generalization is a way to describe inheritance using UML, and will result in a class extend relationship in java.
First you can remove the comment fields at the top and bottom of the diagram by right-click them and select Delete Selected Element (but read it before if not already done). Also we do not need the classes ManagedIndividual and MyConcept in this example. Please also delete them by using the context-menu and do not simply press the remove button on your keyboard! This simply hide the elements. A full overview about the model you can get from the Model Explorer. You can find this using Window --> Show View --> Other... --> Papyrus --> Model Explorer from the Eclipse main menu. Now to make things more easy we right-click the class MyService and select Show Properties View. The resulting view allows us to get information about a selected object and change attributes if needed. Here we want to change MyService to Lighting. Next we rename MyDevice to LightSource and going to add a property for the brightness of a light-source to it. This can be done by using the Papyrus Palette like available at the right of the diagram window. Here in sub-section Ontology you can find the entries datatypeProperty (Property) and objectProperty (Property). The differences between both types are described in detail in the ontology chapter. But in short words a datatype-property denotes a basic UML datatype like String, Integer and so on. An object-property represents a pointer to an other object of the ontology (a class based on MangedIndividual). Now we want to create a datatype-property. Therefore please click the according element and then click at next the first box under the caption of LightSource. Please give brightness as a name for the property and select Integer as the type. This can be done by select the button with the three dots right of the caption Type in the properties view. Now you should see a dialogue like the following:
In the field Filter you can search for available types. Please type Integer here and select Integer given in UMLPrimitiveTypes. The same way you can select arbitrary other types. All need to be done now is to indicate that the Lighting-Service will be used to control elements of type LightSource. Therefore we are going to use a directed association, that we find in the Ontologies sub-section of the Papyrus Palette. Please click once at the Association Entry and then one time on Lighting and finally at LightSource. All need to be done now is to correct the multiplicity of the association. This can be done by select the association and use the Properties-View to set Multiplicity of the Member End with the name lightSource to 0..*. The basics of our example are now finished. If you want to extend the model by your own please be aware, that the tool currently only supports the elements that are given in the Ontologies sub-section of the Papyrus Palette. Currently we do not take use of the Enumeration element, so lets finally test out also this one. Click at Enumeration and then into some free space of the diagram. Please give the name LightTypes for the enumeration. Now you can add an Enumeration literal in the same way like done for the datatype-property. Please add here the literals Electric and Natural. If all has been done right you should have a result like this:
Now we are going to create the sources out of the model. Therefore make sure that you saved the changes done at the diagram and right-click at the LightingOntology.uml file in the file-/package explorer. Please select here AAL Studio --> Transform UML ontology to Java from the context-menu. Select 2.0.0 as universAAL version and click OK. Some text should be shown in the Eclipse console and the transformation is done! The project should now look like this:
There are three packages generated, where one only contains the OSGi activator. The other two contain all the bundles like needed by universAAL for the ontology. To get more information about building ontologies and details about the class-structure have a look at the according chapter in the RD. All we need for our example is ready now and we have a full featured ontology project for the steps in the next chapters.
Since we have checked the button for the Java to UML support box during creation of the ontology project, the transformation from UML to Java additionally produces a class to export the ontology as OWL file. In our example this class is located in the creator package and named OwlOWLCreator.java. The basic idea is here to use the capabilities of the serialization tool like used within the middleware to load the Java ontology, write it out as a Turtle serialized file and finally convert it to a valid RDF/XML OWL file. The OwlOWLCreator class contains a main-method that can be simply started by using Eclipse to let it run as a Java-Application (right-click the class and select Run As --> 1 Java Application). After the execution you can find a file Lightingontology.owl in the project root that contains the result.
Currently there are two known issues about the export. First Enumerations are currently not included within the serialization. Second the import entry for other ontologies may not be correct and they are not included as a RDF resource (like would be correct) but as an RDF datatype. Both bugs depend on functionality given by the middleware and will be fixed in new releases (then the tool do also work correct).
There is also a tool in work that is able to transform generated or given XML/RDF OWL files to UML files like used in the UML to Java tool. This tool is currently under development and not included within the AAL Suite. But if you want to have already more detailed information please have a look at the [OWL2UML_Transformation_Tool].
Support for a direct transformation from OWL Files into a valid Java representation of universAAL is also in on the list. Currently this is also not an integrated part of the AAL Suite. If you want to get a first impression of the tool you can get this from our [OWL2Java_Transformation_Tool].
How to use the Ontology Project Wizard:
Video
How to use the Ontology Modeling part:
Video
How to use the Model Transformation:
Video
How to use the OWL2UML Transformation:
Video