Skip to content

Commit 9e77424

Browse files
authored
Merge pull request #322 from eclipse-esmf/52-allow-description-of-enumeration-values
Add new Value type
2 parents 993fe6d + 5571750 commit 9e77424

File tree

15 files changed

+421
-40
lines changed

15 files changed

+421
-40
lines changed

documentation/modules/ROOT/examples/aspect-sample.ttl

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,82 @@
109109
samm-c:values ( "2010-01-01"^^xsd:date "2012-05-07"^^xsd:date "2018-03-08"^^xsd:date ) .
110110
# end::enumeration-simple-declaration-date[]
111111

112+
# tag::value-declaration[]
113+
:GreenLight a samm:Value ;
114+
samm:value "green" ;
115+
samm:preferredName "Normal"@en ;
116+
samm:description "Indicates that the speed of position change is within specification."@en ;
117+
samm:see <https://en.wikipedia.org/wiki/Traffic_light> .
118+
# end::value-declaration[]
119+
120+
# tag::value-in-example-value-additional[]
121+
:warningLevelProperty a samm:Property ;
122+
samm:exampleValue :GreenLight ;
123+
samm:characteristic [
124+
a samm:Characteristic ;
125+
samm:dataType xsd:string ;
126+
] .
127+
128+
:GreenLight a samm:Value ;
129+
samm:value "green" ;
130+
samm:preferredName "Normal"@en ;
131+
samm:description "Indicates that the speed of position change is within specification."@en ;
132+
samm:see <https://en.wikipedia.org/wiki/Traffic_light> .
133+
# end::value-in-example-value-additional[]
134+
135+
# tag::value-in-example-value-anonymous[]
136+
:propertyWithExampleValue a samm:Property ;
137+
samm:exampleValue [
138+
a samm:Value ;
139+
samm:description "Some Description"@en ;
140+
samm:value 2 ;
141+
] ;
142+
samm:characteristic [
143+
a samm:Characteristic ;
144+
samm:dataType xsd:integer ;
145+
] .
146+
# end::value-in-example-value-anonymous[]
147+
148+
# tag::enumeration-value-type-is-value-reference[]
149+
:TrafficLight a samm-c:Enumeration ;
150+
samm:name "TrafficLight" ;
151+
samm:preferredName "Warning Level"@en ;
152+
samm:description "Represents if speed of position change is within specification (green), within tolerance (yellow), or outside specification (red)."@en ;
153+
samm:dataType xsd:string ;
154+
samm-c:values ( :GreenLight ) .
155+
156+
:GreenLight a samm:Value ;
157+
samm:value "green" ;
158+
samm:preferredName "Normal"@en ;
159+
samm:description "Indicates that the speed of position change is within specification."@en ;
160+
samm:see <https://en.wikipedia.org/wiki/Traffic_light> .
161+
# end::enumeration-value-type-is-value-reference[]
162+
163+
# tag::enumeration-value-type-in-value-mixed-instance[]
164+
:TrafficLight a samm-c:Enumeration ;
165+
samm:name "TrafficLight" ;
166+
samm:preferredName "Warning Level"@en ;
167+
samm:description "Represents if speed of position change is within specification (green), within tolerance (yellow), or outside specification (red)."@en ;
168+
samm:dataType xsd:string ;
169+
samm-c:values (
170+
:GreenLight # A reference to named described scalar value
171+
"yellow" # A direct literal value
172+
[
173+
a samm:Value ; # An anonymous described scalar value with additional metadata
174+
samm:value "red" ;
175+
samm:preferredName "Critical Warning"@en ;
176+
samm:description "Indicates that the position change is outside the specification."@en
177+
]
178+
) .
179+
180+
:GreenLight a samm:Value ;
181+
samm:value "green" ;
182+
samm:preferredName "Normal"@en ;
183+
samm:description "Indicates that the speed of position change is within specification."@en ;
184+
samm:see <https://en.wikipedia.org/wiki/Traffic_light> .
185+
186+
# end::enumeration-value-type-in-value-mixed-instance[]
187+
112188
# tag::enumeration-complex-declaration[]
113189
:Results a samm-c:Enumeration ;
114190
samm:dataType :Result ;

documentation/modules/ROOT/pages/modeling-guidelines.adoc

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,22 +162,30 @@ that all model elements have], Properties have the following attributes:
162162
| Attributes | Description | Required
163163
| `samm:characteristic` | The xref:characteristics.adoc#characteristics[Characteristic] describing
164164
this Property. | {ok}
165-
| `samm:exampleValue` | An exemplary value the Property can take on that helps to understand the
166-
intended meaning of the property better. This can only be set for Properties with scalar data types
167-
(e.g., `xsd:string` or `xsd:float`, but not Entities). The data type of the `samm:exampleValue` must
168-
be convertible to the effective data type of the Property's Characteristic. For example, if the
169-
Characteristic's `samm:dataType` is `xsd:int`, `xsd:short` is also a valid type for the
170-
`samm:exampleValue`. Refer to section xref:datatypes.adoc#implicit-conversions[Implicit Conversions]
165+
| `samm:exampleValue` | An exemplary value that the Property can take, helping to clarify the intended meaning of the Property.
166+
This attribute supports both scalar literal values (e.g., xsd:string, xsd:float), an anonymous described scalar value,
167+
and value references that point to example values (i.e., references to instances of xref:modeling-guidelines.adoc#value-type[samm:Value]).
168+
In either case, the data type of the `samm:exampleValue` must be convertible to the effective data type defined by the Property's Characteristic.
169+
For example, if the Characteristic's `samm:dataType`
170+
is `xsd:int`, a value with the type `xsd:short` is also acceptable. Refer to section xref:datatypes.adoc#implicit-conversions[Implicit Conversions]
171171
for more details. | {nok}
172172
|===
173173

174-
Example:
174+
Example with Literal type:
175175

176176
[source,turtle,subs="attributes+"]
177177
----
178178
include::example$aspect-sample.ttl[tags=property-declaration]
179179
----
180180

181+
Example with value reference type:
182+
183+
[source,turtle,subs="attributes+"]
184+
----
185+
include::example$aspect-sample.ttl[tags=value-in-example-value-additional]
186+
----
187+
188+
181189
[[declaring-characteristics]]
182190
=== Declaring Characteristics
183191

@@ -304,6 +312,28 @@ Example with literal `xsd:date` values:
304312
include::example$aspect-sample.ttl[tags=enumeration-simple-declaration-date]
305313
----
306314

315+
[[enumeration-with-value-type-in-value]]
316+
Example Using Value in an Enumeration:
317+
318+
An Enumeration can include complex values to enrich the semantic description of the enumeration items.
319+
This is especially useful when you want to provide additional metadata—such as a preferred name, description,
320+
or external reference—for a specific value.
321+
322+
There are several ways to define values in an Enumeration:
323+
324+
- Value Reference example:
325+
[source,turtle,subs="attributes+"]
326+
----
327+
include::example$aspect-sample.ttl[tags=enumeration-value-type-is-value-reference]
328+
----
329+
330+
- Multiple (anonymous described scalar value and value reference) Value Definitions:
331+
[source,turtle,subs="attributes+"]
332+
----
333+
include::example$aspect-sample.ttl[tags=enumeration-value-type-in-value-mixed-instance]
334+
----
335+
336+
307337
[[enumeration-with-complex-value]]
308338
Example with complex values:
309339

@@ -742,6 +772,34 @@ for example:
742772
include::example$aspect-sample.ttl[tags=see-dontuse]
743773
----
744774

775+
[[value-type]]
776+
=== Declaring Value
777+
778+
The `samm:Value` type is designed to represent a value enriched with semantic metadata.
779+
It encapsulates the actual data (which can be a literal or a reference) along with additional descriptive information.
780+
This type is used to enhance clarity in Enumerations and Properties by allowing you to attach a human-readable label,
781+
a detailed description, and an external reference to the value.
782+
783+
[source,turtle,subs="attributes+"]
784+
----
785+
include::example$aspect-sample.ttl[tags=value-declaration]
786+
----
787+
788+
Also, as an ExampleValue in Property:
789+
790+
- Additional Value:
791+
[source,turtle,subs="attributes+"]
792+
----
793+
include::example$aspect-sample.ttl[tags=value-in-example-value-additional]
794+
----
795+
796+
- Anonymous ExampleValue:
797+
[source,turtle,subs="attributes+"]
798+
----
799+
include::example$aspect-sample.ttl[tags=value-in-example-value-anonymous]
800+
----
801+
802+
745803
[[optional-properties]]
746804
=== Optional Properties
747805

esmf-semantic-aspect-meta-model/src/main/resources/samm/characteristic/2.2.0/characteristic-shapes.ttl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,10 @@ samm-c:EnumerationShape
514514
$this samm-c:values ?values .
515515
$this samm:dataType ?definedDataType .
516516
?values rdf:rest*/rdf:first ?item .
517-
bind( datatype( ?item ) as ?literalDataType ) .
518-
bind( strlen( str( ?literalDataType ) ) as ?literalDataTypeLength ) .
519-
filter( ( ?literalDataType != ?definedDataType ) && ( ?literalDataTypeLength > 0 ) ) .
517+
optional { ?item a samm:Value ; samm:value ?innerValue . }
518+
bind( coalesce( datatype(?innerValue), datatype(?item) ) AS ?literalDataType ) .
519+
filter( strlen(str(?literalDataType)) > 0 ) .
520+
filter( ?literalDataType != ?definedDataType ) .
520521
bind( 'ERR_WRONG_DATATYPE' as ?code )
521522
bind( ?item as ?highlight )
522523
}

esmf-semantic-aspect-meta-model/src/main/resources/samm/meta-model/2.2.0/aspect-meta-model-definitions.ttl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ samm:Namespace rdfs:subClassOf mmm:NamedConcept ;
7777
rdfs:label "Namespace" ;
7878
rdfs:comment "A Namespace can provide a human-readable name and a description for namespaces." .
7979

80+
samm:Value rdfs:subClassOf mmm:ConceptWithProperties ;
81+
rdfs:label: "Value" ;
82+
rdfs:comment "A type is designed to represent a value enriched with semantic metadata.".
83+
8084
# Meta meta model attributes used in Shapes
8185
mmm:listType a rdf:Property ;
8286
rdfs:label "listType" ;
@@ -152,7 +156,7 @@ samm:parameters a mmm:Attribute ;
152156

153157
samm:exampleValue a mmm:Attribute ;
154158
rdfs:label "exampleValue" ;
155-
rdfs:comment "An exemplary value the Property can take on that helps to understand the intended meaning of the property better. This can only be set for Properties with scalar data types (e.g. xsd:string or xsd:float, but not Entities). The data type of the samm:exampleValue must be convertable to the effective data type of the Property’s Characteristic." ;
159+
rdfs:comment "An exemplary value the Property can take on that helps to understand the intended meaning of the property better. This attribute supports both scalar literal values (e.g., xsd:string or xsd:float), an anonymous described scalar value and value references example values (i.e., references to instances of samm:Value enriched with semantic metadata). The data type of the samm:exampleValue must be convertable to the effective data type of the Property’s Characteristic." ;
156160
rdfs:domain samm:Property ;
157161
rdfs:range rdfs:Resource .
158162

esmf-semantic-aspect-meta-model/src/main/resources/samm/meta-model/2.2.0/aspect-meta-model-shapes.ttl

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,24 +290,24 @@ samm:PropertyShape
290290
sh:minCount 1 ;
291291
sh:maxCount 1 ;
292292
sh:class samm:Characteristic ;
293-
sh:maxCount 1 ;
294293
sh:name "characteristic" ;
295294
sh:description "The Characteristic describing the semantics of the Property." ;
296295
] ;
297296
sh:property [
298297
sh:order 4 ;
299298
sh:path samm:exampleValue ;
300-
sh:nodeKind sh:Literal ;
301299
sh:sparql [
302300
a sh:SPARQLConstraint ;
303301
sh:message "The datatype '{?value}' of the exampleValue neither matches nor can be cast to the Property's '{$this}' Characteristic's dataType." ;
304302
sh:prefixes samm:prefixDeclarations ;
305303
sh:select """
306-
select $this ?value ?code ?highlight
304+
select $this ?value ?exampleValue ?providedType ?characteristicDataType ?code ?highlight
307305
where {
308306
$this samm:exampleValue ?exampleValue .
309307
$this samm:characteristic/samm-c:baseCharacteristic*/samm:dataType ?characteristicDataType .
310-
bind( datatype( ?exampleValue ) as ?providedType )
308+
optional { ?exampleValue a samm:Value ; samm:value ?innerValue . }
309+
bind( coalesce(?innerValue, ?exampleValue) as ?actualValue )
310+
bind( datatype(?actualValue) as ?providedType )
311311
filter( ?providedType not in (
312312
xsd:string,
313313
xsd:boolean,
@@ -374,8 +374,10 @@ samm:PropertyShape
374374
select $this ?exampleValue ?code
375375
where {
376376
$this samm:exampleValue ?exampleValue .
377-
bind( datatype( ?exampleValue ) as ?providedType )
378-
filter ( ?providedType = xsd:boolean && ( str( ?exampleValue ) != "true" && str( ?exampleValue ) != "false" ) )
377+
optional { ?exampleValue a samm:Value ; samm:value ?innerValue . }
378+
bind( coalesce(?innerValue, ?exampleValue) as ?actualValue )
379+
bind( datatype(?actualValue) as ?providedType )
380+
filter ( ?providedType = xsd:boolean && ( str(?actualValue) != "true" && str(?actualValue) != "false" ) )
379381
bind('ERR_EXAMPLE_VALUE_NOT_ALLOWED' AS ?code)
380382
}
381383
"""
@@ -1024,3 +1026,14 @@ samm:ConstrainListTypeUsageShape
10241026
"""
10251027
]
10261028
] .
1029+
1030+
samm:ValueShape
1031+
a sh:NodeShape ;
1032+
sh:targetClass samm:Value ;
1033+
sh:property [
1034+
sh:path samm:value ;
1035+
sh:minCount 1 ;
1036+
sh:maxCount 1 ;
1037+
sh:name "value" ;
1038+
sh:description "A single constant value or link to another resource." ;
1039+
] .

esmf-semantic-aspect-meta-model/src/test/java/org/eclipse/esmf/samm/AbstractShapeTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ protected static Stream<KnownVersion> versionsUpToIncluding1_0_0() {
6868
return versionsUpToIncluding( KnownVersion.SAMM_1_0_0 );
6969
}
7070

71+
protected static Stream<KnownVersion> versionsUpToIncluding2_1_0() {
72+
return versionsUpToIncluding( KnownVersion.SAMM_2_1_0 );
73+
}
74+
7175
final String violationUrn = "http://www.w3.org/ns/shacl#Violation";
7276
final String warningUrn = "http://www.w3.org/ns/shacl#Warning";
7377

esmf-semantic-aspect-meta-model/src/test/java/org/eclipse/esmf/samm/EnumerationShapeTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818

1919
import org.eclipse.esmf.samm.validation.SemanticError;
2020

21-
public class EnumerationShapeTest extends AbstractShapeTest {
21+
class EnumerationShapeTest extends AbstractShapeTest {
2222

2323
@ParameterizedTest
2424
@MethodSource( value = "allVersions" )
25-
public void testEnumerationValidationExpectSuccess( final KnownVersion metaModelVersion ) {
25+
void testEnumerationValidationExpectSuccess( final KnownVersion metaModelVersion ) {
2626
checkValidity( "enumeration-shape", "TestEnumeration", metaModelVersion );
2727
}
2828

2929
@ParameterizedTest
3030
@MethodSource( value = "allVersions" )
31-
public void testMissingRequiredPropertiesExpectFailure2( final KnownVersion metaModelVersion ) {
31+
void testMissingRequiredPropertiesExpectFailure2( final KnownVersion metaModelVersion ) {
3232
final SammUrns sammUrns = new SammUrns( metaModelVersion );
3333
final String focusNode = testNamespacePrefix + "TestEnumerationMissingRequiredProperties";
3434

@@ -42,7 +42,7 @@ public void testMissingRequiredPropertiesExpectFailure2( final KnownVersion meta
4242

4343
@ParameterizedTest
4444
@MethodSource( value = "allVersions" )
45-
public void testValueIsNotOfDefinedDataTypeExpectFailure( final KnownVersion metaModelVersion ) {
45+
void testValueIsNotOfDefinedDataTypeExpectFailure( final KnownVersion metaModelVersion ) {
4646
final SammUrns sammUrns = new SammUrns( metaModelVersion );
4747
final String focusNode = testNamespacePrefix + "TestEnumerationValueIsNotOfDefinedDataType";
4848

@@ -56,7 +56,7 @@ public void testValueIsNotOfDefinedDataTypeExpectFailure( final KnownVersion met
5656

5757
@ParameterizedTest
5858
@MethodSource( value = "allVersions" )
59-
public void testValueIsNotALiteralTypeExpectFailure( final KnownVersion metaModelVersion ) {
59+
void testValueIsNotALiteralTypeExpectFailure( final KnownVersion metaModelVersion ) {
6060
final SammUrns sammUrns = new SammUrns( metaModelVersion );
6161
final String focusNode = testNamespacePrefix + "TestEnumerationValueIsNotALiteralType";
6262

0 commit comments

Comments
 (0)