@prefix dwh: <https://ggen.ai/ontology/data-warehouse#> .
@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#> .
@prefix dcterms: <http://purl.org/dc/terms/> .

# Ontology Definition
dwh: a owl:Ontology ;
    dcterms:title "Data Warehouse & ETL Ontology" ;
    dcterms:description "Enterprise data warehouse, ETL pipelines, dimensional modeling, and data quality" ;
    dcterms:created "2025-01-08"^^xsd:date ;
    owl:versionInfo "1.0.0" .

# ============================================================================
# CORE CLASSES - Data Warehouse
# ============================================================================

dwh:DataWarehouse a owl:Class ;
    rdfs:label "Data Warehouse" ;
    rdfs:comment "Central data warehouse repository" .

dwh:DataMart a owl:Class ;
    rdfs:label "Data Mart" ;
    rdfs:comment "Subject-specific subset of data warehouse" .

dwh:DataLake a owl:Class ;
    rdfs:label "Data Lake" ;
    rdfs:comment "Raw data storage lake" .

dwh:StagingArea a owl:Class ;
    rdfs:label "Staging Area" ;
    rdfs:comment "Temporary staging for ETL processing" .

dwh:ODS a owl:Class ;
    rdfs:label "Operational Data Store (ODS)" ;
    rdfs:comment "Near real-time operational data store" .

# ============================================================================
# DIMENSIONAL MODELING CLASSES
# ============================================================================

dwh:DimensionalModel a owl:Class ;
    rdfs:label "Dimensional Model" ;
    rdfs:comment "Star or snowflake schema model" .

dwh:FactTable a owl:Class ;
    rdfs:label "Fact Table" ;
    rdfs:comment "Central fact table with measures" .

dwh:DimensionTable a owl:Class ;
    rdfs:label "Dimension Table" ;
    rdfs:comment "Dimension table with attributes" .

dwh:Measure a owl:Class ;
    rdfs:label "Measure" ;
    rdfs:comment "Quantitative metric in fact table" .

dwh:Dimension a owl:Class ;
    rdfs:label "Dimension" ;
    rdfs:comment "Dimension for analysis" .

dwh:Hierarchy a owl:Class ;
    rdfs:label "Hierarchy" ;
    rdfs:comment "Dimensional hierarchy (year > quarter > month)" .

dwh:Level a owl:Class ;
    rdfs:label "Level" ;
    rdfs:comment "Level in dimensional hierarchy" .

dwh:Attribute a owl:Class ;
    rdfs:label "Attribute" ;
    rdfs:comment "Dimension attribute" .

# ============================================================================
# SCHEMA PATTERNS
# ============================================================================

dwh:StarSchema a owl:Class ;
    rdfs:subClassOf dwh:DimensionalModel ;
    rdfs:label "Star Schema" ;
    rdfs:comment "Star schema with denormalized dimensions" .

dwh:SnowflakeSchema a owl:Class ;
    rdfs:subClassOf dwh:DimensionalModel ;
    rdfs:label "Snowflake Schema" ;
    rdfs:comment "Snowflake schema with normalized dimensions" .

dwh:GalaxySchema a owl:Class ;
    rdfs:subClassOf dwh:DimensionalModel ;
    rdfs:label "Galaxy Schema" ;
    rdfs:comment "Multiple fact tables sharing dimensions" .

# ============================================================================
# SLOWLY CHANGING DIMENSIONS
# ============================================================================

dwh:SlowlyChangingDimension a owl:Class ;
    rdfs:label "Slowly Changing Dimension (SCD)" ;
    rdfs:comment "Dimension with change tracking" .

dwh:SCD_Type1 a owl:Class ;
    rdfs:subClassOf dwh:SlowlyChangingDimension ;
    rdfs:label "SCD Type 1" ;
    rdfs:comment "Overwrite with no history" .

dwh:SCD_Type2 a owl:Class ;
    rdfs:subClassOf dwh:SlowlyChangingDimension ;
    rdfs:label "SCD Type 2" ;
    rdfs:comment "Add new row with history" .

dwh:SCD_Type3 a owl:Class ;
    rdfs:subClassOf dwh:SlowlyChangingDimension ;
    rdfs:label "SCD Type 3" ;
    rdfs:comment "Add previous value column" .

# ============================================================================
# ETL PIPELINE CLASSES
# ============================================================================

dwh:ETL_Pipeline a owl:Class ;
    rdfs:label "ETL Pipeline" ;
    rdfs:comment "Extract, Transform, Load pipeline" .

dwh:Extract a owl:Class ;
    rdfs:label "Extract" ;
    rdfs:comment "Data extraction stage" .

dwh:Transform a owl:Class ;
    rdfs:label "Transform" ;
    rdfs:comment "Data transformation stage" .

dwh:Load a owl:Class ;
    rdfs:label "Load" ;
    rdfs:comment "Data loading stage" .

dwh:ELT_Pipeline a owl:Class ;
    rdfs:label "ELT Pipeline" ;
    rdfs:comment "Extract, Load, Transform pipeline" .

dwh:DataSource a owl:Class ;
    rdfs:label "Data Source" ;
    rdfs:comment "Source system for extraction" .

dwh:DataTarget a owl:Class ;
    rdfs:label "Data Target" ;
    rdfs:comment "Target destination for loading" .

# ============================================================================
# TRANSFORMATION CLASSES
# ============================================================================

dwh:Transformation a owl:Class ;
    rdfs:label "Transformation" ;
    rdfs:comment "Data transformation operation" .

dwh:Mapping a owl:Class ;
    rdfs:label "Mapping" ;
    rdfs:comment "Source-to-target field mapping" .

dwh:Aggregation a owl:Class ;
    rdfs:subClassOf dwh:Transformation ;
    rdfs:label "Aggregation" ;
    rdfs:comment "Aggregate transformation (SUM, AVG, COUNT)" .

dwh:Join a owl:Class ;
    rdfs:subClassOf dwh:Transformation ;
    rdfs:label "Join" ;
    rdfs:comment "Join transformation" .

dwh:Filter a owl:Class ;
    rdfs:subClassOf dwh:Transformation ;
    rdfs:label "Filter" ;
    rdfs:comment "Filter/WHERE clause transformation" .

dwh:Lookup a owl:Class ;
    rdfs:subClassOf dwh:Transformation ;
    rdfs:label "Lookup" ;
    rdfs:comment "Lookup/reference data enrichment" .

dwh:Deduplication a owl:Class ;
    rdfs:subClassOf dwh:Transformation ;
    rdfs:label "Deduplication" ;
    rdfs:comment "Remove duplicate records" .

dwh:Normalization a owl:Class ;
    rdfs:subClassOf dwh:Transformation ;
    rdfs:label "Normalization" ;
    rdfs:comment "Data normalization (dates, formats)" .

# ============================================================================
# CDC CLASSES
# ============================================================================

dwh:ChangeDataCapture a owl:Class ;
    rdfs:label "Change Data Capture (CDC)" ;
    rdfs:comment "Real-time change capture mechanism" .

dwh:CDC_LogBased a owl:Class ;
    rdfs:subClassOf dwh:ChangeDataCapture ;
    rdfs:label "Log-Based CDC" ;
    rdfs:comment "Transaction log-based CDC" .

dwh:CDC_Trigger a owl:Class ;
    rdfs:subClassOf dwh:ChangeDataCapture ;
    rdfs:label "Trigger-Based CDC" ;
    rdfs:comment "Database trigger CDC" .

dwh:CDC_Timestamp a owl:Class ;
    rdfs:subClassOf dwh:ChangeDataCapture ;
    rdfs:label "Timestamp-Based CDC" ;
    rdfs:comment "Modified timestamp CDC" .

# ============================================================================
# DATA QUALITY CLASSES
# ============================================================================

dwh:DataQuality a owl:Class ;
    rdfs:label "Data Quality" ;
    rdfs:comment "Data quality framework" .

dwh:DataValidation a owl:Class ;
    rdfs:label "Data Validation" ;
    rdfs:comment "Data validation rule" .

dwh:DataProfiling a owl:Class ;
    rdfs:label "Data Profiling" ;
    rdfs:comment "Profile data statistics" .

dwh:DataCleansing a owl:Class ;
    rdfs:label "Data Cleansing" ;
    rdfs:comment "Data cleansing operation" .

dwh:QualityRule a owl:Class ;
    rdfs:label "Quality Rule" ;
    rdfs:comment "Data quality rule" .

dwh:QualityMetric a owl:Class ;
    rdfs:label "Quality Metric" ;
    rdfs:comment "Data quality metric (completeness, accuracy)" .

# ============================================================================
# PARTITIONING & INDEXING
# ============================================================================

dwh:Partitioning a owl:Class ;
    rdfs:label "Partitioning" ;
    rdfs:comment "Table partitioning strategy" .

dwh:RangePartition a owl:Class ;
    rdfs:subClassOf dwh:Partitioning ;
    rdfs:label "Range Partition" ;
    rdfs:comment "Range-based partitioning (dates)" .

dwh:HashPartition a owl:Class ;
    rdfs:subClassOf dwh:Partitioning ;
    rdfs:label "Hash Partition" ;
    rdfs:comment "Hash-based partitioning" .

dwh:ListPartition a owl:Class ;
    rdfs:subClassOf dwh:Partitioning ;
    rdfs:label "List Partition" ;
    rdfs:comment "List value partitioning" .

dwh:Index a owl:Class ;
    rdfs:label "Index" ;
    rdfs:comment "Database index" .

dwh:BTreeIndex a owl:Class ;
    rdfs:subClassOf dwh:Index ;
    rdfs:label "B-Tree Index" ;
    rdfs:comment "Balanced tree index" .

dwh:BitmapIndex a owl:Class ;
    rdfs:subClassOf dwh:Index ;
    rdfs:label "Bitmap Index" ;
    rdfs:comment "Bitmap index for low cardinality" .

dwh:ColumnStore a owl:Class ;
    rdfs:label "Column Store" ;
    rdfs:comment "Columnar storage format" .

# ============================================================================
# QUERY OPTIMIZATION
# ============================================================================

dwh:QueryOptimization a owl:Class ;
    rdfs:label "Query Optimization" ;
    rdfs:comment "Query performance optimization" .

dwh:MaterializedView a owl:Class ;
    rdfs:label "Materialized View" ;
    rdfs:comment "Pre-computed view" .

dwh:AggregateTable a owl:Class ;
    rdfs:label "Aggregate Table" ;
    rdfs:comment "Pre-aggregated summary table" .

dwh:QueryCache a owl:Class ;
    rdfs:label "Query Cache" ;
    rdfs:comment "Cached query results" .

dwh:PartitionPruning a owl:Class ;
    rdfs:label "Partition Pruning" ;
    rdfs:comment "Skip irrelevant partitions" .

# ============================================================================
# DATA LINEAGE & METADATA
# ============================================================================

dwh:DataLineage a owl:Class ;
    rdfs:label "Data Lineage" ;
    rdfs:comment "End-to-end data lineage tracking" .

dwh:LineageEdge a owl:Class ;
    rdfs:label "Lineage Edge" ;
    rdfs:comment "Edge in lineage graph" .

dwh:Metadata a owl:Class ;
    rdfs:label "Metadata" ;
    rdfs:comment "Data warehouse metadata" .

dwh:TechnicalMetadata a owl:Class ;
    rdfs:subClassOf dwh:Metadata ;
    rdfs:label "Technical Metadata" ;
    rdfs:comment "Technical schema metadata" .

dwh:BusinessMetadata a owl:Class ;
    rdfs:subClassOf dwh:Metadata ;
    rdfs:label "Business Metadata" ;
    rdfs:comment "Business glossary and definitions" .

dwh:DataCatalog a owl:Class ;
    rdfs:label "Data Catalog" ;
    rdfs:comment "Searchable data catalog" .

# ============================================================================
# SCHEDULING & ORCHESTRATION
# ============================================================================

dwh:Scheduler a owl:Class ;
    rdfs:label "Scheduler" ;
    rdfs:comment "ETL job scheduler" .

dwh:Job a owl:Class ;
    rdfs:label "Job" ;
    rdfs:comment "ETL job definition" .

dwh:JobRun a owl:Class ;
    rdfs:label "Job Run" ;
    rdfs:comment "Individual job execution" .

dwh:Dependency a owl:Class ;
    rdfs:label "Dependency" ;
    rdfs:comment "Job dependency relationship" .

dwh:Trigger a owl:Class ;
    rdfs:label "Trigger" ;
    rdfs:comment "Job trigger (schedule, event)" .

# ============================================================================
# PROPERTIES - Dimensional Model
# ============================================================================

dwh:tableName a owl:DatatypeProperty ;
    rdfs:domain dwh:FactTable ;
    rdfs:range xsd:string ;
    rdfs:label "table name" ;
    rdfs:comment "Name of the table" .

dwh:measureName a owl:DatatypeProperty ;
    rdfs:domain dwh:Measure ;
    rdfs:range xsd:string ;
    rdfs:label "measure name" ;
    rdfs:comment "Name of the measure" .

dwh:aggregationType a owl:DatatypeProperty ;
    rdfs:domain dwh:Measure ;
    rdfs:range xsd:string ;
    rdfs:label "aggregation type" ;
    rdfs:comment "SUM, AVG, COUNT, MIN, MAX" .

dwh:dimensionName a owl:DatatypeProperty ;
    rdfs:domain dwh:Dimension ;
    rdfs:range xsd:string ;
    rdfs:label "dimension name" ;
    rdfs:comment "Name of the dimension" .

dwh:scdType a owl:DatatypeProperty ;
    rdfs:domain dwh:SlowlyChangingDimension ;
    rdfs:range xsd:integer ;
    rdfs:label "SCD type" ;
    rdfs:comment "SCD type (1, 2, 3, etc.)" .

# ============================================================================
# PROPERTIES - ETL Pipeline
# ============================================================================

dwh:pipelineName a owl:DatatypeProperty ;
    rdfs:domain dwh:ETL_Pipeline ;
    rdfs:range xsd:string ;
    rdfs:label "pipeline name" ;
    rdfs:comment "Name of ETL pipeline" .

dwh:sourceSystem a owl:DatatypeProperty ;
    rdfs:domain dwh:DataSource ;
    rdfs:range xsd:string ;
    rdfs:label "source system" ;
    rdfs:comment "Source system identifier" .

dwh:extractQuery a owl:DatatypeProperty ;
    rdfs:domain dwh:Extract ;
    rdfs:range xsd:string ;
    rdfs:label "extract query" ;
    rdfs:comment "SQL query for extraction" .

dwh:transformationLogic a owl:DatatypeProperty ;
    rdfs:domain dwh:Transform ;
    rdfs:range xsd:string ;
    rdfs:label "transformation logic" ;
    rdfs:comment "Transformation SQL or code" .

dwh:loadStrategy a owl:DatatypeProperty ;
    rdfs:domain dwh:Load ;
    rdfs:range xsd:string ;
    rdfs:label "load strategy" ;
    rdfs:comment "Full, incremental, upsert" .

dwh:batchSize a owl:DatatypeProperty ;
    rdfs:domain dwh:Load ;
    rdfs:range xsd:integer ;
    rdfs:label "batch size" ;
    rdfs:comment "Number of rows per batch" .

# ============================================================================
# PROPERTIES - Data Quality
# ============================================================================

dwh:validationRule a owl:DatatypeProperty ;
    rdfs:domain dwh:DataValidation ;
    rdfs:range xsd:string ;
    rdfs:label "validation rule" ;
    rdfs:comment "Validation expression" .

dwh:completenessScore a owl:DatatypeProperty ;
    rdfs:domain dwh:QualityMetric ;
    rdfs:range xsd:decimal ;
    rdfs:label "completeness score" ;
    rdfs:comment "Data completeness percentage" .

dwh:accuracyScore a owl:DatatypeProperty ;
    rdfs:domain dwh:QualityMetric ;
    rdfs:range xsd:decimal ;
    rdfs:label "accuracy score" ;
    rdfs:comment "Data accuracy percentage" .

# ============================================================================
# PROPERTIES - Partitioning
# ============================================================================

dwh:partitionColumn a owl:DatatypeProperty ;
    rdfs:domain dwh:Partitioning ;
    rdfs:range xsd:string ;
    rdfs:label "partition column" ;
    rdfs:comment "Column used for partitioning" .

dwh:partitionGranularity a owl:DatatypeProperty ;
    rdfs:domain dwh:RangePartition ;
    rdfs:range xsd:string ;
    rdfs:label "partition granularity" ;
    rdfs:comment "Daily, monthly, yearly" .

# ============================================================================
# PROPERTIES - Job Execution
# ============================================================================

dwh:scheduleExpression a owl:DatatypeProperty ;
    rdfs:domain dwh:Scheduler ;
    rdfs:range xsd:string ;
    rdfs:label "schedule expression" ;
    rdfs:comment "Cron expression for scheduling" .

dwh:startTime a owl:DatatypeProperty ;
    rdfs:domain dwh:JobRun ;
    rdfs:range xsd:dateTime ;
    rdfs:label "start time" ;
    rdfs:comment "Job start timestamp" .

dwh:endTime a owl:DatatypeProperty ;
    rdfs:domain dwh:JobRun ;
    rdfs:range xsd:dateTime ;
    rdfs:label "end time" ;
    rdfs:comment "Job end timestamp" .

dwh:status a owl:DatatypeProperty ;
    rdfs:domain dwh:JobRun ;
    rdfs:range xsd:string ;
    rdfs:label "status" ;
    rdfs:comment "Success, failed, running" .

dwh:rowsProcessed a owl:DatatypeProperty ;
    rdfs:domain dwh:JobRun ;
    rdfs:range xsd:integer ;
    rdfs:label "rows processed" ;
    rdfs:comment "Number of rows processed" .

# ============================================================================
# OBJECT PROPERTIES - Relationships
# ============================================================================

dwh:hasDimension a owl:ObjectProperty ;
    rdfs:domain dwh:FactTable ;
    rdfs:range dwh:DimensionTable ;
    rdfs:label "has dimension" ;
    rdfs:comment "Fact table connected to dimension" .

dwh:hasMeasure a owl:ObjectProperty ;
    rdfs:domain dwh:FactTable ;
    rdfs:range dwh:Measure ;
    rdfs:label "has measure" ;
    rdfs:comment "Fact table contains measure" .

dwh:hasTransformation a owl:ObjectProperty ;
    rdfs:domain dwh:ETL_Pipeline ;
    rdfs:range dwh:Transformation ;
    rdfs:label "has transformation" ;
    rdfs:comment "Pipeline includes transformation" .

dwh:hasDataSource a owl:ObjectProperty ;
    rdfs:domain dwh:Extract ;
    rdfs:range dwh:DataSource ;
    rdfs:label "has data source" ;
    rdfs:comment "Extract from data source" .

dwh:hasDataTarget a owl:ObjectProperty ;
    rdfs:domain dwh:Load ;
    rdfs:range dwh:DataTarget ;
    rdfs:label "has data target" ;
    rdfs:comment "Load to data target" .

dwh:hasQualityRule a owl:ObjectProperty ;
    rdfs:domain dwh:DataWarehouse ;
    rdfs:range dwh:QualityRule ;
    rdfs:label "has quality rule" ;
    rdfs:comment "Warehouse enforces quality rule" .

dwh:hasPartitioning a owl:ObjectProperty ;
    rdfs:domain dwh:FactTable ;
    rdfs:range dwh:Partitioning ;
    rdfs:label "has partitioning" ;
    rdfs:comment "Table uses partitioning strategy" .

dwh:hasIndex a owl:ObjectProperty ;
    rdfs:domain dwh:FactTable ;
    rdfs:range dwh:Index ;
    rdfs:label "has index" ;
    rdfs:comment "Table has index" .

dwh:hasLineage a owl:ObjectProperty ;
    rdfs:domain dwh:DataTarget ;
    rdfs:range dwh:DataLineage ;
    rdfs:label "has lineage" ;
    rdfs:comment "Target has data lineage" .
