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

Unique DictionaryEntry #976

Open
ilans opened this issue Feb 18, 2025 · 0 comments
Open

Unique DictionaryEntry #976

ilans opened this issue Feb 18, 2025 · 0 comments
Labels
Profile:Core Core Profile and related matters RDF/OWL/SHACL RDF graph, schema, ontology, constraint
Milestone

Comments

@ilans
Copy link
Collaborator

ilans commented Feb 18, 2025

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
----------------------------------------------------------------------------------------------------
@ilans ilans added Profile:Core Core Profile and related matters RDF/OWL/SHACL RDF graph, schema, ontology, constraint labels Feb 18, 2025
@ilans ilans added this to the 3.1 milestone Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Profile:Core Core Profile and related matters RDF/OWL/SHACL RDF graph, schema, ontology, constraint
Projects
None yet
Development

No branches or pull requests

1 participant