-- @atlcompiler atl2006 -- $Id: ECORE2OWL.atl 7823 2008-12-10 09:33:51Z dwagelaa $ -- Translates Ecore to OWL module ECORE2OWL; create OUT : OWL from IN : ECORE; uses TransientLinks; -- ====================================================================== -- helper attributes begin -- ====================================================================== helper def : ECORE2OWLVersionString : String = '$Id: ECORE2OWL.atl 7823 2008-12-10 09:33:51Z dwagelaa $'; helper def : inElements : Set(ECORE!"ecore::EObject") = ECORE!"ecore::EObject".allInstancesFrom('IN'); helper def : allElements : Set(ECORE!"ecore::EObject") = ECORE!"ecore::EObject".allInstances(); helper def : allEEnums : Set(ECORE!"ecore::EEnum") = ECORE!"ecore::EEnum".allInstances(); helper def : otherElements : Set(ECORE!"ecore::EObject") = thisModule.allElements->reject(e|thisModule.inElements->includes(e)); helper context ECORE!"ecore::EClassifier" def : xsdTypeName : String = let type : String = self.instanceTypeName in if type = 'int' or type = 'float' or type = 'boolean' or type = 'double' or type = 'byte' or type = 'short' then type else if type = 'java.lang.String' then 'string' else if type = 'java.util.Date' then 'date' else if type = 'char' then 'unsignedByte' else if type = 'java.lang.Integer' then 'int' else if type = 'java.lang.Float' then 'float' else if type = 'java.lang.Boolean' then 'boolean' else if type = 'java.lang.Double' then 'double' else if type = 'java.lang.Byte' then 'byte' else if type = 'java.lang.Short' then 'short' else if type = 'java.lang.Character' then 'unsignedByte' else if type = 'java.math.BigDecimal' then 'decimal' else if type = 'java.math.BigInteger' then 'integer' else 'anySimpleType' endif endif endif endif endif endif endif endif endif endif endif endif endif; -- ====================================================================== -- helper attributes end -- ====================================================================== -- ====================================================================== -- transformation rules begin -- ====================================================================== rule EPackage { from s : ECORE!"ecore::EPackage" (thisModule.inElements->includes(s)) using { otherPackages : Set(ECORE!"ecore::EPackage") = thisModule.otherElements->select(e|e.oclIsKindOf(ECORE!"ecore::EPackage")); } to n : OWL!"rdfs::Namespace" ( name <- 'DEFAULT', URI <- s.nsURI + '#'), ont : OWL!"owl::OWLOntology" ( localName <- '', namespace <- n, RDFSLabel <- Sequence{label}, RDFSComment <- Sequence{comment}, ownedNamespace <- Set{n, thisModule.XSDNamespace('xsd')}->union(otherPackages), contains <- Set{label, comment, allContainment, allContainer, containment, container, thisModule.XSDType('Name')} ->union(thisModule.allElements->reject(e|e.oclIsKindOf(ECORE!"ecore::EPackage"))) ->union(thisModule.allEEnums->collect(e|thisModule.resolveTemp(e, 'dr')).debug('allEEnums')) ->union(otherPackages->collect(p|p.mapstoOfKind(OWL!"rdfs::RDFSResource"))->flatten())), label : OWL!"rdfs::PlainLiteral" ( language <- 'en', lexicalForm <- s.name), comment : OWL!"rdfs::PlainLiteral" ( language <- 'en', lexicalForm <- 'Generated by ECORE2OWL' + thisModule.ECORE2OWLVersionString), allContainment : OWL!"owl::OWLObjectProperty" ( localName <- 'allContainment', OWLInverseOf <- allContainer, transitive <- true, namespace <- n), allContainer : OWL!"owl::OWLObjectProperty" ( localName <- 'allContainer', transitive <- true, namespace <- n), containment : OWL!"owl::OWLObjectProperty" ( localName <- 'containment', OWLInverseOf <- container, inverseFunctional <- true, RDFSSubPropertyOf <- allContainment, namespace <- n), container : OWL!"owl::OWLObjectProperty" ( localName <- 'container', functional <- true, RDFSSubPropertyOf <- allContainer, namespace <- n) } rule EClass { from s : ECORE!"ecore::EClass" to t : OWL!"owl::OWLClass" ( localName <- s.name.debug('EClass'), RDFSSubClassOf <- s.eSuperTypes, namespace <- s.ePackage) } rule EDataType { from s : ECORE!"ecore::EDataType" (s.oclIsTypeOf(ECORE!"ecore::EDataType")) to t : OWL!"rdfs::RDFSDatatype" ( localName <- s.xsdTypeName, namespace <- thisModule.XSDNamespace('xsd')) } rule EAttribute { from s : ECORE!"ecore::EAttribute" ( if not s.eContainingClass.oclIsUndefined() then -- some EAttributes are stored under EAnnotations not s.eType.oclIsKindOf(ECORE!"ecore::EEnum") else false endif) to t : OWL!"owl::OWLDatatypeProperty" ( localName <- s.eContainingClass.name + '_' + s.name, functional <- (s.upperBound = 1), RDFSDomain <- s.eContainingClass, RDFSRange <- s.eType, namespace <- s.eContainingClass.ePackage) } rule EAttribute_EEnum { from s : ECORE!"ecore::EAttribute" ( if not s.eContainingClass.oclIsUndefined() then -- some EAttributes are stored under EAnnotations s.eType.oclIsKindOf(ECORE!"ecore::EEnum") else false endif) to t : OWL!"owl::OWLDatatypeProperty" ( localName <- s.eContainingClass.name + '_' + s.name, functional <- (s.upperBound = 1), RDFSSubPropertyOf <- s.eType, RDFSDomain <- s.eContainingClass, namespace <- s.eContainingClass.ePackage) } rule EReference { from s : ECORE!"ecore::EReference" ( not s.eContainingClass.oclIsUndefined()) -- some EReferences are stored under EAnnotations to t : OWL!"owl::OWLObjectProperty" ( localName <- s.eContainingClass.name + '_' + s.name, functional <- (s.upperBound = 1), RDFSDomain <- s.eContainingClass, RDFSRange <- s.eType, OWLInverseOf <- s.eOpposite, RDFSSubPropertyOf <- if s.containment then Sequence{thisModule.resolveTemp(s.eContainingClass.ePackage, 'containment')} else if s.container then Sequence{thisModule.resolveTemp(s.eContainingClass.ePackage, 'container')} else Sequence{} endif endif, namespace <- s.eContainingClass.ePackage) } rule EEnum { from s : ECORE!"ecore::EEnum" to t : OWL!"owl::OWLDatatypeProperty" ( localName <- s.name, RDFSRange <- dr, namespace <- s.ePackage), dr : OWL!"owl::OWLDataRange" ( OWLOneOf <- s.eLiterals, namespace <- s.ePackage) } rule EEnumLiteral { from s : ECORE!"ecore::EEnumLiteral" to t : OWL!"rdfs::TypedLiteral" ( lexicalForm <- s.literal, datatype <- thisModule.XSDType('Name'), namespace <- s.eEnum.ePackage) } unique lazy rule XSDType { from s : String to t : OWL!"rdfs::RDFSDatatype" ( localName <- s, namespace <- thisModule.XSDNamespace('xsd')) } unique lazy rule XSDNamespace { from s : String to t : OWL!"rdfs::Namespace" ( name <- s, URI <- 'http://www.w3.org/2001/XMLSchema#') } -- ====================================================================== -- transformation rules end -- ======================================================================