Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T2: Export of controlled vocabulary restrictions #228 #240

Merged
merged 8 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/common/checkers.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,28 @@
$listOfNotDefinedNamespaces"/>

</xsl:function>

<xd:doc>
<xd:desc>
This function checks whether an enumeration has a constraint level property (tag) assigned
and if its value is either "permissive" or "restrictive".

The function returns a boolean result:
- `true()` if tag exists with the expected property and value.
- `false()` if no matching tag is found or if the enumeration has no tags.
</xd:desc>
<xd:param name="enumeration"/>
</xd:doc>
<xsl:function name="f:hasEnumerationAConstraintLevelProperty" as="xs:boolean">
<xsl:param name="enumeration" as="element()"/>

<xsl:variable name="enumerationTags" select="f:getElementTags($enumeration)"/>

<xsl:sequence select="
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

some $tag in $enumerationTags
satisfies ($tag/@name = $cvConstraintLevelProperty and $tag/@value = ('permissive', 'restrictive'))
"/>
</xsl:function>



Expand Down
28 changes: 28 additions & 0 deletions src/html-conventions-lib/enumeration-html-conventions.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@
<xsl:call-template name="enumerationOutgoingConnectors">
<xsl:with-param name="enumeration" select="."/>
</xsl:call-template>

<xsl:call-template name="enumerationConstraintLevel">
<xsl:with-param name="enumeration" select="."/>
</xsl:call-template>
<!-- End of specific checker rules-->

</xsl:variable>
Expand Down Expand Up @@ -202,6 +206,30 @@
"
/>
</xsl:template>

<xd:doc>
<xd:desc>[enumeration-constraint-level-4] he enumeration $value$ does not have a correct constraint level (either permissive or restrictive) set as a tag
with the $cvConstraintLevelProperty$ key. The permissive level will be used as a fallback value. </xd:desc>
<xd:param name="enumeration"/>
</xd:doc>

<xsl:template name="enumerationConstraintLevel">
<xsl:param name="enumeration"/>
<xsl:sequence
select="
if (not(f:hasEnumerationAConstraintLevelProperty($enumeration))) then
f:generateWarningMessage(fn:concat('The enumeration ', $enumeration/@name,
' does not have a correct constraint level (either permissive or restrictive) set as a tag with the ', $cvConstraintLevelProperty, ' key. The permissive level will be used as a fallback value.'),
path($enumeration),
'enumeration-constraint-level-4',
'',
''
)
else
()
"
/>
</xsl:template>



Expand Down
2 changes: 1 addition & 1 deletion src/owl-core-lib/descriptors-owl-core.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<xsl:param name="tagName"/>
<xsl:param name="tagValue"/>
<xsl:param name="elementUri"/>
<xsl:if test="not($tagName = $statusProperty)">
<xsl:if test="not($tagName = $excludedTagNamesList)">
<rdf:Description rdf:about="{$elementUri}">
<xsl:choose>
<xsl:when test="fn:contains($tagName, '@')">
Expand Down
115 changes: 113 additions & 2 deletions src/shacl-shape-lib/elements-shacl-shape.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,122 @@
</rdf:Description>
</xsl:if>
</xsl:template>

<xd:doc>
<xd:desc>Rule D.06. Enumeration item — Specify a restrictive SHACL NodeShape for items of an enumeration
for each UML Enumeration in the defining mode (based on the constraint level set for the UML Enumeration
as defined in rule:enumeration-constraint-level). The URIs of the node shape is deterministically generated
from the UML Enumeration name. Set a constraint for the enumeration item belonging to a concept scheme
represented by the enumeration URI.</xd:desc>
<xd:param name="enumeration"/>
</xd:doc>
<xsl:template name="enumerationItem">
<xsl:param name="enumeration"/>

<!-- Get the enumeration's compact URI -->
<xsl:variable name="enumerationCompactURI" select="$enumeration/@name"/>

<xsl:if test="$enumerationCompactURI and $enableGenerationOfSkosConcept">
<xsl:variable name="shapeURI" select="f:buildPropertyShapeURI($enumerationCompactURI, 'itemShape')"/>
<xsl:variable name="inSchemeURI" select="f:buildURIfromLexicalQName($enumerationCompactURI)"/>

<rdf:Description rdf:about="{$shapeURI}">
<rdf:type rdf:resource="http://www.w3.org/ns/shacl#NodeShape"/>
<sh:property rdf:parseType="Resource">
<sh:path rdf:resource="http://www.w3.org/2004/02/skos/core#inScheme"/>
<sh:hasValue rdf:resource="{$inSchemeURI}"/>
</sh:property>
</rdf:Description>
</xsl:if>
</xsl:template>

<xd:doc>
<xd:desc>
Rule R.13. Dependency range shape — Within the SHACL PropertyShape corresponding to a dependency relation
linked to a given source UML Class, constraint the range of the dependency.
Specify the suitable constraint based on the constraint level set for the UML Enumeration

* permissive: set skos:Concept as the expected type of an enumeration item

* restrictive: refer to a NodeShape for an enumeration item that further restricts allowed values
</xd:desc>
<xd:param name="enumeration"/>
</xd:doc>
<xsl:template name="enumerationDependencyRangeShape">
<xsl:param name="enumeration"/>

<!-- Root element and enumeration tags -->
<xsl:variable name="root" select="root($enumeration)"/>
<xsl:variable name="enumerationTags" select="f:getElementTags($enumeration)"/>

<!-- Get the enumeration's compact URI -->
<xsl:variable name="enumerationCompactURI" select="$enumeration/@name"/>

<!-- Determine the constraint level, defaulting to 'permissive' -->
<xsl:variable name="enumerationConstraintLevel"
select="
if (some $tag in $enumerationTags satisfies $tag/@name = $cvConstraintLevelProperty)
then ($enumerationTags[@name = $cvConstraintLevelProperty][1]/@value)
else 'permissive'
"/>

<!-- Retrieve all dependency IDs -->

<xsl:variable name="dependenciesIds" select="$enumeration/links/Dependency/@xmi:id"/>

<!-- Generate RDF descriptions based on the constraint level -->
<xsl:choose>
<xsl:when test="$enumerationConstraintLevel = 'restrictive' and $enableGenerationOfSkosConcept">
<!-- Iterate over dependencies -->

<xsl:variable name="nodeUri" select="f:buildPropertyShapeURI($enumerationCompactURI, 'itemShape')"/>
<xsl:for-each select="$dependenciesIds">
<xsl:variable name="dependencyConnector" select="f:getConnectorByIdRef(., $root)"/>
<xsl:variable name="dependencyName" select="$dependencyConnector/target/role/@name"/>
<xsl:variable name="sourceClassName" select="$dependencyConnector/source/model/@name"/>
<xsl:variable name="shapeUriClassDependency"
select="f:buildPropertyShapeURI($sourceClassName, $dependencyName)"/>

<rdf:Description rdf:about="{$shapeUriClassDependency}">
<rdf:type rdf:resource="http://www.w3.org/ns/shacl#PropertyShape"/>
<sh:path rdf:resource="{f:buildURIfromLexicalQName($dependencyName)}"/>
<sh:node rdf:resource="{$nodeUri}"/>
</rdf:Description>
</xsl:for-each>

</xsl:when>
<xsl:when test="$enumerationConstraintLevel = 'permissive' and $enableGenerationOfSkosConcept">
<!-- Generate shapes for permissive or default cases -->
<xsl:for-each select="$dependenciesIds">
<xsl:variable name="dependencyConnector" select="f:getConnectorByIdRef(., $root)"/>
<xsl:variable name="dependencyName" select="$dependencyConnector/target/role/@name"/>
<xsl:variable name="sourceClassName" select="$dependencyConnector/source/model/@name"/>
<xsl:variable name="shapeUriClassDependency"
select="f:buildPropertyShapeURI($sourceClassName, $dependencyName)"/>

<rdf:Description rdf:about="{$shapeUriClassDependency}">
<rdf:type rdf:resource="http://www.w3.org/ns/shacl#PropertyShape"/>
<sh:path rdf:resource="{f:buildURIfromLexicalQName($dependencyName)}"/>
<sh:class rdf:resource="http://www.w3.org/2004/02/skos/core#Concept"/>
</rdf:Description>
</xsl:for-each>
</xsl:when>
</xsl:choose>
</xsl:template>

<xd:doc>
<xd:desc>This will override the common selector when applying templates</xd:desc>
<xd:desc>Applying shape layer rules to Enumeration dependencies and items</xd:desc>
</xd:doc>
<xsl:template match="element[@xmi:type = 'uml:Enumeration']"/>
<xsl:template match="element[@xmi:type = 'uml:Enumeration']">
<xsl:if test="not(f:isExcludedByStatus(.))">
<xsl:call-template name="enumerationItem">
<xsl:with-param name="enumeration" select="."/>
</xsl:call-template>
<xsl:call-template name="enumerationDependencyRangeShape">
<xsl:with-param name="enumeration" select="."/>
</xsl:call-template>
</xsl:if>
</xsl:template>

<xd:doc>
<xd:desc>This will override the common selector when applying templates</xd:desc>
Expand Down
6 changes: 6 additions & 0 deletions test/ePO-default-config/config-parameters.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@

<!-- This variable controls whether the enumerations are transformed into skos schemes or ignored-->
<xsl:variable name="enableGenerationOfConceptSchemes" select="fn:false()"/>

<!-- Property used for constraint level for enumerations-->
<xsl:variable name="cvConstraintLevelProperty" select="'epo:constraintLevel'"/>


<!--Allowed characters for a normalized string-->
Expand All @@ -85,6 +88,9 @@
<xsl:variable name="commentsGeneration" select="fn:true()"/>
<xsl:variable name="commentProperty" select="'skos:editorialNote'"/>

<!-- Tag names/keys that are excluded from output -->
<xsl:variable name="excludedTagNamesList" select="($statusProperty, $cvConstraintLevelProperty)"/>

<!-- Variables for status filtering -->
<xsl:variable name="statusProperty" select="'epo:status'"/>
<xsl:variable name="validStatusesList" select="('proposed', 'approved', 'implemented')"/>
Expand Down
Loading