Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

docs: add CLAUDE.md workflow, /ontology-engineer skill, and dynamic flowchart

FABIOTESSe107dba5c29c
diff --git a/CLAUDE.md b/CLAUDE.md
new file mode 100644
index 00000000..d63969a7
--- /dev/null
+++ b/CLAUDE.md
@@ -0,0 +1,70 @@
+# Open Ontologies
+
+## Ontology Engineering Workflow
+
+When building or modifying ontologies, follow this workflow. Claude decides which tools to call and in what order based on results — this is not a fixed pipeline.
+
+### Generate
+
+1. Understand the domain requirements (natural language, competency questions, methodology constraints)
+2. Generate Turtle/OWL directly — Claude knows OWL, RDF, BORO, 4D modeling natively
+
+### Validate and Load
+
+3. Call `onto_validate` on the generated Turtle — if it fails, fix the syntax errors and re-validate
+4. Call `onto_load` to load into the Oxigraph triple store
+5. Call `onto_stats` to verify class count, property count, triple count match expectations
+
+### Verify
+
+6. Call `onto_lint` to check for missing labels, comments, domains, ranges — fix any issues found
+7. Call `onto_query` with SPARQL to verify structure:
+ - Are all expected classes present?
+ - Do subclass hierarchies match the spec?
+ - Can competency questions be answered?
+8. If a reference ontology exists, call `onto_diff` to compare
+
+### Iterate
+
+9. If any step above reveals problems, fix the Turtle and restart from step 3
+10. This loop continues until validation passes, stats match, lint is clean, and SPARQL queries return expected results
+
+### Persist
+
+11. Call `onto_save` to write the final ontology to a .ttl file
+12. Call `onto_version` to save a named snapshot for rollback
+
+### Key Principle
+
+Claude dynamically decides the next tool call based on what the previous tool returned. If `onto_validate` fails, Claude fixes and retries. If `onto_stats` shows wrong counts, Claude regenerates. If `onto_lint` finds missing labels, Claude adds them. The MCP tools are individual operations — Claude is the orchestrator.
+
+## Tool Reference
+
+| Tool | When to use |
+| ---- | ----------- |
+| `onto_validate` | After generating or modifying Turtle — always validate first |
+| `onto_load` | After validation passes — loads into triple store for querying |
+| `onto_stats` | After loading — sanity check on class/property/triple counts |
+| `onto_lint` | After loading — catches missing labels, domains, ranges |
+| `onto_query` | To verify structure, answer competency questions, explore the ontology |
+| `onto_diff` | To compare against a reference or previous version |
+| `onto_save` | To persist the ontology to a file |
+| `onto_convert` | To convert between formats (Turtle, N-Triples, RDF/XML, N-Quads, TriG) |
+| `onto_clear` | To reset the store before loading a different ontology |
+| `onto_pull` | To fetch an ontology from a remote URL or SPARQL endpoint |
+| `onto_push` | To push an ontology to a SPARQL endpoint |
+| `onto_import` | To resolve and load owl:imports chains |
+| `onto_version` | To save a named snapshot before making changes |
+| `onto_history` | To list saved version snapshots |
+| `onto_rollback` | To restore a previous version if something goes wrong |
+
+## Enforcer Rules
+
+OpenCheir enforces workflow safety rules automatically:
+
+- **onto_validate_after_save** — warns if you save 3+ times without validating
+- **onto_version_before_push** — warns if you push without saving a version snapshot first
+
+## Benchmarks
+
+This repo contains reference ontologies and comparison scripts in `benchmark/`. Use them as starting points or to verify the AI-native approach against traditional methods.
diff --git a/README.md b/README.md
index 9c7a679e..34e6bb95 100644
--- a/README.md
+++ b/README.md
@@ -29,43 +29,44 @@ Two projects work together:
## How it works
-You provide domain requirements in natural language. Claude generates Turtle/OWL, then calls the MCP tools to validate, load, query, and persist it — in a loop until it's right.
+You provide domain requirements in natural language. Claude generates Turtle/OWL, then **dynamically decides** which MCP tools to call based on what each tool returns — validating, fixing, re-loading, querying, iterating until the ontology is correct.
-```text
-You: "Build me a Pizza ontology with 49 toppings and 22 named pizzas"
- │
- ▼
- Claude generates Turtle (from its training knowledge)
- │
- ▼
- onto_validate ──→ syntax ok? if not, Claude fixes and retries
- onto_load ──→ loads into Oxigraph triple store
- onto_stats ──→ 95 classes, 8 properties — correct count?
- onto_lint ──→ missing labels? missing domains? Claude fixes
- onto_query ──→ SPARQL to verify structure and competency questions
- onto_save ──→ persists to .ttl file
- onto_version ──→ saves snapshot for rollback
+```mermaid
+flowchart TD
+ You["You — 'Build me a Pizza ontology'"]
+ Claude["Claude generates Turtle"]
+ Validate["onto_validate"]
+ Fix["Claude fixes errors"]
+ Load["onto_load"]
+ Stats["onto_stats"]
+ Lint["onto_lint"]
+ Query["onto_query — SPARQL"]
+ Save["onto_save"]
+ Version["onto_version"]
+
+ You --> Claude
+ Claude --> Validate
+ Validate -->|"syntax errors"| Fix
+ Fix --> Validate
+ Validate -->|"ok"| Load
+ Load --> Stats
+ Stats -->|"wrong counts"| Claude
+ Stats -->|"ok"| Lint
+ Lint -->|"issues"| Fix
+ Lint -->|"clean"| Query
+ Query -->|"gaps found"| Claude
+ Query -->|"all correct"| Version
+ Version --> Save
```
+This is not a fixed pipeline inside the MCP server. The MCP server exposes 15 individual tools — **Claude is the orchestrator** that decides what to call next based on results. If `onto_validate` fails, Claude fixes the Turtle and retries. If `onto_stats` shows wrong counts, Claude regenerates. If `onto_lint` finds missing labels, Claude adds them.
+
No Protege. No GUI. No manual class creation. Claude is the ontology engineer, OpenCheir is the runtime.
-```mermaid
-flowchart TD
- You["You — natural language"]
- Claude["Claude — generates OWL, calls tools"]
- MCP["MCP Protocol (stdio)"]
- OpenCheir["OpenCheir — MCP server (Rust)"]
- Ontology["Ontology Module — 15 tools"]
- Oxigraph["Oxigraph — RDF/SPARQL engine"]
- Files["Files — .ttl, .owl, .nt"]
-
- You -->|"Build me a Pizza ontology"| Claude
- Claude -->|"onto_validate, onto_load, ..."| MCP
- MCP --> OpenCheir
- OpenCheir --> Ontology
- Ontology --> Oxigraph
- Ontology --> Files
-```
+The workflow is codified in two places so Claude follows it consistently:
+
+- **[`CLAUDE.md`](CLAUDE.md)** — loaded automatically when you open Claude Code in this repo. Describes the generate → validate → verify → iterate → persist workflow.
+- **[`/ontology-engineer` skill](skills/ontology-engineer.md)** — portable skill you can use from any project. Invoke it with `/ontology-engineer` in Claude Code.
## Tools
diff --git a/skills/ontology-engineer.md b/skills/ontology-engineer.md
new file mode 100644
index 00000000..8201a876
--- /dev/null
+++ b/skills/ontology-engineer.md
@@ -0,0 +1,90 @@
+---
+name: ontology-engineer
+description: Use when building, modifying, or validating ontologies. Orchestrates the onto_* MCP tools in a generate-validate-iterate loop. Triggers on "ontology", "OWL", "RDF", "Turtle", "SPARQL", "BORO", "4D modeling", or /ontology-engineer.
+---
+
+# Ontology Engineer
+
+AI-native ontology engineering using OpenCheir's `onto_*` MCP tools.
+
+## When to Use
+
+- User asks to build, extend, or modify an ontology
+- User asks to validate, lint, or query an existing ontology
+- User mentions OWL, RDF, Turtle, SPARQL, BORO, 4D modeling, IES4
+- User wants to compare ontologies or run competency questions
+
+## Prerequisites
+
+The `onto_*` tools must be available via the OpenCheir MCP server. If they're not available, tell the user to install OpenCheir.
+
+## Workflow
+
+Claude dynamically decides which tool to call next based on results. This is NOT a fixed pipeline — adapt based on what each tool returns.
+
+### Phase 1: Understand
+
+- What domain? (Pizza, buildings, healthcare, etc.)
+- What methodology? (standard OWL, BORO/4D, SKOS, etc.)
+- What are the competency questions? (what should the ontology be able to answer?)
+- Is there a reference ontology to compare against?
+
+### Phase 2: Generate
+
+- Generate Turtle/OWL directly from domain knowledge
+- Claude knows OWL, RDF, BORO, 4D modeling, every methodology natively
+- For complex methodologies, ask the user for background documents or constraints
+
+### Phase 3: Validate (loop until clean)
+
+```
+onto_validate → syntax errors? → fix Turtle, re-validate
+onto_load → loaded ok? → proceed to verification
+onto_stats → counts match? → if not, regenerate missing parts
+onto_lint → issues found? → fix labels/domains/ranges, re-load
+```
+
+### Phase 4: Verify (loop until correct)
+
+```
+onto_query → run SPARQL to check:
+ - all expected classes present?
+ - subclass hierarchies correct?
+ - competency questions answerable?
+onto_diff → if reference exists, compare and report gaps
+```
+
+### Phase 5: Persist
+
+```
+onto_version → save snapshot before finalizing
+onto_save → write to .ttl file
+```
+
+## Key Rules
+
+1. **Always validate before loading** — `onto_validate` catches syntax errors that would silently fail
+2. **Always check stats after loading** — `onto_stats` catches missing classes/properties
+3. **Always lint after loading** — `onto_lint` catches missing labels and domains
+4. **Version before pushing** — `onto_version` before `onto_push` (enforcer rule)
+5. **Iterate, don't declare done** — if any check fails, fix and re-run from Phase 3
+
+## Tool Quick Reference
+
+| Tool | Purpose |
+| ---- | ------- |
+| `onto_validate` | Check OWL/RDF syntax (file or inline Turtle) |
+| `onto_load` | Load into Oxigraph triple store |
+| `onto_stats` | Class/property/triple counts |
+| `onto_lint` | Missing labels, comments, domains |
+| `onto_query` | Run SPARQL queries |
+| `onto_diff` | Compare two ontologies |
+| `onto_save` | Persist to file |
+| `onto_convert` | Format conversion |
+| `onto_clear` | Reset the store |
+| `onto_pull` | Fetch from URL or SPARQL endpoint |
+| `onto_push` | Push to SPARQL endpoint |
+| `onto_import` | Resolve owl:imports |
+| `onto_version` | Save named snapshot |
+| `onto_history` | List snapshots |
+| `onto_rollback` | Restore previous version |