@prefix delta: <https://ontology.inferal.com/modules/rdf-delta/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sd: <http://www.w3.org/ns/sparql-service-description#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .

delta:ConstructorRequestShape
    a sh:NodeShape ;
    rdfs:label "dataset delta constructor request shape"@en ;
    rdfs:comment "Validates one unambiguous pair of Service Description dataset snapshots selected for the reference constructor."@en ;
    sh:targetClass delta:DatasetDelta ;
    sh:targetSubjectsOf delta:baselineDataset, delta:resultDataset ;
    sh:class delta:DatasetDelta ;
    sh:nodeKind sh:IRI ;
    sh:property [
        sh:path delta:baselineDataset ;
        sh:class sd:Dataset ;
        sh:node delta:ConstructorDatasetShape ;
        sh:nodeKind sh:IRI ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
    ] ;
    sh:property [
        sh:path delta:resultDataset ;
        sh:class sd:Dataset ;
        sh:node delta:ConstructorDatasetShape ;
        sh:nodeKind sh:IRI ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
    ] .

delta:ConstructorDatasetShape
    a sh:NodeShape ;
    rdfs:label "constructor dataset description shape"@en ;
    rdfs:comment "Requires a Service Description dataset to identify one carrier graph for its default graph and unambiguous descriptions of its named graphs."@en ;
    sh:class sd:Dataset ;
    sh:nodeKind sh:IRI ;
    sh:property [
        sh:path sd:defaultGraph ;
        sh:class sd:Graph ;
        sh:node delta:ConstructorGraphShape ;
        sh:nodeKind sh:IRI ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
    ] ;
    sh:property [
        sh:path sd:namedGraph ;
        sh:class sd:NamedGraph ;
        sh:node delta:ConstructorNamedGraphShape ;
    ] ;
    sh:sparql [
        a sh:SPARQLConstraint ;
        sh:message "A constructor dataset must not assign one logical graph name to multiple named-graph descriptions."@en ;
        sh:prefixes [
            sh:declare [
                sh:prefix "sd" ;
                sh:namespace "http://www.w3.org/ns/sparql-service-description#" ;
            ] ;
        ] ;
        sh:select """
            SELECT $this ?name
            WHERE {
              $this sd:namedGraph ?left, ?right .
              ?left sd:name ?name .
              ?right sd:name ?name .
              FILTER(!sameTerm(?left, ?right))
            }
        """ ;
    ] .

delta:ConstructorNamedGraphShape
    a sh:NodeShape ;
    rdfs:label "constructor named graph description shape"@en ;
    rdfs:comment "Requires each named-graph description to preserve one logical graph name while identifying one carrier graph containing that graph's triples."@en ;
    sh:class sd:NamedGraph ;
    sh:property [
        sh:path sd:name ;
        sh:nodeKind sh:IRI ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
    ] ;
    sh:property [
        sh:path sd:graph ;
        sh:class sd:Graph ;
        sh:node delta:ConstructorGraphShape ;
        sh:nodeKind sh:IRI ;
        sh:minCount 1 ;
        sh:maxCount 1 ;
    ] .

delta:ConstructorGraphShape
    a sh:NodeShape ;
    rdfs:label "constructor carrier graph shape"@en ;
    rdfs:comment "Requires every graph description used by the constructor input contract to be an IRI that can also select its triples from the carrier dataset."@en ;
    sh:class sd:Graph ;
    sh:nodeKind sh:IRI .
