DOI: 10.6084/m9.figshare.29399987
title: The codes and data for "Geospatial Knowledge Cube: Enhancing Semantic Query in Geospatial Data Cubes with Ontology and LLMs"

description: Geospatial Knowledge Cube: Enhancing Semantic Query in Geospatial Data Cubes with Ontology and LLMsProject OverviewGeospatial Knowledge Cube is an extension of GeoCube, enhanced with ontology-based semantics to enable interaction with Large Language Models (LLMs) for semantic querying.The project directory is structured as follows:<pre><pre>├── ontology/<br>│ ├── gkc_ontology_benchmark.ttl<br>│ └── gkc_ontology_error_analysis.ttl<br>├── mapping/<br>│ ├── gkc_mapping_benchmark.obda<br>│ └── gkc_mapping_error_analysis.obda<br>├── database/<br>│ ├── database.dump<br>│ └── goldenSQL/<br>│ ├── Q1.sql<br>│ ├── Q2.sql<br>│ └── ...<br>├── codes/<br>│ ├── experiment.py<br>│ ├── prompt_template.py<br>│ ├── question/<br>│ ├── generate_benchmark_query/<br>│ └── expanded_error_analysis_query/<br>└── README.md<br></pre></pre>Environment and dependenciesJava Development Kit (JDK) 11Python 3.10+PostgreSQLPostGIS extension for PostgreSQLOntop-Protégé for ontology-based OBDA mappingTwo experiment configurationsThis repository contains two ontology + mapping configurations.<b>A) Benchmark configuration (main evaluation)</b>Ontology: <code>ontology/gkc_ontology_benchmark.ttl</code>Mapping: <code>mapping/gkc_mapping_benchmark.obda</code>Questions: <code>codes/question/benchmark_question.csv</code> <i>(81 questions)</i>Outputs: <code>codes/generate_benchmark_query/</code>Used for: all benchmark results except <b>Tables 3 & 4</b>.<b>B) Error-analysis configuration (fine-grained diagnosis)</b>Ontology: <code>ontology/gkc_ontology_error_analysis.ttl</code>Mapping: <code>mapping/gkc_mapping_error_analysis.obda</code>Questions: <code>codes/question/error_analysis_question.csv</code> <i>(10 questions)</i>Outputs: <code>codes/expanded_error_analysis_query/</code>Used for: <b>Table 4</b> only.Step 1: Data ImportThe file <code>database/database.dump</code> was generated using <code>pg_dump</code> and contains a full PostgreSQL database backup, including schema and data.Create database: <code>createdb geocube_db</code>Restore dump: <code>pg_restore -U your_username -d geocube_db database/database.dump</code>Enable extensions: <code>CREATE EXTENSION postgis; CREATE EXTENSION postgis_raster;</code>Step 2: Semantic Layer ConstructionOpen Protégé and load the ontology from the <code>ontology/</code> folder.Use the Ontop Plugin in Protégé to create or load OBDA mappings that link ontology classes/properties to the underlying PostgreSQL schema.Load the corresponding <code>.obda</code> mapping file from the <code>mapping/</code> folder.Configure the database connection and test queries directly in Protégé.Alternatively, you can use Ontop CLI to perform the same task by:configuring <code>ontop.obda</code> and <code>.properties</code> filesrunning the Ontop CLI reasoner for SPARQL-to-SQL translationStep 3: Question DesignIn the paper, we classify data querying tasks along two dimensions — schema complexity and question complexity — forming a 3×3 grid. Each cell contains 9 questions, totaling <b>81 questions</b>.All questions are documented in <code>codes/question/benchmark_question.csv</code>, where each entry includes:Natural language questionGolden SQL query <i>(you can find it in the </i><code><em>database/goldenSQL</em></code><i> directory)</i>Step 4: Experiment ScriptAll experiments are implemented in a single Python script under <code>codes/experiment.py</code>. Please run the python script:<pre><pre>python {python_project_root}/codes/experiment.py<br></pre></pre>Key components:<code>chat()</code> function is the main entry point.Experiments corresponding to <b>Figures 6–8</b> in the paper are located in:<code>gpt-3.5-turbo</code> experiments<code>gpt-4o</code> experimentsBefore running the script:Insert your OpenAI API key in the appropriate location.<i>(Optional)</i> Update database connection parameters if using a local PostgreSQL instance.<i>(Optional)</i> Update Ontop CLI connection settings if running SPARQL experiments.The script supports <i>temperature parameter tuning</i> to evaluate generation robustness under different conditions.Step 5: Data Logging and AnalysisDuring experiments, the following metrics are collected:<b>Overall Accuracy</b>: Results corresponding to <b>Tables 2</b> in the paper.<b>Error Analysis</b>: Results corresponding to <b>Tables 4</b> in the paper.<b>Stability Across Multiple Runs</b>: Insights visualized in <b>Figure 7</b>.<b>Token Usage and Cost</b>: Analysis presented in <b>Figure 8</b>.<b>Note:</b> These metrics are logged during execution. No automatic aggregation script is included. Aggregation was performed manually during the study; the raw logs in <code>codes/</code> can be used to reproduce the reported numbers.