ucoProject / UCO

This repository is for development of the Unified Cyber Ontology.
Apache License 2.0
74 stars 34 forks source link

SHACL-SPARQL constraints reviewing sequence paths need list handling reversed #502

Closed ajnelson-nist closed 1 year ago

ajnelson-nist commented 1 year ago

Bug description

A shape in CASE-Corpora was defined with a sequence path of properties ending with a datatype property. The OWL-SHACL shape in UCO-OWL flagged it as erroneous. After review of the SHACL specification on property shapes and the sequence form of sh:path, the review mechanism appears incorrect. The rdf:List used in the SHACL-SPARQL constraint has its logic backwards, reviewing the first member of the list instead of the last.

This Issue is being posted as a bugfix, not requiring a committee vote to implement.

Steps to reproduce

This shape triggered the issue. It is excerpted from this version of case-corpora.ttl.

@prefix case-corpora: <http://example.org/ontology/case/corpora/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix uco-core: <https://ontology.unifiedcyberontology.org/uco/core/> .
@prefix uco-observable: <https://ontology.unifiedcyberontology.org/uco/observable/> .

case-corpora:Distribution-URL-hasFacet-fullValue-shape
    a sh:PropertyShape ;
    sh:class uco-observable:URL ;
    sh:description "CASE-Corpora requires any referenced Distribution have a downloadable URL, stored in the fullValue of a URLFacet."@en ;
    sh:minCount "1"^^xsd:integer ;
    sh:nodeKind sh:IRI ;
    sh:path case-corpora:hasDownloadURL ;
    sh:qualifiedMinCount "1"^^xsd:integer ;
    sh:qualifiedValueShape [
        sh:datatype xsd:string ;
        sh:nodeKind sh:Literal ;
        sh:path (
            uco-core:hasFacet
            uco-observable:fullValue
        ) ;
    ] ;
    .

The nested property shape under sh:qualifiedValueShape reviews the triple's-object-value of the fullValue property. (There may be a better style to use to encode that shape; that's beside the point of this bug.) These errors raised by uco-owl are incorrect:

@prefix core: <https://ontology.unifiedcyberontology.org/uco/core/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix uco-owl: <https://ontology.unifiedcyberontology.org/owl/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

[]
    a sh:ValidationReport ;
    sh:conforms "false"^^xsd:boolean ;
    sh:result
        [
            a sh:ValidationResult ;
            sh:focusNode core:hasFacet ;
            sh:resultMessage "An OWL Object Property cannot use a SHACL DatatypeConstraintComponent." ;
            sh:resultSeverity sh:Violation ;
            sh:sourceConstraint [
                a sh:SPARQLConstraint ;
                sh:message "An OWL Object Property cannot use a SHACL DatatypeConstraintComponent."@en ;
                sh:select """
                PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                PREFIX sh: <http://www.w3.org/ns/shacl#>
                SELECT $this
                WHERE {
                    $value
                        sh:datatype ?nDatatype ;
                        sh:path / rdf:rest* / rdf:first? $this ;
                        .
                }
        """ ;
            ] ;
            sh:sourceConstraintComponent sh:SPARQLConstraintComponent ;
            sh:sourceShape uco-owl:ObjectProperty-shacl-constraints-shape ;
            sh:value core:hasFacet ;
        ] ,
        [
            a sh:ValidationResult ;
            sh:focusNode core:hasFacet ;
            sh:resultMessage "An OWL Object Property must not permit a Literal value via SHACL consraints." ;
            sh:resultSeverity sh:Violation ;
            sh:sourceConstraint [
                a sh:SPARQLConstraint ;
                sh:message "An OWL Object Property must not permit a Literal value via SHACL consraints."@en ;
                sh:select """
                PREFIX sh: <http://www.w3.org/ns/shacl#>
                SELECT $this
                WHERE {
                    $value sh:path / rdf:rest* / rdf:first? $this ;

                    { $value sh:nodeKind sh:BlankNodeOrLiteral . }
                    UNION
                    { $value sh:nodeKind sh:IRIOrLiteral . }
                    UNION
                    { $value sh:nodeKind sh:Literal . }
                }
        """ ;
            ] ;
            sh:sourceConstraintComponent sh:SPARQLConstraintComponent ;
            sh:sourceShape uco-owl:ObjectProperty-shacl-constraints-shape ;
            sh:value core:hasFacet ;
        ]
        ;
    .

Coordination