# DataCarrierProductMatch — scanned or resolved identifier is this product.

@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:DataCarrierProductMatch
    a owl:Ontology, sh:NodeShape ;
    owl:versionInfo "0.8.0" ;
    rdfs:label "Data-carrier identifier matches product"@en ;
    rdfs:comment "When a relying party discovers a product passport from a scanned or resolved identifier, that identifier must be the Product IRI or an alsoKnownAs alias of it. The looked-up identifier is recorded with gv:resolvedFrom at graph-construction time."@en ;
    rdfs:seeAlso <https://untp.unece.org/docs/specification/IdentityResolver> ,
                 <https://untp.unece.org/docs/specification/DigitalProductPassport> ;
    owl:imports gv:resolvedFrom ;
    sh:declare
        [ sh:prefix "unece" ; sh:namespace "https://test.uncefact.org/vocabulary/"^^xsd:anyURI ] ,
        [ sh:prefix "gv" ; sh:namespace "https://vocabulary.uncefact.org/untp/shapes/"^^xsd:anyURI ] ;
    sh:targetClass unece:Product ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "The identifier used to discover this product passport is not the product's id and is not listed as alsoKnownAs."@en ;
        sh:prefixes gv:DataCarrierProductMatch ;
        sh:select """
            PREFIX unece: <https://test.uncefact.org/vocabulary/>
            PREFIX gv:    <https://vocabulary.uncefact.org/untp/shapes/>
            SELECT $this ?requested
            WHERE {
              $this gv:resolvedFrom ?requested .
              FILTER($this != ?requested)
              FILTER NOT EXISTS { $this unece:alsoKnownAs ?requested }
            }
        """ ;
    ] .
