| 1 |
-- @atlcompiler atl2006
|
| 2 |
-- $Id$
|
| 3 |
-- Base module for transforming a UML2 model to an API OWL ontology
|
| 4 |
module UML2ToAPIOntology; --abstract
|
| 5 |
|
| 6 |
create OUT : OWL from IN : UML2, PLATFORM : OWL, JAVA : OWL;--, PREVOUT : OWL, PREVIN : UML2;
|
| 7 |
|
| 8 |
uses UML2Comparison;
|
| 9 |
|
| 10 |
-- ======================================================================
|
| 11 |
-- helper attributes begin
|
| 12 |
-- ======================================================================
|
| 13 |
|
| 14 |
helper def : UML2ToAPIOntologyVersionString : String =
|
| 15 |
'$Id$';
|
| 16 |
|
| 17 |
helper def : inElements : Set(UML2!"ecore::EObject") = UML2!"ecore::EObject".allInstancesFrom('IN');
|
| 18 |
|
| 19 |
helper def : includedPackages : Set(UML2!"uml::Package") = UML2!"uml::Package".allInstancesFrom('IN')
|
| 20 |
->select(p|p.oclIsTypeOf(UML2!"uml::Package") and p.packagedElement
|
| 21 |
->select(c|c.oclIsKindOf(UML2!"uml::Class") or c.oclIsKindOf(UML2!"uml::Interface"))->notEmpty());
|
| 22 |
|
| 23 |
helper def : platformPlatform : Set(OWL!"owl::OWLClass") = OWL!"owl::OWLClass".allInstancesFrom('PLATFORM')
|
| 24 |
->select(o|o.localName = 'Platform');
|
| 25 |
|
| 26 |
helper def : javaLibrary : Set(OWL!"owl::OWLClass") = OWL!"owl::OWLClass".allInstancesFrom('JAVA')
|
| 27 |
->select(o|o.localName = 'JavaLibrary');
|
| 28 |
|
| 29 |
helper def : javaJRE : Set(OWL!"owl::OWLClass") = OWL!"owl::OWLClass".allInstancesFrom('JAVA')
|
| 30 |
->select(o|o.localName = 'JRE');
|
| 31 |
|
| 32 |
helper def : platformProvidesFeature : OWL!"owl::OWLObjectProperty" =
|
| 33 |
OWL!"owl::OWLObjectProperty".allInstancesFrom('PLATFORM')
|
| 34 |
->select(p|p.localName = 'providesFeature')->first();
|
| 35 |
|
| 36 |
helper def : jreProvidesBuiltinJavaLibrary : OWL!"owl::OWLObjectProperty" =
|
| 37 |
OWL!"owl::OWLObjectProperty".allInstancesFrom('JAVA')
|
| 38 |
->select(p|p.localName = 'providesBuiltinJavaLibrary')->first();
|
| 39 |
|
| 40 |
helper def : platformOntology : Set(OWL!"owl::OWLOntology") =
|
| 41 |
OWL!"owl::OWLOntology".allInstancesFrom('PLATFORM');
|
| 42 |
|
| 43 |
helper def : javaOntology : Set(OWL!"owl::OWLOntology") =
|
| 44 |
OWL!"owl::OWLOntology".allInstancesFrom('JAVA');
|
| 45 |
|
| 46 |
helper def : importedOntologies : Set(OWL!"owl::OWLOntology") =
|
| 47 |
OWL!"owl::OWLOntology".allInstances()->select(o|
|
| 48 |
OWL!"owl::OWLOntology".allInstancesFrom('PLATFORM')->excludes(o) and
|
| 49 |
OWL!"owl::OWLOntology".allInstancesFrom('JAVA')->excludes(o));
|
| 50 |
|
| 51 |
-- ======================================================================
|
| 52 |
-- general context helper attributes begin
|
| 53 |
-- ======================================================================
|
| 54 |
|
| 55 |
helper context UML2!"uml::NamedElement" def : javaQualifiedName : String =
|
| 56 |
if self.owner.oclIsTypeOf(UML2!"uml::Package") or self.owner.oclIsKindOf(UML2!"uml::Classifier") then
|
| 57 |
self.owner.javaQualifiedName + '.' + self.name
|
| 58 |
else
|
| 59 |
self.name
|
| 60 |
endif;
|
| 61 |
|
| 62 |
helper context UML2!"uml::NamedElement" def : ontClassName : String =
|
| 63 |
if self.owner.oclIsTypeOf(UML2!"uml::Package") then
|
| 64 |
self.owner.ontClassName
|
| 65 |
else '' endif
|
| 66 |
+ self.name.firstToUpper();
|
| 67 |
|
| 68 |
-- ======================================================================
|
| 69 |
-- helper attributes for finding references
|
| 70 |
-- ======================================================================
|
| 71 |
|
| 72 |
helper context UML2!"uml::Package" def : references : Set(UML2!"uml::Package") =
|
| 73 |
self.allOwnedClassifiers
|
| 74 |
->collect(c|c.references)->flatten()->asSet()
|
| 75 |
->collect(r|r.referencesOtherPackageThan(self))->flatten()->asSet()
|
| 76 |
.debug(thisModule.modelName.prefix + self.qualifiedName + ' referenced packages');
|
| 77 |
|
| 78 |
-- Non-transitive references
|
| 79 |
helper context UML2!"uml::Classifier" def : references : Set(UML2!"uml::Classifier") =
|
| 80 |
self.general->union(
|
| 81 |
self.suppliers->select(s|s.oclIsKindOf(UML2!"uml::Classifier")))->union(
|
| 82 |
self.feature->collect(f|f.referencesOtherThan(self)))
|
| 83 |
->flatten()->asSet();
|
| 84 |
|
| 85 |
-- ======================================================================
|
| 86 |
-- helper attributes for determining compatibility
|
| 87 |
-- ======================================================================
|
| 88 |
|
| 89 |
helper context UML2!"uml::NamedElement" def : owlClassesInPrev : Sequence(OWL!"owl::OWLClass") =
|
| 90 |
OWL!"owl::OWLClass".allInstances()
|
| 91 |
->select(c|c.localName = self.ontClassName + 'Library')
|
| 92 |
->select(o|o.namespace.name = self.getModel().name);
|
| 93 |
|
| 94 |
helper context UML2!"uml::Package" def : compatibleClasses : Sequence(OWL!"owl::OWLClass") =
|
| 95 |
self.compatibleInPrev->collect(p|p.owlClassesInPrev)->flatten();
|
| 96 |
|
| 97 |
helper context UML2!"uml::Package" def : equivalentClasses : Sequence(OWL!"owl::OWLClass") =
|
| 98 |
self.equivalentInPrev->collect(p|p.owlClassesInPrev)->flatten();
|
| 99 |
|
| 100 |
-- ======================================================================
|
| 101 |
-- helper attributes end
|
| 102 |
-- ======================================================================
|
| 103 |
|
| 104 |
-- ======================================================================
|
| 105 |
-- general helper methods
|
| 106 |
-- ======================================================================
|
| 107 |
|
| 108 |
helper context String def: firstToUpper() : String =
|
| 109 |
self.substring(1, 1).toUpper() + self.substring(2, self.size());
|
| 110 |
|
| 111 |
-- ======================================================================
|
| 112 |
-- helper methods for finding references
|
| 113 |
-- ======================================================================
|
| 114 |
|
| 115 |
helper context UML2!"uml::PackageableElement" def : referencesOtherPackageThan(p : UML2!"uml::Package") : Set(UML2!"uml::Package") =
|
| 116 |
let np : UML2!"uml::Package" = self.getNearestPackage() in
|
| 117 |
if np <> p then Set{np} else Set{} endif;
|
| 118 |
|
| 119 |
helper context UML2!"uml::BehavioralFeature" def : referencesOtherThan(c : UML2!"uml::Classifier") : Sequence(UML2!"uml::Classifier") =
|
| 120 |
self.ownedParameter->collect(p|p.referencesOtherThan(c))->flatten();
|
| 121 |
|
| 122 |
helper context UML2!"uml::TypedElement" def : referencesOtherThan(c : UML2!"uml::Classifier") : Sequence(UML2!"uml::Classifier") =
|
| 123 |
if self.type.oclIsKindOf(UML2!"uml::Class") or self.type.oclIsKindOf(UML2!"uml::Interface") then
|
| 124 |
if self.type.getModel() = c.getModel() and self.type <> c
|
| 125 |
then Sequence{self.type}
|
| 126 |
else Sequence{} endif
|
| 127 |
else Sequence{} endif;
|
| 128 |
|
| 129 |
-- ======================================================================
|
| 130 |
-- helper methods end
|
| 131 |
-- ======================================================================
|
| 132 |
|
| 133 |
-- ======================================================================
|
| 134 |
-- transformation rules begin
|
| 135 |
-- ======================================================================
|
| 136 |
|
| 137 |
rule PrevNamespace(o : OWL!"owl::OWLOntology") {
|
| 138 |
to n : OWL!"rdfs::Namespace" (
|
| 139 |
URI <- o.namespace.URI,
|
| 140 |
name <- o.namespace.name)
|
| 141 |
do {
|
| 142 |
n;
|
| 143 |
}
|
| 144 |
}
|
| 145 |
|
| 146 |
-- ======================================================================
|
| 147 |
-- transformation rules end
|
| 148 |
-- ======================================================================
|