@prefix : <https://w3id.org/adiro/aec_provenance#> .
@base <https://w3id.org/adiro/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix prov: <http://www.w3.org/ns/prov#> .
@prefix dcterms: <http://purl.org/dc/terms/> .

#################################################################
#    Ontology
#################################################################

<https://w3id.org/adiro/aec_provenance> rdf:type owl:Ontology ;
    rdfs:label "AEC Provenance Ontology" ;
    rdfs:comment "Foundational, domain-neutral module for provenance. It lets any value inferred from a drawing be recorded as an assertion that carries its own source, confidence, and how it was produced, aligned to W3C PROV-O. The drawing modules import it." ;
    dcterms:title "AEC Provenance Ontology" ;
    dcterms:description "Reified assertion + inference provenance + confidence for AEC drawing extraction. Domain-neutral; PROV-O-aligned." ;
    dcterms:license <https://www.gnu.org/licenses/gpl-3.0.html> ;
    dcterms:creator "Buro Happold - Machine Learning R&D" ;
    dcterms:publisher "Buro Happold" ;
    owl:priorVersion <https://w3id.org/adiro/aec_provenance/1.0.0> ;
    owl:versionIRI <https://w3id.org/adiro/aec_provenance/1.0.1> ;
    owl:versionInfo "1.0.1" .

#################################################################
#    PROV-O terms referenced for alignment
#
#    Declared locally (not owl:imports) so the module stays self-contained
#    and the reasoning CI resolves everything offline via catalog-v001.xml
#    without fetching PROV-O over the network. These are minimal typing stubs
#    for the handful of PROV-O terms our alignment axioms point at; the
#    authoritative definitions live at http://www.w3.org/ns/prov#.
#    Credit: PROV-O alignment first suggested by Tianyang Huang.
#################################################################

prov:Entity rdf:type owl:Class ;
    rdfs:label "Entity" ;
    rdfs:comment "Typing stub for the PROV-O term of the same name, declared locally so this module stays self-contained and the reasoning CI resolves offline. A stub is a name, not a definition: the authoritative axioms live at the source that rdfs:isDefinedBy points at. PROV-O declares prov:Entity owl:disjointWith prov:Activity, which is why the alignment below is seated carefully: a FieldAssertion is the Entity produced, an InferenceMeta is the Activity that produced it, and nothing may be both." ;
    rdfs:isDefinedBy <http://www.w3.org/ns/prov#> .

prov:Activity rdf:type owl:Class ;
    rdfs:label "Activity" ;
    rdfs:comment "Typing stub for the PROV-O term of the same name, declared locally so this module stays self-contained and the reasoning CI resolves offline. A stub is a name, not a definition: the authoritative axioms live at the source that rdfs:isDefinedBy points at. Disjoint with prov:Entity in PROV-O - see prov:Entity above." ;
    rdfs:isDefinedBy <http://www.w3.org/ns/prov#> .

prov:Agent rdf:type owl:Class ;
    rdfs:label "Agent" ;
    rdfs:comment "Typing stub for the PROV-O term of the same name, declared locally so this module stays self-contained and the reasoning CI resolves offline. A stub is a name, not a definition: the authoritative axioms live at the source that rdfs:isDefinedBy points at." ;
    rdfs:isDefinedBy <http://www.w3.org/ns/prov#> .

prov:wasGeneratedBy rdf:type owl:ObjectProperty ;
    rdfs:label "wasGeneratedBy" ;
    rdfs:comment "Typing stub for the PROV-O term of the same name, declared locally so this module stays self-contained and the reasoning CI resolves offline. A stub is a name, not a definition: the authoritative axioms live at the source that rdfs:isDefinedBy points at. (rdfs:domain prov:Entity, rdfs:range prov:Activity)" ;
    rdfs:isDefinedBy <http://www.w3.org/ns/prov#> .

prov:wasAssociatedWith rdf:type owl:ObjectProperty ;
    rdfs:label "wasAssociatedWith" ;
    rdfs:comment "Typing stub for the PROV-O term of the same name, declared locally so this module stays self-contained and the reasoning CI resolves offline. A stub is a name, not a definition: the authoritative axioms live at the source that rdfs:isDefinedBy points at. (rdfs:domain prov:Activity, rdfs:range prov:Agent)" ;
    rdfs:isDefinedBy <http://www.w3.org/ns/prov#> .

prov:used rdf:type owl:ObjectProperty ;
    rdfs:label "used" ;
    rdfs:comment "Typing stub for the PROV-O term of the same name, declared locally so this module stays self-contained and the reasoning CI resolves offline. A stub is a name, not a definition: the authoritative axioms live at the source that rdfs:isDefinedBy points at. (rdfs:domain prov:Activity, rdfs:range prov:Entity)" ;
    rdfs:isDefinedBy <http://www.w3.org/ns/prov#> .

prov:endedAtTime rdf:type owl:DatatypeProperty ;
    rdfs:label "endedAtTime" ;
    rdfs:comment "Typing stub for the PROV-O term of the same name, declared locally so this module stays self-contained and the reasoning CI resolves offline. A stub is a name, not a definition: the authoritative axioms live at the source that rdfs:isDefinedBy points at. (rdfs:domain prov:Activity, rdfs:range xsd:dateTime). ADIRO's own :inferredAt declares rdfs:range xsd:dateTime, so the precision is asserted where it belongs - on the term this suite owns." ;
    rdfs:isDefinedBy <http://www.w3.org/ns/prov#> .

#################################################################
#    Annotation Properties - field-kind metadata
#
#    A "field kind" is a skos:Concept in a field-kind scheme (defined by the
#    importing module, e.g. the TitleblockFieldScheme in aec_drawing_metadata).
#    These annotations describe such a concept; they carry no reasoning weight.
#################################################################

:expectedRange rdf:type owl:AnnotationProperty ;
    rdfs:label "expectedRange" ;
    rdfs:comment "On a field-kind concept: the expected type of its asserted value - a datatype (e.g. xsd:string, xsd:date) for literal-valued fields, or a class (e.g. Person, Organisation) for object-valued fields. Signals whether an assertion of this kind uses hasLiteralValue or hasValueEntity." .

:mapsToFieldProperty rdf:type owl:AnnotationProperty ;
    rdfs:label "mapsToFieldProperty" ;
    rdfs:comment "On a field-kind concept: the canonical ADIRO property that a validated assertion of this field kind is promoted to (the bridge from the reified assertion to a direct statement on the subject). The subject is the assertion's assertedAbout, so a promotion is: ?a assertedAbout ?subject ; assertsFieldKind ?k . ?k mapsToFieldProperty ?p  =>  ?subject ?p <value>. Annotation only - the promotion is performed by tooling on validation, not by reasoning." .

#################################################################
#    Classes
#################################################################

:InferredEntity rdf:type owl:Class ;
    rdfs:label "Inferred Entity" ;
    rdfs:comment "Anything ADIRO infers or extracts that carries its own provenance and confidence - the shared superclass of everything an inference/extraction step produces as a first-class, provenance-bearing individual. A field-value claim (FieldAssertion, here) is one; a spatial localisation (a BoundingBox, in aec_geometry) is another. It exists so that hasInferenceMeta and hasConfidence apply uniformly to any such product, not only to a field-value claim: a detected box is an inferred entity with its own producer and score, distinct from the confidence in the value read at that box. In PROV-O terms this is the prov:Entity an inference activity generated." ;
    rdfs:subClassOf prov:Entity .

:FieldAssertion rdf:type owl:Class ;
    rdfs:label "Field Assertion" ;
    rdfs:comment "A single reified assertion that some source makes a value-claim about a field kind. Reifying the claim (rather than attaching the value straight to a subject) lets each printed occurrence carry its own provenance - which region asserted it (assertedBy), what produced it (hasInferenceMeta), and with what confidence (hasConfidence) - independently of the value it states. The value is a literal (hasLiteralValue) for datatype-valued fields or an entity (hasValueEntity) for object-valued fields. Validated assertions are promoted to direct statements on the subject downstream; conflicting assertions across sources are surfaced, not silently merged. A kind of InferredEntity, so it carries the shared provenance/confidence; in PROV-O terms the prov:Entity an extraction produced, which is why the PROV alignment is seated across two classes rather than all on one." ;
    rdfs:subClassOf :InferredEntity .

:InferenceMeta rdf:type owl:Class ;
    rdfs:label "Inference Meta" ;
    rdfs:comment "Provenance metadata for an inferred or extracted assertion: what produced it (inferredBy / inferredWith), the source it was derived from (inferredFrom), and when (inferredAt). Modelled as a separate object so several assertions can share one inference record and so provenance can be added without touching the value. Analogous to DANO's DrawingElementMeta, but aligned to PROV-O: this is the prov:Activity that produced the assertion, NOT a prov:Entity. PROV-O declares those two owl:disjointWith, so the distinction is load-bearing rather than stylistic." ;
    rdfs:subClassOf prov:Activity .

#################################################################
#    Object Properties
#################################################################

:assertsFieldKind rdf:type owl:ObjectProperty ;
    rdfs:label "assertsFieldKind" ;
    rdfs:comment "The field kind (a SKOS concept in a field-kind scheme, e.g. a title-block field such as Scale or Client) that this assertion is about. Keeping the kind as a referenced concept - rather than a bespoke property per field - is what lets names/synonyms live on the concept and keeps the number of relationships small." ;
    rdfs:domain :FieldAssertion ;
    rdfs:range skos:Concept .

:assertedBy rdf:type owl:ObjectProperty ;
    rdfs:label "assertedBy" ;
    rdfs:comment "The source that makes this assertion - typically the drawing region it was read from (e.g. a Titleblock or a Layout). This is the provenance that lets the same field kind asserted by different regions be distinguished (e.g. a sheet's scale read from the title block versus the same sheet's scale read from a general note), which a fixed domain on a per-field property cannot express." ;
    rdfs:domain :FieldAssertion .

:assertedAbout rdf:type owl:ObjectProperty ;
    rdfs:label "assertedAbout" ;
    rdfs:comment "The subject the claim is ABOUT - the thing a validated assertion is promoted onto. Distinct from assertedBy, which records where the claim was read FROM: a drawn-by name is read from a title-block region (assertedBy) but is a claim about a particular DrawingRevision (assertedAbout), and a sheet has many revisions, so the subject cannot be recovered from the region alone. Without it, mapsToFieldProperty names a property but nothing names the individual to hang it on, and promotion is not expressible. No rdfs:range is asserted: the subjects differ per field kind - Titleblock, DrawingSheet, DrawingRevision, DrawingPackage, Project - and a narrower range would entail those subjects are of a type they are not." ;
    rdfs:domain :FieldAssertion .

:hasValueEntity rdf:type owl:ObjectProperty ;
    rdfs:label "hasValueEntity" ;
    rdfs:comment "For object-valued field kinds, the entity that is the asserted value - e.g. a Person or Organisation. Used instead of hasLiteralValue when the field references a thing rather than states a string, which is what makes cross-sheet questions ('everything checked by X') answerable." ;
    rdfs:domain :FieldAssertion .

:hasInferenceMeta rdf:type owl:ObjectProperty ;
    rdfs:label "hasInferenceMeta" ;
    rdfs:comment "Links an inferred entity (a FieldAssertion, a BoundingBox, ...) to the InferenceMeta describing what produced it, from where, and when. Aligned to prov:wasGeneratedBy: the entity (a prov:Entity) was generated by the inference (a prov:Activity)." ;
    rdfs:subPropertyOf prov:wasGeneratedBy ;
    rdfs:domain :InferredEntity ;
    rdfs:range :InferenceMeta .

:inferredBy rdf:type owl:ObjectProperty ;
    rdfs:label "inferredBy" ;
    rdfs:comment "The actor, organisation or software that produced this inference. Aligned to prov:wasAssociatedWith - the agent the inference activity was associated with." ;
    rdfs:subPropertyOf prov:wasAssociatedWith ;
    rdfs:domain :InferenceMeta ;
    rdfs:range prov:Agent .

:inferredWith rdf:type owl:ObjectProperty ;
    rdfs:label "inferredWith" ;
    rdfs:subPropertyOf prov:used ;
    rdfs:comment "The algorithm or model (ideally with version) used to produce this inference. Distinct from inferredBy, which names the responsible actor; inferredWith names the tool. Aligned to prov:used - the activity used this model." ;
    rdfs:domain :InferenceMeta .

:inferredFrom rdf:type owl:ObjectProperty ;
    rdfs:label "inferredFrom" ;
    rdfs:comment "The source the value was derived from - e.g. the origin file, page or region. Aligned to prov:used - the activity used this source." ;
    rdfs:subPropertyOf prov:used ;
    rdfs:domain :InferenceMeta .

#################################################################
#    Datatype Properties
#################################################################

:hasLiteralValue rdf:type owl:DatatypeProperty ;
    rdfs:label "hasLiteralValue" ;
    rdfs:comment "For datatype-valued field kinds, the literal value asserted, kept verbatim (not normalised, expanded or translated at extraction time)." ;
    rdfs:domain :FieldAssertion ;
    rdfs:range rdfs:Literal .

:capturedCaption rdf:type owl:DatatypeProperty ;
    rdfs:label "capturedCaption" ;
    rdfs:comment "The caption/label text exactly as printed on the drawing for this assertion (e.g. 'Verfasser', 'Dwg. Desc.'). Retained even when the field kind is uncertain, so the ground truth of what was on the sheet is never lost and mapping can be revisited later." ;
    rdfs:domain :FieldAssertion ;
    rdfs:range xsd:string .

:hasConfidence rdf:type owl:DatatypeProperty ;
    rdfs:label "hasConfidence" ;
    rdfs:comment "Confidence of the inference behind an inferred entity, as a decimal in [0,1]. Applies to any InferredEntity - the confidence in a field-value claim (FieldAssertion) and the confidence in a detected localisation (a BoundingBox in aec_geometry) are separate values, each carried on the individual it belongs to. Carried on the individual rather than on a triple, which keeps confidence in the graph without requiring RDF-star or statement reification. The range is an OWL 2 datatype restriction on xsd:decimal with minInclusive 0 and maxInclusive 1, so the [0,1] bound is asserted rather than only described in prose. Note this cannot fire in CI today: the reasoning gate runs over the T-Box in src/ and the repository holds no instance data, so the bound becomes enforceable when an A-Box exists (GitHub issue #22)." ;
    rdfs:domain :InferredEntity ;
    rdfs:range [ rdf:type rdfs:Datatype ;
                 owl:onDatatype xsd:decimal ;
                 owl:withRestrictions ( [ xsd:minInclusive "0.0"^^xsd:decimal ]
                                        [ xsd:maxInclusive "1.0"^^xsd:decimal ] ) ] .

:inferredAt rdf:type owl:DatatypeProperty ;
    rdfs:label "inferredAt" ;
    rdfs:comment "The time the inference was produced. Aligned to prov:endedAtTime - when the inference activity ended." ;
    rdfs:subPropertyOf prov:endedAtTime ;
    rdfs:domain :InferenceMeta ;
    rdfs:range xsd:dateTime .
