# ==========================================================================
#  W26  Stance, standing and a protected witness
# ==========================================================================
#
#  FROM      Chapter and Verse
#            https://www.semantechs.co.uk/articles/chapter-and-verse/
#
#  CHECKS
#    Every claim has a stance (affirms, denies or unknown); a yes or no needs a
#    standing and an attributed source; an unknown needs a recorded search;
#    statements are attributed; a protected person cannot be identified.
#
#  HOW IT WORKS
#    The open world as a rule: a missing record may only be reported as
#    "unknown", and only with the search that failed to find it. A definitive
#    "no" needs a witness. The protected-person shape forbids any naming
#    property on a node marked protected.
#
#  DIAGRAM
#    claim with stance "unknown"   derived from a recorded mailbox search    ok
#    claim with stance "denies"    derived from a search, no witness         -> would be a violation
#
#  WHAT TO TAKE AWAY
#    - A shape can stop "we found nothing" from turning into "it did not
#      happen".
#
#  TRY IT
#    Add ex:EmployeeK gist:name "Not to be published" . to the data and
#    validate again: one violation.
#
#  DATA      inquiry.ttl
#  LOAD IT   https://semantechs.co.uk/turtle-editor-viewer/?dot=https%3A%2F%2Fwww.semantechs.co.uk%2Farticles%2Fshow-your-working%2Fdemos%2F09-chapter-and-verse%2Finquiry.ttl&shapes=https%3A%2F%2Fwww.semantechs.co.uk%2Farticles%2Fshow-your-working%2Fdemos%2F09-chapter-and-verse%2Fw26-inquiry-shapes.ttl
#  SPEC      SHACL 4.6 Logical Constraint Components
#            https://www.w3.org/TR/shacl/#core-components-logical
#  REPORTS   conforms -- 0 violations, 0 warnings, 0 info; 18 shapes
# ==========================================================================

@prefix sh:     <http://www.w3.org/ns/shacl#> .
@prefix rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs:   <http://www.w3.org/2000/01/rdf-schema#> .
@prefix prov:   <http://www.w3.org/ns/prov#> .
@prefix schema: <http://schema.org/> .
@prefix gist:   <https://w3id.org/semanticarts/ns/ontology/gist/> .
@prefix ex:     <https://example.org/inquiry/> .
@prefix shp:    <https://example.org/shapes/> .

shp:ClaimHasSourceAndStance a sh:NodeShape ;
    sh:targetSubjectsOf rdf:reifies ;
    sh:property [
        sh:path prov:wasDerivedFrom ; sh:minCount 1 ;
        sh:message "A claim must say what it was derived from." ] ;
    sh:property [
        sh:path ex:stance ; sh:minCount 1 ; sh:maxCount 1 ;
        sh:in ( ex:_affirms ex:_denies ex:_unknown ) ;
        sh:message "Every claim needs one stance: affirms, denies or unknown." ] ;
    sh:property [
        sh:path gist:isCategorizedBy ;
        sh:in ( ex:_alleged ex:_disputed ex:_corroborated ex:_withdrawn ) ;
        sh:message "A standing is alleged, disputed, corroborated or withdrawn." ] .

# A claim that says yes or no is someone's claim, with a standing. An "unknown"
# is the record of a search that found nothing either way.
shp:AnsweredClaim a sh:NodeShape ;
    sh:targetSubjectsOf rdf:reifies ;
    sh:or (
        [ sh:path ex:stance ; sh:hasValue ex:_unknown ;
          sh:property [ sh:path prov:wasDerivedFrom ; sh:class prov:Activity ] ]
        [ sh:property [ sh:path gist:isCategorizedBy ; sh:minCount 1 ] ;
          sh:property [ sh:path ( prov:wasDerivedFrom prov:wasAttributedTo ) ; sh:minCount 1 ] ]
    ) ;
    sh:message "A claim that affirms or denies needs a standing and an attributed source; an unknown needs a recorded search." .

shp:StatementIsAttributed a sh:NodeShape ;
    sh:targetClass gist:Content ;
    sh:property [ sh:path prov:wasAttributedTo ; sh:minCount 1 ; sh:message "A statement must say who made it." ] ;
    sh:property [ sh:path prov:wasGeneratedBy ; sh:minCount 1 ; sh:message "A statement must say where and when it was made." ] .

shp:ProtectedPersonIsProtected a sh:NodeShape ;
    sh:targetClass ex:ProtectedPerson ;
    sh:property [ sh:path rdfs:label ; sh:minCount 1 ; sh:message "A protected person needs a code name." ] ;
    sh:property [ sh:path gist:name ; sh:maxCount 0 ; sh:message "A protected person must not be named." ] ;
    sh:property [ sh:path schema:birthDate ; sh:maxCount 0 ; sh:message "Nothing that could identify a protected person." ] ;
    sh:property [ sh:path gist:hasAddress ; sh:maxCount 0 ; sh:message "Nothing that could identify a protected person." ] .
