# ClaimHasMatchingAssessment — a claim has an assessment of the same criterion.

@prefix sh:     <http://www.w3.org/ns/shacl#> .
@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:    <http://www.w3.org/2002/07/owl#> .
@prefix xsd:    <http://www.w3.org/2001/XMLSchema#> .
@prefix unece:  <https://test.uncefact.org/vocabulary/> .
@prefix gv:     <https://vocabulary.uncefact.org/untp/shapes/> .

gv:ClaimHasMatchingAssessment
    a owl:Ontology, sh:NodeShape ;
    owl:versionInfo "0.8.0" ;
    rdfs:label "Claim has a matching assessment"@en ;
    rdfs:comment "A performance claim on a product or facility is substantiated when a conformity assessment in the graph references the same criterion IRI and is about the same product or the facility that produced it. Claims without a matching assessment are unverified."@en ;
    rdfs:seeAlso <https://untp.unece.org/docs/specification/ConformityVocabularyCatalog> ,
                 <https://untp.unece.org/docs/specification/ConformityCredential> ;
    sh:declare
        [ sh:prefix "unece" ; sh:namespace "https://test.uncefact.org/vocabulary/"^^xsd:anyURI ] ;
    sh:targetClass unece:Claim ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "This claim has no matching conformity assessment in the graph for the same criterion and the same product or producing facility."@en ;
        sh:prefixes gv:ClaimHasMatchingAssessment ;
        sh:select """
            PREFIX unece: <https://test.uncefact.org/vocabulary/>
            SELECT $this ?crit
            WHERE {
              $this unece:referenceCriteria ?crit .
              FILTER NOT EXISTS {
                ?assessment a unece:ConformityAssessment ;
                            unece:assessedAgainst ?crit .
                {
                  ?product unece:performanceClaim $this .
                  {
                    ?assessment unece:eventProduct ?product
                  }
                  UNION
                  {
                    ?product unece:producedAtFacility ?fac .
                    {
                      ?assessment unece:assessedFacility ?fac
                    }
                    UNION
                    {
                      ?assessment unece:assessedFacility / unece:assessedFacility ?fac
                    }
                  }
                }
                UNION
                {
                  ?facility unece:performanceClaim $this .
                  {
                    ?assessment unece:assessedFacility ?facility
                  }
                  UNION
                  {
                    ?assessment unece:assessedFacility / unece:assessedFacility ?facility
                  }
                }
              }
            }
        """ ;
    ] .
