@prefix audit: <https://voc.semanticpartners.com/ontology/audit#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@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 xsd: <http://www.w3.org/2001/XMLSchema#> .

audit: a owl:Ontology ;
    rdfs:label "Audit Log Ontology" ;
    rdfs:comment "An OWL ontology and SHACL Shapes to record changes in RDF data and create an audit trail which can be used to reconstruct past states of a given resource, track the activity of a given contributor, and generally to capture every addition and deletion of triples to a given subject." ;
    owl:versionInfo "0.2" .

audit:ChangeRecordShape a sh:NodeShape ;
    rdfs:label "Change Record Shape" ;
    rdfs:comment "A shape to ensure that instances of ChangeRecord contain data in a consistent format." ;
    sh:property [ a sh:PropertyShape ;
            rdfs:label "Predicate Reification Shape" ;
            rdfs:comment "The specific RDF property that was changed." ;
            sh:class rdf:Property ;
            sh:description "The specific RDF property that was changed." ;
            sh:maxCount 1 ;
            sh:minCount 1 ;
            sh:name "predicate" ;
            sh:path rdf:predicate ],
        [ a sh:PropertyShape ;
            rdfs:label "Object Reification Shape" ;
            rdfs:comment "The value before the update." ;
            sh:description "The value before the update." ;
            sh:maxCount 1 ;
            sh:minCount 1 ;
            sh:name "object" ;
            sh:or ( [ sh:nodeKind sh:Literal ] [ sh:nodeKind sh:IRI ] ) ;
            sh:path rdf:object ] ;
    sh:targetClass audit:ChangeRecord .

audit:ChangeStateShape a sh:NodeShape ;
    rdfs:label "Change State Shape" ;
    rdfs:comment "A shape to ensure that instances of ChangeState contain the necessary information to create an audit trail." ;
    sh:property [ a sh:PropertyShape ;
            rdfs:label "Subject Reification Shape" ;
            rdfs:comment "The URI of the resource that was updated." ;
            sh:description "The URI of the resource that was updated." ;
            sh:maxCount 1 ;
            sh:minCount 1 ;
            sh:name "subject" ;
            sh:nodeKind sh:IRI ;
            sh:path rdf:subject ],
        [ a sh:PropertyShape ;
            rdfs:label "deleted Shape" ;
            rdfs:comment "The list of all triples that were deleted." ;
            sh:class audit:ChangeRecord ;
            sh:description "The list of all triples that were deleted." ;
            sh:minCount 0 ;
            sh:name "deleted" ;
            sh:path audit:deleted ],
        [ a sh:PropertyShape ;
            rdfs:label "added Shape" ;
            rdfs:comment "The list of all triples that were added." ;
            sh:class audit:ChangeRecord ;
            sh:description "The list of all triples that were added." ;
            sh:minCount 0 ;
            sh:name "added" ;
            sh:path audit:added ],
        [ a sh:PropertyShape ;
            rdfs:label "changed By Shape" ;
            rdfs:comment "The email address of the person who made the change." ;
            sh:datatype xsd:string ;
            sh:description "The email address of the person who made the change." ;
            sh:maxCount 1 ;
            sh:minCount 1 ;
            sh:name "changedBy" ;
            sh:path audit:changedBy ;
            sh:pattern "^[\\w\\-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$" ],
        [ a sh:PropertyShape ;
            rdfs:label "valid Until Shape" ;
            rdfs:comment "The UTC timestamp when the change was recorded." ;
            sh:datatype xsd:dateTime ;
            sh:description "The UTC timestamp when the change was recorded." ;
            sh:maxCount 1 ;
            sh:minCount 1 ;
            sh:name "validUntil" ;
            sh:path audit:validUntil ;
            sh:pattern ".*Z$" ],
        [ a sh:PropertyShape ;
            rdfs:label "change Reason Shape" ;
            rdfs:comment "A description of the purpose for the change." ;
            sh:datatype xsd:string ;
            sh:description "A description of the purpose for the change." ;
            sh:maxCount 1 ;
            sh:minCount 1 ;
            sh:name "changeReason" ;
            sh:path audit:changeReason ] ;
    sh:targetClass audit:ChangeState .

audit:added a owl:ObjectProperty ;
    rdfs:label "added" ;
    rdfs:comment "The relationship between a ChangeState and the ChangeRecords, recording the triples that were added to the resource." ;
    rdfs:domain audit:ChangeState ;
    rdfs:range audit:ChangeRecord .

audit:changeReason a owl:DatatypeProperty ;
    rdfs:label "changeReason" ;
    rdfs:comment "A description of the purpose for the change." ;
    rdfs:domain audit:ChangeState ;
    rdfs:range xsd:string .

audit:changedBy a owl:DatatypeProperty ;
    rdfs:label "changedBy" ;
    rdfs:comment "The email address of the person who made the change." ;
    rdfs:domain audit:ChangeState ;
    rdfs:range xsd:string .

audit:deleted a owl:ObjectProperty ;
    rdfs:label "deleted" ;
    rdfs:comment "The relationship between a ChangeState and the ChangeRecords, recording the triples that were deleted from the resource." ;
    rdfs:domain audit:ChangeState ;
    rdfs:range audit:ChangeRecord .

audit:validUntil a owl:DatatypeProperty ;
    rdfs:label "validUntil" ;
    rdfs:comment "The timestamp until which the Change State is valid." ;
    rdfs:domain audit:ChangeState ;
    rdfs:range xsd:dateTime ;
    owl:subPropertyOf dcterms:date .

audit:ChangeRecord a owl:Class ;
    rdfs:label "Change Record" ;
    rdfs:comment "Instances of this class record a discrete change to an RDF resource." .

audit:ChangeState a owl:Class ;
    rdfs:label "Change State" ;
    rdfs:comment "The state of an RDF resource recording all the changes in terms of individual deletions and additions, each expressed with a single ChangeRecord instance." .

