@prefix uko: <https://cleveragents.ai/ontology/uko#> .
@prefix uko-code: <https://cleveragents.ai/ontology/uko/code#> .
@prefix uko-doc: <https://cleveragents.ai/ontology/uko/doc#> .
@prefix uko-data: <https://cleveragents.ai/ontology/uko/data#> .
@prefix uko-infra: <https://cleveragents.ai/ontology/uko/infra#> .
@prefix uko-oo: <https://cleveragents.ai/ontology/uko/oo#> .
@prefix uko-py: <https://cleveragents.ai/ontology/uko/py#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

# ===========================================================================
# Ontology metadata
# ===========================================================================

uko: a owl:Ontology ;
    owl:versionIRI <https://cleveragents.ai/ontology/uko/0.1.0> ;
    rdfs:label "Unified Knowledge Ontology" ;
    rdfs:comment "CleverAgents knowledge representation layers 0-3" .

# ===========================================================================
# Layer 0: Universal Foundation  (uko:)
# ===========================================================================

# -- Base Classes --

uko:InformationUnit a owl:Class ;
    rdfs:label "InformationUnit" ;
    rdfs:comment "The root of every UKO node. Anything that can appear in an actor's context." .

uko:Container a owl:Class ;
    rdfs:subClassOf uko:InformationUnit ;
    rdfs:label "Container" ;
    rdfs:comment "An information unit that contains other information units (file, module, class, section)." .

uko:Atom a owl:Class ;
    rdfs:subClassOf uko:InformationUnit ;
    rdfs:label "Atom" ;
    rdfs:comment "A leaf-level information unit (function body, paragraph, config value)." .

uko:Annotation a owl:Class ;
    rdfs:subClassOf uko:InformationUnit ;
    rdfs:label "Annotation" ;
    rdfs:comment "Metadata attached to another information unit (comment, docstring, attribute)." .

uko:Boundary a owl:Class ;
    rdfs:subClassOf uko:InformationUnit ;
    rdfs:label "Boundary" ;
    rdfs:comment "An interface point between containers (export, API endpoint, public method signature)." .

# -- Core Relationships --

uko:contains a owl:ObjectProperty ;
    rdfs:domain uko:Container ;
    rdfs:range uko:InformationUnit ;
    rdfs:label "contains" ;
    rdfs:comment "Parent contains child (e.g., module contains class)." .

uko:references a owl:ObjectProperty ;
    rdfs:domain uko:InformationUnit ;
    rdfs:range uko:InformationUnit ;
    rdfs:label "references" ;
    rdfs:comment "Weak reference (e.g., a function mentions a type in a docstring)." .

uko:dependsOn a owl:ObjectProperty ;
    rdfs:domain uko:InformationUnit ;
    rdfs:range uko:InformationUnit ;
    rdfs:label "dependsOn" ;
    rdfs:comment "Strong dependency (e.g., import, inheritance, call)." .

# -- Content Properties --

uko:hasRendering a owl:DatatypeProperty ;
    rdfs:domain uko:InformationUnit ;
    rdfs:range xsd:string ;
    rdfs:label "hasRendering" ;
    rdfs:comment "A rendered text representation of this node at a specific detail depth. Multiple renderings at different depths may exist for the same node. The depth is indicated by the associated uko:renderingDepth value." .

uko:renderingDepth a owl:DatatypeProperty ;
    rdfs:domain uko:InformationUnit ;
    rdfs:range xsd:nonNegativeInteger ;
    rdfs:label "renderingDepth" ;
    rdfs:comment "The integer detail depth at which the associated uko:hasRendering was produced. Paired with uko:hasRendering via a blank node or reification." .

uko:hasFullContent a owl:DatatypeProperty ;
    rdfs:domain uko:InformationUnit ;
    rdfs:range xsd:string ;
    rdfs:label "hasFullContent" ;
    rdfs:comment "Shorthand for the maximum-depth rendering of this node (complete, unabridged content). Equivalent to uko:hasRendering at the domain's maximum depth." .

# -- Provenance Properties --

uko:sourceResource a owl:ObjectProperty ;
    rdfs:domain uko:InformationUnit ;
    rdfs:label "sourceResource" ;
    rdfs:comment "The CleverAgents Resource (by ULID) this node was extracted from." .

uko:sourcePath a owl:DatatypeProperty ;
    rdfs:domain uko:InformationUnit ;
    rdfs:range xsd:string ;
    rdfs:label "sourcePath" ;
    rdfs:comment "Path within the resource (e.g., file path relative to the resource root)." .

uko:sourceRange a owl:DatatypeProperty ;
    rdfs:domain uko:InformationUnit ;
    rdfs:range xsd:string ;
    rdfs:label "sourceRange" ;
    rdfs:comment "Byte or line range within the source file (e.g., '42:1-87:0')." .

# -- Temporal Properties --

uko:validFrom a owl:DatatypeProperty ;
    rdfs:domain uko:InformationUnit ;
    rdfs:range xsd:dateTime ;
    rdfs:label "validFrom" .

uko:validUntil a owl:DatatypeProperty ;
    rdfs:domain uko:InformationUnit ;
    rdfs:range xsd:dateTime ;
    rdfs:label "validUntil" .

uko:isCurrent a owl:DatatypeProperty ;
    rdfs:domain uko:InformationUnit ;
    rdfs:range xsd:boolean ;
    rdfs:label "isCurrent" .

uko:isRevisionOf a owl:ObjectProperty ;
    rdfs:domain uko:InformationUnit ;
    rdfs:range uko:InformationUnit ;
    rdfs:label "isRevisionOf" ;
    rdfs:comment "Links a revised node to its predecessor." .

# ===========================================================================
# Layer 1: General Software  (uko-code:)
# ===========================================================================

uko-code:Module a owl:Class ;
    rdfs:subClassOf uko:Container ;
    rdfs:label "Module" ;
    rdfs:comment "A source code module (file, package, namespace)." .

uko-code:Callable a owl:Class ;
    rdfs:subClassOf uko:Atom ;
    rdfs:label "Callable" ;
    rdfs:comment "Any callable unit (function, method, procedure, lambda)." .

uko-code:TypeDefinition a owl:Class ;
    rdfs:subClassOf uko:Atom ;
    rdfs:label "TypeDefinition" ;
    rdfs:comment "A type or schema definition (class, struct, interface, enum, typedef)." .

uko-code:TestCase a owl:Class ;
    rdfs:subClassOf uko:Atom ;
    rdfs:label "TestCase" ;
    rdfs:comment "A test case or test function." .

uko-code:Import a owl:Class ;
    rdfs:subClassOf uko:Annotation ;
    rdfs:label "Import" ;
    rdfs:comment "An import/include/require statement." .

# -- uko-code: Properties --

uko-code:hasReturnType a owl:DatatypeProperty ;
    rdfs:domain uko-code:Callable ;
    rdfs:range xsd:string ;
    rdfs:label "hasReturnType" .

uko-code:hasParameters a owl:DatatypeProperty ;
    rdfs:domain uko-code:Callable ;
    rdfs:range xsd:string ;
    rdfs:label "hasParameters" ;
    rdfs:comment "JSON-encoded parameter list." .

uko-code:testsCallable a owl:ObjectProperty ;
    rdfs:domain uko-code:TestCase ;
    rdfs:range uko-code:Callable ;
    rdfs:label "testsCallable" ;
    rdfs:comment "Links a test case to the callable it tests." .

# ===========================================================================
# Layer 1: Documents  (uko-doc:)
# ===========================================================================

# -- Container Classes --

uko-doc:Document a owl:Class ;
    rdfs:subClassOf uko:Container ;
    rdfs:label "Document" ;
    rdfs:comment "A complete document (article, report, manual, specification)." .

uko-doc:Part a owl:Class ;
    rdfs:subClassOf uko:Container ;
    rdfs:label "Part" ;
    rdfs:comment "A top-level division of a document (e.g., Part I, Part II)." .

uko-doc:Chapter a owl:Class ;
    rdfs:subClassOf uko:Container ;
    rdfs:label "Chapter" ;
    rdfs:comment "A chapter within a document or part." .

uko-doc:Section a owl:Class ;
    rdfs:subClassOf uko:Container ;
    rdfs:label "Section" ;
    rdfs:comment "A numbered or titled section within a chapter." .

uko-doc:Subsection a owl:Class ;
    rdfs:subClassOf uko-doc:Section ;
    rdfs:label "Subsection" ;
    rdfs:comment "A subsection nested within a section (arbitrary depth)." .

# -- Atom Classes --

uko-doc:Paragraph a owl:Class ;
    rdfs:subClassOf uko:Atom ;
    rdfs:label "Paragraph" ;
    rdfs:comment "A paragraph of prose text." .

uko-doc:CodeBlock a owl:Class ;
    rdfs:subClassOf uko:Atom ;
    rdfs:label "CodeBlock" ;
    rdfs:comment "An inline code listing or example within a document." .

uko-doc:Figure a owl:Class ;
    rdfs:subClassOf uko:Atom ;
    rdfs:label "Figure" ;
    rdfs:comment "A figure, diagram, or image with an optional caption." .

uko-doc:Table a owl:Class ;
    rdfs:subClassOf uko:Atom ;
    rdfs:label "Table" ;
    rdfs:comment "A tabular data element within a document." .

uko-doc:BlockQuote a owl:Class ;
    rdfs:subClassOf uko:Atom ;
    rdfs:label "BlockQuote" ;
    rdfs:comment "A quoted passage from another source." .

uko-doc:ListBlock a owl:Class ;
    rdfs:subClassOf uko:Atom ;
    rdfs:label "ListBlock" ;
    rdfs:comment "An ordered or unordered list." .

# -- Annotation Classes --

uko-doc:Footnote a owl:Class ;
    rdfs:subClassOf uko:Annotation ;
    rdfs:label "Footnote" ;
    rdfs:comment "A footnote or endnote." .

uko-doc:Citation a owl:Class ;
    rdfs:subClassOf uko:Annotation ;
    rdfs:label "Citation" ;
    rdfs:comment "A bibliographic citation or reference." .

uko-doc:Comment a owl:Class ;
    rdfs:subClassOf uko:Annotation ;
    rdfs:label "Comment" ;
    rdfs:comment "An editorial comment or annotation (e.g., HTML comment, review note)." .

# -- Boundary Classes --

uko-doc:TableOfContents a owl:Class ;
    rdfs:subClassOf uko:Boundary ;
    rdfs:label "TableOfContents" ;
    rdfs:comment "The document's table of contents -- an interface into the document's structure." .

uko-doc:Index a owl:Class ;
    rdfs:subClassOf uko:Boundary ;
    rdfs:label "Index" ;
    rdfs:comment "A back-of-book index or keyword index." .

uko-doc:Glossary a owl:Class ;
    rdfs:subClassOf uko:Boundary ;
    rdfs:label "Glossary" ;
    rdfs:comment "A glossary of terms defined in the document." .

# -- uko-doc: Relationships --

uko-doc:discussesTopic a owl:ObjectProperty ;
    rdfs:subPropertyOf uko:references ;
    rdfs:domain uko:InformationUnit ;
    rdfs:range uko:InformationUnit ;
    rdfs:label "discussesTopic" ;
    rdfs:comment "Semantic relationship: this unit discusses a topic that is the subject of another unit." .

uko-doc:cites a owl:ObjectProperty ;
    rdfs:subPropertyOf uko:references ;
    rdfs:domain uko:InformationUnit ;
    rdfs:range uko-doc:Citation ;
    rdfs:label "cites" ;
    rdfs:comment "This unit cites a bibliographic reference." .

uko-doc:crossReferences a owl:ObjectProperty ;
    rdfs:subPropertyOf uko:references ;
    rdfs:domain uko:InformationUnit ;
    rdfs:range uko:InformationUnit ;
    rdfs:label "crossReferences" ;
    rdfs:comment "Explicit cross-reference (e.g., 'see Section 3.2')." .

uko-doc:precedes a owl:ObjectProperty ;
    rdfs:domain uko:InformationUnit ;
    rdfs:range uko:InformationUnit ;
    rdfs:label "precedes" ;
    rdfs:comment "Reading order: this unit comes before the target unit." .

# -- uko-doc: Datatype Properties --

uko-doc:headingLevel a owl:DatatypeProperty ;
    rdfs:domain uko-doc:Section ;
    rdfs:range xsd:integer ;
    rdfs:label "headingLevel" ;
    rdfs:comment "The nesting depth of this section (1 = top-level, 2 = subsection, etc.)." .

uko-doc:headingText a owl:DatatypeProperty ;
    rdfs:domain uko-doc:Section ;
    rdfs:range xsd:string ;
    rdfs:label "headingText" ;
    rdfs:comment "The title/heading text of this section." .

uko-doc:wordCount a owl:DatatypeProperty ;
    rdfs:domain uko:InformationUnit ;
    rdfs:range xsd:integer ;
    rdfs:label "wordCount" ;
    rdfs:comment "Word count of the text content in this unit." .

uko-doc:language a owl:DatatypeProperty ;
    rdfs:domain uko-doc:Document ;
    rdfs:range xsd:string ;
    rdfs:label "language" ;
    rdfs:comment "Natural language of the document (e.g., 'en', 'fr')." .

uko-doc:topicKeywords a owl:DatatypeProperty ;
    rdfs:domain uko:InformationUnit ;
    rdfs:range xsd:string ;
    rdfs:label "topicKeywords" ;
    rdfs:comment "JSON-encoded list of topic keywords extracted from this unit." .

# ===========================================================================
# Layer 1: Data Schemas  (uko-data:)
# ===========================================================================

# -- Container Classes --

uko-data:Database a owl:Class ;
    rdfs:subClassOf uko:Container ;
    rdfs:label "Database" ;
    rdfs:comment "A database instance containing schemas." .

uko-data:Schema a owl:Class ;
    rdfs:subClassOf uko:Container ;
    rdfs:label "Schema" ;
    rdfs:comment "A database schema (namespace for tables, views, etc.)." .

uko-data:Table a owl:Class ;
    rdfs:subClassOf uko:Container ;
    rdfs:label "Table" ;
    rdfs:comment "A database table containing columns." .

uko-data:View a owl:Class ;
    rdfs:subClassOf uko:Container ;
    rdfs:label "View" ;
    rdfs:comment "A database view (virtual table defined by a query)." .

# -- Atom Classes --

uko-data:Column a owl:Class ;
    rdfs:subClassOf uko:Atom ;
    rdfs:label "Column" ;
    rdfs:comment "A column within a table or view." .

uko-data:StoredProcedure a owl:Class ;
    rdfs:subClassOf uko:Atom ;
    rdfs:label "StoredProcedure" ;
    rdfs:comment "A stored procedure or function in the database." .

uko-data:Trigger a owl:Class ;
    rdfs:subClassOf uko:Atom ;
    rdfs:label "Trigger" ;
    rdfs:comment "A database trigger." .

uko-data:Migration a owl:Class ;
    rdfs:subClassOf uko:Atom ;
    rdfs:label "Migration" ;
    rdfs:comment "A schema migration (DDL change script)." .

# -- Annotation Classes --

uko-data:Constraint a owl:Class ;
    rdfs:subClassOf uko:Annotation ;
    rdfs:label "Constraint" ;
    rdfs:comment "A column or table constraint (NOT NULL, UNIQUE, CHECK, etc.)." .

uko-data:Index a owl:Class ;
    rdfs:subClassOf uko:Annotation ;
    rdfs:label "Index" ;
    rdfs:comment "A database index on one or more columns." .

uko-data:ColumnComment a owl:Class ;
    rdfs:subClassOf uko:Annotation ;
    rdfs:label "ColumnComment" ;
    rdfs:comment "A COMMENT ON COLUMN annotation in the database." .

# -- Boundary Classes --

uko-data:ForeignKey a owl:Class ;
    rdfs:subClassOf uko:Boundary ;
    rdfs:label "ForeignKey" ;
    rdfs:comment "A foreign key constraint -- an interface point between tables." .

uko-data:APIEndpoint a owl:Class ;
    rdfs:subClassOf uko:Boundary ;
    rdfs:label "APIEndpoint" ;
    rdfs:comment "A database-level API endpoint (e.g., PostgREST, GraphQL)." .

# -- uko-data: Relationships --

uko-data:foreignKeyTo a owl:ObjectProperty ;
    rdfs:subPropertyOf uko:dependsOn ;
    rdfs:domain uko-data:Column ;
    rdfs:range uko-data:Column ;
    rdfs:label "foreignKeyTo" ;
    rdfs:comment "Foreign key relationship from this column to a column in another table." .

uko-data:viewReferences a owl:ObjectProperty ;
    rdfs:subPropertyOf uko:dependsOn ;
    rdfs:domain uko-data:View ;
    rdfs:range uko-data:Table ;
    rdfs:label "viewReferences" ;
    rdfs:comment "This view's query references columns from the target table." .

uko-data:procedureAccesses a owl:ObjectProperty ;
    rdfs:subPropertyOf uko:dependsOn ;
    rdfs:domain uko-data:StoredProcedure ;
    rdfs:range uko-data:Table ;
    rdfs:label "procedureAccesses" ;
    rdfs:comment "This stored procedure reads from or writes to the target table." .

uko-data:triggerFires a owl:ObjectProperty ;
    rdfs:subPropertyOf uko:dependsOn ;
    rdfs:domain uko-data:Trigger ;
    rdfs:range uko-data:Table ;
    rdfs:label "triggerFires" ;
    rdfs:comment "This trigger fires on events on the target table." .

uko-data:migrationAlters a owl:ObjectProperty ;
    rdfs:subPropertyOf uko:dependsOn ;
    rdfs:domain uko-data:Migration ;
    rdfs:range uko-data:Table ;
    rdfs:label "migrationAlters" ;
    rdfs:comment "This migration modifies the schema of the target table." .

# -- uko-data: Datatype Properties --

uko-data:dataType a owl:DatatypeProperty ;
    rdfs:domain uko-data:Column ;
    rdfs:range xsd:string ;
    rdfs:label "dataType" ;
    rdfs:comment "SQL data type (e.g., 'VARCHAR(255)', 'INTEGER', 'JSONB')." .

uko-data:isNullable a owl:DatatypeProperty ;
    rdfs:domain uko-data:Column ;
    rdfs:range xsd:boolean ;
    rdfs:label "isNullable" .

uko-data:isPrimaryKey a owl:DatatypeProperty ;
    rdfs:domain uko-data:Column ;
    rdfs:range xsd:boolean ;
    rdfs:label "isPrimaryKey" .

uko-data:rowEstimate a owl:DatatypeProperty ;
    rdfs:domain uko-data:Table ;
    rdfs:range xsd:long ;
    rdfs:label "rowEstimate" ;
    rdfs:comment "Estimated row count from database statistics." .

uko-data:viewDefinition a owl:DatatypeProperty ;
    rdfs:domain uko-data:View ;
    rdfs:range xsd:string ;
    rdfs:label "viewDefinition" ;
    rdfs:comment "The SQL query that defines this view." .

uko-data:procedureBody a owl:DatatypeProperty ;
    rdfs:domain uko-data:StoredProcedure ;
    rdfs:range xsd:string ;
    rdfs:label "procedureBody" ;
    rdfs:comment "The SQL/PL body of the stored procedure." .

# ===========================================================================
# Layer 1: Infrastructure  (uko-infra:)
# ===========================================================================

# -- Container Classes --

uko-infra:Service a owl:Class ;
    rdfs:subClassOf uko:Container ;
    rdfs:label "Service" ;
    rdfs:comment "A deployable service or application." .

uko-infra:ConfigBlock a owl:Class ;
    rdfs:subClassOf uko:Container ;
    rdfs:label "ConfigBlock" ;
    rdfs:comment "A configuration block or section (e.g., a YAML map, TOML table)." .

uko-infra:DeploymentUnit a owl:Class ;
    rdfs:subClassOf uko:Container ;
    rdfs:label "DeploymentUnit" ;
    rdfs:comment "A deployment unit (e.g., Kubernetes Deployment, Docker Compose service)." .

# -- Atom Classes --

uko-infra:ConfigKey a owl:Class ;
    rdfs:subClassOf uko:Atom ;
    rdfs:label "ConfigKey" ;
    rdfs:comment "A configuration key-value pair." .

uko-infra:EnvironmentVariable a owl:Class ;
    rdfs:subClassOf uko:Atom ;
    rdfs:label "EnvironmentVariable" ;
    rdfs:comment "An environment variable definition." .

# -- Boundary Classes --

uko-infra:Endpoint a owl:Class ;
    rdfs:subClassOf uko:Boundary ;
    rdfs:label "Endpoint" ;
    rdfs:comment "A network endpoint (HTTP route, gRPC service, message queue)." .

uko-infra:Port a owl:Class ;
    rdfs:subClassOf uko:Boundary ;
    rdfs:label "Port" ;
    rdfs:comment "A network port binding." .

# -- uko-infra: Relationships --

uko-infra:connectsTo a owl:ObjectProperty ;
    rdfs:subPropertyOf uko:dependsOn ;
    rdfs:domain uko-infra:Service ;
    rdfs:range uko-infra:Service ;
    rdfs:label "connectsTo" ;
    rdfs:comment "This service connects to or depends on the target service." .

uko-infra:exposes a owl:ObjectProperty ;
    rdfs:domain uko-infra:Service ;
    rdfs:range uko-infra:Endpoint ;
    rdfs:label "exposes" ;
    rdfs:comment "This service exposes the target endpoint." .

# ===========================================================================
# Layer 2: Object-Oriented Paradigm  (uko-oo:)
# ===========================================================================

uko-oo:Class a owl:Class ;
    rdfs:subClassOf uko-code:TypeDefinition , uko:Container ;
    rdfs:label "Class" ;
    rdfs:comment "An OO class that contains methods and attributes." .

uko-oo:Interface a owl:Class ;
    rdfs:subClassOf uko-code:TypeDefinition , uko:Boundary ;
    rdfs:label "Interface" ;
    rdfs:comment "An interface or abstract base class." .

uko-oo:Method a owl:Class ;
    rdfs:subClassOf uko-code:Callable ;
    rdfs:label "Method" ;
    rdfs:comment "A method defined within a class." .

uko-oo:Attribute a owl:Class ;
    rdfs:subClassOf uko:Atom ;
    rdfs:label "Attribute" ;
    rdfs:comment "A class or instance attribute." .

# -- Layer 2 Properties --

uko-oo:inheritsFrom a owl:ObjectProperty ;
    rdfs:subPropertyOf uko:dependsOn ;
    rdfs:domain uko-oo:Class ;
    rdfs:range uko-oo:Class ;
    rdfs:label "inheritsFrom" .

uko-oo:implements a owl:ObjectProperty ;
    rdfs:subPropertyOf uko:dependsOn ;
    rdfs:domain uko-oo:Class ;
    rdfs:range uko-oo:Interface ;
    rdfs:label "implements" .

# ===========================================================================
# Layer 3: Technology-Specific Specializations
# ===========================================================================
# Layer 3 extends Layer 2 (or Layer 1) with technology-specific refinements.
# Per the specification, Layer 3 is defined via DetailLevelMap insertions
# rather than new OWL classes.  The uko-py: prefix is reserved for
# Python-specific extensions when DetailLevelMap support is added.
