@prefix : <https://w3id.org/adiro/aec_geometry#> .
@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 geo: <http://www.opengis.net/ont/geosparql#> .
@prefix aprov: <https://w3id.org/adiro/aec_provenance#> .
@prefix dcterms: <http://purl.org/dc/terms/> .

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

<https://w3id.org/adiro/aec_geometry> rdf:type owl:Ontology ;
    rdfs:label "AEC Geometry Ontology" ;
    rdfs:comment "Foundational, domain-neutral module for geometry. It records where something sits on a drawing page as a bounding box, read against an explicit coordinate frame. Each box carries its own provenance and confidence. It reuses GeoSPARQL, is imported by the drawing modules, and is shared across use cases." ;
    dcterms:title "AEC Geometry Ontology" ;
    dcterms:description "Bounding boxes + coordinate frames for AEC drawing extraction. Domain-neutral; provenance-bearing; GeoSPARQL-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:imports <https://w3id.org/adiro/aec_provenance> ;
    owl:priorVersion <https://w3id.org/adiro/aec_geometry/1.0.0> ;
    owl:versionIRI <https://w3id.org/adiro/aec_geometry/1.0.1> ;
    owl:versionInfo "1.0.1" .

#################################################################
#    GeoSPARQL term reused 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 GeoSPARQL over the network. This is a minimal typing stub for the
#    one GeoSPARQL term our shapes subclass; the authoritative definition lives
#    at http://www.opengis.net/ont/geosparql#. Reusing geo:Geometry (rather than
#    minting our own shape class) is an option-1A external reference per
#    the external-ontology-imports design decision (Discussion #74): GeoSPARQL is a stable,
#    maintained OGC standard, the alignment (BoundingBox is a kind of geometry)
#    is sound, and "is a spatial shape" is exactly the entailment wanted.
#################################################################

geo:Geometry rdf:type owl:Class ;
    rdfs:label "Geometry" ;
    rdfs:comment "Local typing stub for GeoSPARQL's Geometry class (authoritative definition at the rdfs:isDefinedBy IRI), declared here so reasoning stays offline. Used as the supertype of BoundingBox so an ADIRO box is recognised as a spatial shape; ADIRO adopts no GeoSPARQL CRS or spatial-query profile (deferred, GitHub issue #36)." ;
    rdfs:isDefinedBy <http://www.opengis.net/ont/geosparql#> .

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

:BoundingBox rdf:type owl:Class ;
    rdfs:label "Bounding Box" ;
    rdfs:comment "A rectangular region on a drawing page that locates something detected there - e.g. a title-block field's caption or value. Its coordinates are held as an xyxy string (bboxXYXY) and are meaningless without the CoordinateFrame it points at (inCoordinateFrame), which fixes the unit, coordinate space, origin, axes, page and exact PDF. A BoundingBox is itself an InferredEntity: it carries its own provenance (aprov:hasInferenceMeta - a detector, or a human annotator) and its own confidence (aprov:hasConfidence, the detector score), which is DISTINCT from the confidence in a value read at that box. A subclass of GeoSPARQL geo:Geometry so it is recognised as a spatial shape." ;
    rdfs:subClassOf geo:Geometry , aprov:InferredEntity .

:CoordinateFrame rdf:type owl:Class ;
    rdfs:label "Coordinate Frame" ;
    rdfs:comment "The coordinate context that makes a geometry's numbers interpretable - the exact PDF/page, unit and named coordinate space its coordinates are relative to (detailed by the datatype properties below). Normally owned by a DrawingSheet (aec_drawing_metadata:hasCoordinateFrame) and shared by the geometries on that page; a sheet may have different frames for different file versions. Not an InferredEntity: a declared coordinate context, not a detection with its own confidence." .

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

:inCoordinateFrame rdf:type owl:ObjectProperty ;
    rdfs:label "inCoordinateFrame" ;
    rdfs:comment "The CoordinateFrame that interprets this geometry's coordinates. Required for a geometry to mean anything: the same xyxy numbers denote different regions in different frames, so equal coordinates alone never establish that two geometries are the same region." ;
    rdfs:domain geo:Geometry ;
    rdfs:range :CoordinateFrame .

:hasBoundingBox rdf:type owl:ObjectProperty ;
    rdfs:label "hasBoundingBox" ;
    rdfs:comment "The bounding box that locates a region on a drawing page. In UC-01 this is the title block's own region (aec_drawing_metadata:Titleblock hasBoundingBox ...): the field values are read from within that single region and are not themselves individually localised. No rdfs:domain is asserted, so the same property serves any locatable region or element - e.g. UC-03 reference symbols, when that work extends this module." ;
    rdfs:range :BoundingBox .

#################################################################
#    Datatype Properties - the shape
#################################################################

:bboxXYXY rdf:type owl:DatatypeProperty ;
    rdfs:label "bboxXYXY" ;
    rdfs:comment "The rectangle as a string \"[xmin, ymin, xmax, ymax]\" in the coordinate frame's convention (xmin/ymin the top-left corner, xmax/ymax the bottom-right, under page_display_pt). The xyxy ordering is aligned to the Croissant cr:BoundingBox 'XYXY' format token, so an ADIRO box can be mapped to Croissant/CV formats by an exporter - ADIRO stores a page-point xyxy string, whereas Croissant expects a four-number array with a format declaration (background: GitHub issue #91). Interpret only together with inCoordinateFrame." ;
    rdfs:domain :BoundingBox ;
    rdfs:range xsd:string .

#################################################################
#    Datatype Properties - the coordinate frame
#################################################################

:coordinateSpace rdf:type owl:DatatypeProperty ;
    rdfs:label "coordinateSpace" ;
    rdfs:comment "The named coordinate convention that fixes the origin and axes. Primary: 'page_display_pt' - top-left origin, x rightwards, y downwards, in points. Native PDF user space and rendered-image pixels are different spaces and must be named as such; do not interchange the names." ;
    rdfs:domain :CoordinateFrame ;
    rdfs:range xsd:string .

:unit rdf:type owl:DatatypeProperty ;
    rdfs:label "unit" ;
    rdfs:comment "The unit of the coordinate values: 'pt' for the primary page_display_pt space (1 pt = 1/72 inch), 'px' for raster/pixel evidence. Display-page coordinates in pt are independent of rendering DPI." ;
    rdfs:domain :CoordinateFrame ;
    rdfs:range xsd:string .

:frameArtifactRef rdf:type owl:DatatypeProperty ;
    rdfs:label "frameArtifactRef" ;
    rdfs:comment "A reference (e.g. a manifest key or content hash) pinning the exact PDF/artifact version the coordinates are relative to, so a frame is tied to a specific file and not merely a page number." ;
    rdfs:domain :CoordinateFrame ;
    rdfs:range xsd:string .

:pageIndex rdf:type owl:DatatypeProperty ;
    rdfs:label "pageIndex" ;
    rdfs:comment "Zero-based index of the page within the referenced PDF that this frame describes." ;
    rdfs:domain :CoordinateFrame ;
    rdfs:range xsd:nonNegativeInteger .

:displayWidthPt rdf:type owl:DatatypeProperty ;
    rdfs:label "displayWidthPt" ;
    rdfs:comment "Effective display-page width in points after the recorded page mapping; supports bounds checks on coordinates." ;
    rdfs:domain :CoordinateFrame ;
    rdfs:range xsd:decimal .

:displayHeightPt rdf:type owl:DatatypeProperty ;
    rdfs:label "displayHeightPt" ;
    rdfs:comment "Effective display-page height in points after the recorded page mapping; supports bounds checks on coordinates." ;
    rdfs:domain :CoordinateFrame ;
    rdfs:range xsd:decimal .

:pdfRotationDeg rdf:type owl:DatatypeProperty ;
    rdfs:label "pdfRotationDeg" ;
    rdfs:comment "Effective PDF page rotation metadata for the referenced page. The primary page_display_pt coordinates already include the recorded page mapping, so this is for interpretation/validation - do not apply the rotation to the coordinates again." ;
    rdfs:domain :CoordinateFrame ;
    rdfs:range xsd:integer .

:profileRef rdf:type owl:DatatypeProperty ;
    rdfs:label "profileRef" ;
    rdfs:comment "Reference to the versioned coordinate profile that defines the named coordinateSpace in full (origin, axes, unit and effective page extent), so the convention is pinned rather than only implied by the space's name." ;
    rdfs:domain :CoordinateFrame ;
    rdfs:range xsd:string .
