Skip to content

Commit

Permalink
rule for floating comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragos0000 committed Aug 2, 2023
1 parent 3175d7e commit 121e0ae
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 12 deletions.
8 changes: 8 additions & 0 deletions src/common/selectors.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
<xsl:template match="xmi:XMI">
<xsl:apply-templates select="/xmi:XMI/xmi:Extension/elements"/>
<xsl:apply-templates select="/xmi:XMI/xmi:Extension/connectors"/>
<xsl:apply-templates select="/xmi:XMI/uml:Model/packagedElement//ownedComment"/>
</xsl:template>

<xd:doc>
<xd:desc>This template target floating comments in the model</xd:desc>
</xd:doc>
<xsl:template match="ownedComment">
<xsl:apply-templates select="ownedComment[@xmi:type='uml:Comment']"/>
</xsl:template>

<xd:doc>
Expand Down
2 changes: 1 addition & 1 deletion src/owl-core-lib/connectors-owl-core.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
<xsl:with-param name="elementUri" select="$roleURI"/>
</xsl:call-template>
</xsl:if>
<!-- TODO ADD COMMENT RULE T05-->

<xsl:call-template name="coreDefinedBy">
<xsl:with-param name="elementUri" select="$roleURI"/>
</xsl:call-template>
Expand Down
6 changes: 3 additions & 3 deletions src/owl-core-lib/descriptors-owl-core.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</xsl:template>

<xd:doc>
<xd:desc>Rule T.05. Comment - Specify annotation axiom for UML Comment associated to a UML
<xd:desc>Rule T.06. Comment - Specify annotation axiom for UML Comment associated to a UML
element</xd:desc>
<xd:param name="comment"/>
<xd:param name="elementUri"/>
Expand All @@ -64,9 +64,9 @@
<xsl:param name="comment"/>
<xsl:param name="elementUri"/>
<rdf:Description rdf:about="{$elementUri}">
<rdfs:comment xml:lang="en">
<skos:editorialNote xml:lang="en">
<xsl:value-of select="$comment"/>
</rdfs:comment>
</skos:editorialNote>
</rdf:Description>
</xsl:template>

Expand Down
81 changes: 73 additions & 8 deletions src/owl-core-lib/elements-owl-core.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,74 @@
<xsl:output method="xml" encoding="UTF-8" byte-order-mark="no" indent="yes"
cdata-section-elements="lines"/>

<xd:doc>
<xd:desc> Rule T.05. Comment — in core ontology layer. Specify an annotation axiom (comment or editorial note)
on the OWL entity for the UML Comment associated to a UML element.
Selector to run core layer transfomation rules for commnents </xd:desc>
</xd:doc>
<xsl:template match="ownedComment[@xmi:type='uml:Comment']">
<xsl:variable name="commentText" select="./@body"/>
<xsl:for-each select="./annotatedElement/@xmi:idref">
<xsl:variable name="elementFound" select="f:getElementByIdRef(.,root(.))"/>
<xsl:if test="boolean($elementFound)">
<xsl:variable name="elementUri" select="f:buildURIFromElement($elementFound)"/>
<xsl:call-template name="coreLayerComment">
<xsl:with-param name="elementUri" select="$elementUri"/>
<xsl:with-param name="comment" select="$commentText"/>
</xsl:call-template>
</xsl:if>
<xsl:variable name="connectorFound" select="f:getConnectorByIdRef(.,root(.))"/>
<xsl:if test="fn:boolean($connectorFound)">
<xsl:variable name="connectorDirection"
select="$connectorFound/properties/@direction"/>
<xsl:choose>
<xsl:when test="$connectorDirection = 'Source -&gt; Destination'">
<xsl:variable name="connectorTargetRoleUri"
select="
if ($connectorFound/target/role/not(@name) = fn:true()) then
()
else
f:buildURIfromLexicalQName($connectorFound/target/role/@name)"/>
<xsl:if test="boolean($connectorTargetRoleUri)">
<xsl:call-template name="coreLayerComment">
<xsl:with-param name="elementUri" select="$connectorTargetRoleUri"/>
<xsl:with-param name="comment" select="$commentText"/>
</xsl:call-template>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="connectorTargetRoleUri"
select="
if ($connectorFound/target/role/not(@name) = fn:true()) then
()
else
f:buildURIfromLexicalQName($connectorFound/target/role/@name)"/>
<xsl:variable name="connectorSourceRoleUri"
select="
if ($connectorFound/source/role/not(@name) = fn:true()) then
()
else
f:buildURIfromLexicalQName($connectorFound/source/role/@name)"/>
<xsl:if test="boolean($connectorSourceRoleUri)">
<xsl:call-template name="coreLayerComment">
<xsl:with-param name="elementUri" select="$connectorSourceRoleUri"/>
<xsl:with-param name="comment" select="$commentText"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="boolean($connectorTargetRoleUri)">
<xsl:call-template name="coreLayerComment">
<xsl:with-param name="elementUri" select="$connectorTargetRoleUri"/>
<xsl:with-param name="comment" select="$commentText"/>
</xsl:call-template>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</xsl:template>




<xd:doc>
<xd:desc> Selector to run core layer transformation rules for classes</xd:desc>
Expand Down Expand Up @@ -68,8 +136,7 @@
<xsl:with-param name="elementUri" select="$classURI"/>
</xsl:call-template>
</xsl:if>
<!-- TODO ADD COMMENT RULE T05-->


<xsl:call-template name="coreDefinedBy">
<xsl:with-param name="elementUri" select="$classURI"/>
</xsl:call-template>
Expand Down Expand Up @@ -182,7 +249,6 @@
</xsl:call-template>
</xsl:if>

<!-- TODO ADD COMMENT RULE T05-->

<xsl:call-template name="coreDefinedBy">
<xsl:with-param name="elementUri" select="$attributeURI"/>
Expand Down Expand Up @@ -248,7 +314,6 @@
<xsl:with-param name="elementUri" select="$dataTypeURI"/>
</xsl:call-template>
</xsl:if>
<!-- TODO ADD COMMENT RULE T05-->

<xsl:call-template name="coreDefinedBy">
<xsl:with-param name="elementUri" select="$dataTypeURI"/>
Expand Down Expand Up @@ -285,7 +350,7 @@
<xsl:with-param name="elementUri" select="$conceptSchemeURI"/>
</xsl:call-template>
</xsl:if>
<!-- TODO ADD COMMENT RULE T05-->


<xsl:call-template name="coreDefinedBy">
<xsl:with-param name="elementUri" select="$conceptSchemeURI"/>
Expand All @@ -304,7 +369,7 @@
<xsl:with-param name="elementUri" select="$conceptSchemeURI"/>
</xsl:call-template>
</xsl:if>
<!-- TODO ADD COMMENT RULE T05-->


<xsl:call-template name="coreDefinedBy">
<xsl:with-param name="elementUri" select="$conceptSchemeURI"/>
Expand Down Expand Up @@ -351,7 +416,7 @@
<xsl:with-param name="elementUri" select="$enumerationAttributeURI"/>
</xsl:call-template>
</xsl:if>
<!-- TODO ADD COMMENT RULE T05-->


<xsl:call-template name="coreDefinedBy">
<xsl:with-param name="elementUri" select="$enumerationAttributeURI"/>
Expand All @@ -374,7 +439,7 @@
<xsl:with-param name="elementUri" select="$enumerationAttributeURI"/>
</xsl:call-template>
</xsl:if>
<!-- TODO ADD COMMENT RULE T05-->


<xsl:call-template name="coreDefinedBy">
<xsl:with-param name="elementUri" select="$enumerationAttributeURI"/>
Expand Down
75 changes: 75 additions & 0 deletions src/shacl-shape-lib/elements-shacl-shape.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,81 @@

<xsl:output method="xml" encoding="UTF-8" byte-order-mark="no" indent="yes"
cdata-section-elements="lines"/>


<xd:doc>
<xd:desc> Rule T.06. Comment — in data shape layer. Specify an annotation axiom (comment or description)
on the SHACL shape for the UML Comment associated to a UML element.
Selector to run core layer transfomation rules for commnents </xd:desc>
</xd:doc>
<xsl:template match="ownedComment[@xmi:type='uml:Comment']">
<xsl:variable name="commentText" select="./@body"/>
<xsl:for-each select="./annotatedElement/@xmi:idref">
<xsl:variable name="elementFound" select="f:getElementByIdRef(.,root(.))"/>
<xsl:if test="boolean($elementFound)">
<xsl:variable name="elementUri" select="f:buildShapeURI($elementFound/@name)"/>
<xsl:call-template name="shapeLayerComment">
<xsl:with-param name="uri" select="$elementUri"/>
<xsl:with-param name="rdfsComment" select="fn:true()"/>
<xsl:with-param name="comment" select="$commentText"/>
</xsl:call-template>
</xsl:if>
<xsl:variable name="connectorFound" select="f:getConnectorByIdRef(.,root(.))"/>
<xsl:if test="fn:boolean($connectorFound)">
<xsl:variable name="connectorDirection"
select="$connectorFound/properties/@direction"/>
<xsl:choose>
<xsl:when test="$connectorDirection = 'Source -&gt; Destination'">
<xsl:variable name="connectorShapeUri"
select="
if ($connectorFound/target/role/not(@name) = fn:true()) then
()
else
f:buildPropertyShapeURI($connectorFound/source/model/@name,$connectorFound/target/role/@name)"/>
<xsl:if test="boolean($connectorShapeUri)">
<xsl:call-template name="shapeLayerComment">
<xsl:with-param name="uri" select="$connectorShapeUri"/>
<xsl:with-param name="comment" select="$commentText"/>
<xsl:with-param name="rdfsComment" select="fn:false()"/>
</xsl:call-template>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="connectorTargetRoleShapeUri"
select="
if ($connectorFound/target/role/not(@name) = fn:true()) then
()
else
f:buildPropertyShapeURI($connectorFound/source/model/@name,$connectorFound/target/role/@name)"/>
<xsl:variable name="connectorSourceRoleShapeUri"
select="
if ($connectorFound/source/role/not(@name) = fn:true()) then
()
else
f:buildPropertyShapeURI($connectorFound/target/model/@name,$connectorFound/source/role/@name)"/>
<xsl:if test="boolean($connectorSourceRoleShapeUri)">
<xsl:call-template name="shapeLayerComment">
<xsl:with-param name="uri" select="$connectorSourceRoleShapeUri"/>
<xsl:with-param name="comment" select="$commentText"/>
<xsl:with-param name="rdfsComment" select="fn:false()"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="boolean($connectorTargetRoleShapeUri)">
<xsl:call-template name="shapeLayerComment">
<xsl:with-param name="uri" select="$connectorTargetRoleShapeUri"/>
<xsl:with-param name="comment" select="$commentText"/>
<xsl:with-param name="rdfsComment" select="fn:false()"/>
</xsl:call-template>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:for-each>
</xsl:template>






<xd:doc>
Expand Down
10 changes: 10 additions & 0 deletions test/unitTests/test-owl-core-lib/test-elements-owl-core.xspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@
xmlns:skos="http://www.w3.org/2004/02/skos/core#"
stylesheet="../../../src/owl-core-lib/elements-owl-core.xsl">


<x:scenario label="Scenario for testing template with match 'ownedComment[@xmi:type='uml:Comment']">
<x:context href="../../testData/ePO_CM-v.4.0.0.xml" select="/xmi:XMI/uml:Model[1]/packagedElement[1]/packagedElement[1]/packagedElement[39]/packagedElement[1]/ownedComment[1]"/>
<x:expect label="there is a rdf:Description" test="boolean(/rdf:Description)"/>
<x:expect label="there is 2 rdf:Description" test="count(/rdf:Description) = 2 "/>
<x:expect label="there is a skos:editorialNote" test="boolean(/rdf:Description/skos:editorialNote)"/>
<x:expect label="there is a correct URI" test="/rdf:Description/@rdf:about = 'http://data.europa.eu/a4g/ontology#hasAwardedValue'"/>
<x:expect label="there is a correct URI" test="/rdf:Description[2]/@rdf:about = 'http://data.europa.eu/a4g/ontology#hasAwardedEstimatedValue'"/>
</x:scenario>


<x:scenario label="Scenario for testing template with match 'element[@xmi:type = 'uml:Class'] with a comment">
<x:context href="../../testData/ePO-CM_v.3.0.1.eap.xmi" select="/xmi:XMI/xmi:Extension[1]/elements[1]/element[55]"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,17 @@
<x:expect label="there is sh:description" test="boolean(rdf:Description/sh:description)"/>
<x:expect label="there is no rdfs:comment" test="not(boolean(rdf:Description/rdfs:comment))"/>


</x:scenario>


<x:scenario label="Scenario for testing template with match 'ownedComment[@xmi:type='uml:Comment']">
<x:context href="../../testData/ePO_CM-v.4.0.0.xml" select="/xmi:XMI/uml:Model[1]/packagedElement[1]/packagedElement[1]/packagedElement[39]/packagedElement[1]/ownedComment[1]"/>
<x:expect label="dddd" select="''"/>
<x:expect label="there is a rdf:Description" test="boolean(/rdf:Description)"/>
<x:expect label="there is 2 rdf:Description" test="count(/rdf:Description) = 2 "/>
<x:expect label="there is a sh:description" test="boolean(/rdf:Description/sh:description)"/>
<x:expect label="there is a correct URI" test="/rdf:Description/@rdf:about = 'http://data.europa.eu/a4g/data-shape#epo-LotAwardOutcome-epo-hasAwardedValue'"/>
<x:expect label="there is a correct URI" test="/rdf:Description[2]/@rdf:about = 'http://data.europa.eu/a4g/data-shape#epo-LotAwardOutcome-epo-hasAwardedEstimatedValue'"/>
</x:scenario>
</x:description>

0 comments on commit 121e0ae

Please sign in to comment.