spdx-3-model icon indicating copy to clipboard operation
spdx-3-model copied to clipboard

Relationship with NoneElement has no other to elements

Open ilans opened this issue 10 months ago • 0 comments

From Relationship:

To explicitly assert that no such relationships exist, the to property should contain the NoneElement individual and no other elements.

Suggested SHACL shapes:

@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix spdxcore: <https://spdx.org/rdf/3.0.1/terms/Core/> .

spdxcore:RelationshipShape
    a sh:NodeShape ;
    sh:targetClass spdxcore:Relationship ;
    sh:property [
        sh:path spdxcore:to ;
        sh:qualifiedValueShape spdxcore:NoneElement ;
        sh:qualifiedMinCount 1 ;
        sh:qualifiedMaxCount 1 ;
        sh:message "If a 'to' property to 'NoneElement' is defined, no other 'to' properties are allowed."@en ;
    ] .

Test data:

@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix ex: <http://example.org/ns#> .
@prefix spdxcore: <https://spdx.org/rdf/3.0.1/terms/Core/> .
@prefix spdxreltype: <https://spdx.org/rdf/3.0.1/terms/Core/RelationshipType/> .
@prefix spdxsw: <https://spdx.org/rdf/3.0.1/terms/Software/> .
@prefix spdxsmplic: <https://spdx.org/rdf/3.0.1/terms/SimpleLicensing/> .
@prefix spdxextlic: <https://spdx.org/rdf/3.0.1/terms/ExpandedLicensing/> .

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" .

ex:MyPackage
    a spdxsw:Package ;
    spdxcore:creationInfo _:MyCreationInfo .

<http://spdx.org/licenses/MIT> a spdxextlic:ListedLicense ;
    spdxcore:creationInfo _:MyCreationInfo ;
    spdxsmplic:licenseText "MIT License" .

ex:ValidNoneElementOnly
    a spdxcore:Relationship ;
    spdxcore:creationInfo _:MyCreationInfo ;
    spdxcore:relationshipType spdxreltype:hasConcludedLicense ;
    spdxcore:from ex:MyPackage ;
    spdxcore:to spdxcore:NoneElement .

ex:InvalidNotNoneElementAndOthers
    a spdxcore:Relationship ;
    spdxcore:creationInfo _:MyCreationInfo ;
    spdxcore:relationshipType spdxreltype:hasConcludedLicense ;
    spdxcore:from ex:MyPackage ;
    spdxcore:to spdxcore:NoneElement ;
    spdxcore:to <http://spdx.org/licenses/MIT> .

Test script: https://raw.githubusercontent.com/condots/dots/refs/heads/main/scripts/shacl/test.py

Test results:

----------------------------------------------------------------------------------------------------
Severity: sh:Violation
Source Shape: ne24c02f83b3f410caf1fef6f118b7955b525
Focus Node: ex:InvalidNotNoneElementAndOthers
Value Node: None
Result Path: spdxcore:to
Message: If a 'to' property to 'NoneElement' is defined, no other 'to' properties are allowed.
----------------------------------------------------------------------------------------------------
Found 1 SHACL violations!

ilans avatar Mar 03 '25 20:03 ilans