spdx-3-model
spdx-3-model copied to clipboard
Unique DictionaryEntry
From DictionaryEntry:
To implement a dictionary, this class is to be used in a collection with unique keys.
Suggested SHACL shapes:
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix spdxbuild: <https://spdx.org/rdf/3.0.1/terms/Build/> .
spdxbuild:Build
sh:sparql [
sh:select """
SELECT ?this ?property ?key
(CONCAT('Duplicate key "', ?key,
'" found in property "', STR(?property), '"') AS ?value)
WHERE {
?this ?property ?entry .
?entry a spdxcore:DictionaryEntry ;
spdxcore:key ?key .
FILTER ( EXISTS {
?this ?property ?other .
?other a spdxcore:DictionaryEntry ;
spdxcore:key ?key .
FILTER(?other != ?entry)
} )
}
GROUP BY ?this ?property ?key
""" ;
sh:message "{?value}" ;
] .
Test data:
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix spdxcore: <https://spdx.org/rdf/3.0.1/terms/Core/> .
@prefix spdxbuild: <https://spdx.org/rdf/3.0.1/terms/Build/> .
@prefix ex: <http://example.org/ns#> .
ex:MyAgent
a spdxcore:Agent ;
spdxcore:creationInfo _:MyCreationInfo .
_:MyCreationInfo
a spdxcore:CreationInfo ;
spdxcore:createdBy ex:MyAgent ;
spdxcore:created "2024-09-04T20:25:34Z"^^xsd:dateTimeStamp ;
spdxcore:specVersion "3.0.1" .
_:Entry1
a spdxcore:DictionaryEntry ;
spdxcore:key "key1" ;
spdxcore:value "value" ;
spdxcore:creationInfo _:MyCreationInfo .
_:Entry2
a spdxcore:DictionaryEntry ;
spdxcore:key "key2" ;
spdxcore:value "value" ;
spdxcore:creationInfo _:MyCreationInfo .
_:Entry3
a spdxcore:DictionaryEntry ;
spdxcore:key "key1" ;
spdxcore:value "value" ;
spdxcore:creationInfo _:MyCreationInfo .
ex:ValidBuildWithUniqueKeys
a spdxbuild:Build ;
spdxbuild:buildType "http://fake-build-type"^^xsd:anyURI ;
spdxcore:creationInfo _:MyCreationInfo ;
spdxbuild:environment _:Entry1 ; # key1
spdxbuild:environment _:Entry2 ; # key2
spdxbuild:parameter _:Entry1 ; # key1
spdxbuild:parameter _:Entry2 . # key2
ex:InvalidBuildWithDuplicateParameterKeys
a spdxbuild:Build ;
spdxbuild:buildType "http://fake-build-type"^^xsd:anyURI ;
spdxcore:creationInfo _:MyCreationInfo ;
spdxbuild:environment _:Entry1 ; # key1
spdxbuild:environment _:Entry2 ; # key2
spdxbuild:parameter _:Entry1 ; # key1
spdxbuild:parameter _:Entry3 . # key1
ex:InvalidBuildWithDuplicateEnvironmentKeys
a spdxbuild:Build ;
spdxbuild:buildType "http://fake-build-type"^^xsd:anyURI ;
spdxcore:creationInfo _:MyCreationInfo ;
spdxbuild:environment _:Entry1 ; # key1
spdxbuild:environment _:Entry3 ; # key1
spdxbuild:parameter _:Entry1 ; # key1
spdxbuild:parameter _:Entry2 . # key2
Test script: https://raw.githubusercontent.com/condots/dots/refs/heads/main/scripts/shacl/test.py
Test results:
----------------------------------------------------------------------------------------------------
Violation message: Duplicate key "key1" found in property "https://spdx.org/rdf/3.0.1/terms/Build/parameter"
Violation constraint: SPARQLConstraintComponent
Violation value: Duplicate key "key1" found in property "https://spdx.org/rdf/3.0.1/terms/Build/parameter"
Property path: None
Focus node: http://example.org/ns#InvalidBuildWithDuplicateParameterKeys
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
Violation message: Duplicate key "key1" found in property "https://spdx.org/rdf/3.0.1/terms/Build/environment"
Violation constraint: SPARQLConstraintComponent
Violation value: Duplicate key "key1" found in property "https://spdx.org/rdf/3.0.1/terms/Build/environment"
Property path: None
Focus node: http://example.org/ns#InvalidBuildWithDuplicateEnvironmentKeys
----------------------------------------------------------------------------------------------------