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.

One sheet in, one ontology out, with the evidence for every line (#233)

Fabio Rovai8b058dbd20d0
diff --git a/docs/interop-with-graph-platforms.md b/docs/interop-with-graph-platforms.md
index a86780ee..fc82e931 100644
--- a/docs/interop-with-graph-platforms.md
+++ b/docs/interop-with-graph-platforms.md
@@ -15,7 +15,7 @@ entities and relationships, and assemble a graph. They are pipelines, written
in Python, with orchestration, storage, and retrieval included.
Open Ontologies **verifies and governs**: it is a single Rust binary with no
-model client inside it, exposing 112 MCP tools over a formal store. Its job
+model client inside it, exposing 113 MCP tools over a formal store. Its job
starts where extraction ends.
```
diff --git a/docs/tool-reference.md b/docs/tool-reference.md
index 358bb4bb..459996c4 100644
--- a/docs/tool-reference.md
+++ b/docs/tool-reference.md
@@ -11,7 +11,7 @@ who meets a catalogue first cannot tell what it is for. Everything below keeps
its code and its own documentation; it loses its place above the fold.
-120 tools.
+121 tools.
| Tool | What it does |
| --- | --- |
@@ -68,6 +68,7 @@ its code and its own documentation; it loses its place above the fold.
| `onto_hnsw_build` | Build (or rebuild) the HNSW cosine index over the loaded text embeddings with explicit `ef_construction` and `ef_search` parameters. |
| `onto_import` | Resolve and load all owl:imports from the currently loaded ontology |
| `onto_import_schema` | Import a relational database schema as an OWL ontology. |
+| `onto_induce` | ONE SHEET IN, ONE ONTOLOGY OUT: induce an OWL class, typed properties, a SHACL shape and a loading mapping from one data sheet, with the evidence for every line. |
| `onto_ingest` | Parse a structured data file (CSV, JSON, NDJSON, XML, YAML, XLSX, Parquet) into RDF triples and load into the ontology store. |
| `onto_invariant_check` | Evaluate every registered BC+ invariant against the current graph and return the names + descriptions of any that fail. |
| `onto_invariant_list` | List all registered BC+ static causal laws (invariants). |
diff --git a/python/README.md b/python/README.md
index c8518209..5401a2d0 100644
--- a/python/README.md
+++ b/python/README.md
@@ -226,7 +226,7 @@ report["conforms"] # None, because nothing was examined
## Relationship to the Rust engine
-This is the **Python layer** of the project. For the full engine (three-layer Dynamics/Causal/Planner architecture, HNSW semantic search, SHIQ tableaux reasoning, PDDL planning, governance, 120 tools), use the [Rust build](https://github.com/fabio-rovai/open-ontologies). HNSW semantic search there is a compile-time feature, so build with `--features embeddings`; the published binaries do not carry it. Same Oxigraph core; pick the weight class you need.
+This is the **Python layer** of the project. For the full engine (three-layer Dynamics/Causal/Planner architecture, HNSW semantic search, SHIQ tableaux reasoning, PDDL planning, governance, 121 tools), use the [Rust build](https://github.com/fabio-rovai/open-ontologies). HNSW semantic search there is a compile-time feature, so build with `--features embeddings`; the published binaries do not carry it. Same Oxigraph core; pick the weight class you need.
## License
diff --git a/skills/ontology-engineer.md b/skills/ontology-engineer.md
index 3e607b80..bdef7f26 100644
--- a/skills/ontology-engineer.md
+++ b/skills/ontology-engineer.md
@@ -5,7 +5,7 @@ description: Use when building, modifying, or validating ontologies. Orchestrate
# Ontology Engineer
-AI-native ontology engineering using the Open Ontologies `onto_*` MCP tools (120 tools, 8 of which require an optional Cargo feature).
+AI-native ontology engineering using the Open Ontologies `onto_*` MCP tools (121 tools, 8 of which require an optional Cargo feature).
## When to Use
diff --git a/skills/ontology-engineering/SKILL.md b/skills/ontology-engineering/SKILL.md
index 5be7465e..591d4857 100644
--- a/skills/ontology-engineering/SKILL.md
+++ b/skills/ontology-engineering/SKILL.md
@@ -5,7 +5,7 @@ description: Build, validate, and govern RDF/OWL ontologies using the Open Ontol
# Ontology Engineering Workflow
-You have access to the Open Ontologies MCP server, which provides 120 tools for AI-native ontology engineering backed by an in-memory Oxigraph triple store. 112 of them are advertised in a default build, and the other 8 require an optional Cargo feature and return an error without it: four need `embeddings`, two need `plugins`, and two need `postgres` or `duckdb`.
+You have access to the Open Ontologies MCP server, which provides 121 tools for AI-native ontology engineering backed by an in-memory Oxigraph triple store. 113 of them are advertised in a default build, and the other 8 require an optional Cargo feature and return an error without it: four need `embeddings`, two need `plugins`, and two need `postgres` or `duckdb`.
## Core Workflow
diff --git a/src/batch.rs b/src/batch.rs
index 89f11f7e..04665df5 100644
--- a/src/batch.rs
+++ b/src/batch.rs
@@ -150,6 +150,7 @@ impl BatchRunner {
"pull" => self.exec_pull(&cmd.args).await,
"push" => self.exec_push(&cmd.args).await,
"ingest" => self.exec_ingest(&cmd.args),
+ "induce" => self.exec_induce(&cmd.args),
"drift" => self.exec_drift(&cmd.args),
"lock" => self.exec_lock(&cmd.args),
"monitor" => self.exec_monitor(),
@@ -824,6 +825,59 @@ impl BatchRunner {
}
}
+ /// `induce FILE [--base-iri B] [--class NAME] [--out DIR] [--no-load]`:
+ /// one sheet in, one ontology out. Writes `ontology.ttl`, `shapes.ttl`,
+ /// `mapping.json` and `induced.json` under `--out` when given, loads the
+ /// ontology, the shapes and the rows into the store unless `--no-load`,
+ /// and returns the report with the Turtle inline.
+ fn exec_induce(&self, args: &[String]) -> Value {
+ use crate::ingest::DataIngester;
+ let path = match args.first().filter(|a| !a.starts_with("--")) {
+ Some(p) => p.clone(),
+ None => return json!({"error": "induce requires a data file path"}),
+ };
+ let base = Self::flag_value(args, "--base-iri").unwrap_or("http://example.org/data/".to_string());
+ let stem = Self::flag_value(args, "--class").unwrap_or_else(|| {
+ std::path::Path::new(&path).file_stem().and_then(|s| s.to_str()).unwrap_or("Row").to_string()
+ });
+ let rows = match DataIngester::parse_file(&path) {
+ Ok(r) => r,
+ Err(e) => return json!({"error": e.to_string()}),
+ };
+ if rows.is_empty() {
+ return json!({"error": "no data rows found; nothing to induce from"});
+ }
+ let headers = DataIngester::headers_in_order(&path, &rows);
+ let induced = crate::induce::induce(&rows, &headers, &stem, &base);
+ if let Some(out) = Self::flag_value(args, "--out") {
+ let dir = std::path::Path::new(&out);
+ if let Err(e) = std::fs::create_dir_all(dir)
+ .and_then(|_| std::fs::write(dir.join("ontology.ttl"), &induced.ontology_ttl))
+ .and_then(|_| std::fs::write(dir.join("shapes.ttl"), &induced.shapes_ttl))
+ .and_then(|_| std::fs::write(dir.join("mapping.json"), serde_json::to_string_pretty(&induced.mapping).unwrap_or_default()))
+ .and_then(|_| std::fs::write(dir.join("induced.json"), serde_json::to_string_pretty(&induced).unwrap_or_default()))
+ {
+ return json!({"error": format!("cannot write {out}: {e}")});
+ }
+ }
+ let mut v = serde_json::to_value(&induced).unwrap_or_else(|e| json!({"error": e.to_string()}));
+ if !args.iter().any(|a| a == "--no-load") {
+ let loaded = self
+ .graph
+ .load_turtle(&induced.ontology_ttl, None)
+ .and_then(|a| self.graph.load_turtle(&induced.shapes_ttl, None).map(|b| a + b))
+ .and_then(|ab| self.graph.load_ntriples(&induced.mapping.rows_to_ntriples(&rows)).map(|c| (ab, c)));
+ match loaded {
+ Ok((schema, data)) => {
+ v["loaded"] = json!({"schema_triples": schema, "instance_triples": data});
+ }
+ Err(e) => return json!({"error": format!("induced, but loading failed: {e}")}),
+ }
+ }
+ v["ok"] = json!(true);
+ v
+ }
+
fn exec_drift(&self, args: &[String]) -> Value {
if args.len() < 2 {
return json!({"error": "drift requires two file paths"});
diff --git a/src/induce.rs b/src/induce.rs
new file mode 100644
index 00000000..302ac9b2
--- /dev/null
+++ b/src/induce.rs
@@ -0,0 +1,728 @@
+//! One sheet in, one ontology out, with the evidence for every line of it.
+//!
+//! A spreadsheet is a claim about a domain made by someone who did not write
+//! it down: the columns are the properties, the rows are the individuals, the
+//! header is the only schema. This module reads that claim back as an OWL
+//! class with typed properties, a SHACL shape that the rows themselves
+//! satisfy, and a mapping that loads the rows as instances, and it says next
+//! to every induced statement WHICH rows made it say so.
+//!
+//! What it induces is a HYPOTHESIS about the sheet, not a truth about the
+//! domain. `sh:maxCount 1` on a column means no row had two values, which is
+//! exactly what a one-cell column guarantees and nothing more; `sh:in` on a
+//! column means twelve or fewer distinct values were seen, not that a
+//! thirteenth is wrong. The output says so, once at the top and once per
+//! statement, so a reader can strike the lines the domain does not support.
+//!
+//! Three choices are deliberate and stated here rather than discovered later:
+//!
+//! 1. **Cardinality is a shape, not an axiom.** A one-value column could be
+//! rendered `owl:FunctionalProperty`. It is not, because under OWL RL a
+//! functional property with two values does not reject the second row, it
+//! IDENTIFIES the two objects (`prp-fp`). A shape rejects the next row; an
+//! axiom rewrites the world. The next row is what a sheet's author meant.
+//! 2. **Observed ranges are evidence, not constraints.** The minimum and
+//! maximum of a numeric column are reported in the shape's description and
+//! never as `sh:minInclusive`, because a price of 0 in a sheet whose
+//! lowest price was 4 is not a violation of anything the author said.
+//! 3. **Repeated columns are one property.** `topping1 .. topping7` is one
+//! multi-valued `topping` with `sh:maxCount 7`, which is what the author
+//! meant by numbering them. The group is reported, so a false merge
+//! (`address1`/`address2` as two lines of one address) is visible.
+
+use std::collections::{BTreeMap, BTreeSet, HashMap};
+
+use serde::Serialize;
+
+use crate::mapping::{FieldMapping, MappingConfig};
+
+const XSD: &str = "http://www.w3.org/2001/XMLSchema#";
+
+/// The datatypes this module can tell apart, in the order they are tried.
+/// Every filled value of a column must parse for the column to earn the type;
+/// one value that does not demotes the column to the next candidate.
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub enum Dt {
+ Boolean,
+ Integer,
+ Decimal,
+ Double,
+ Date,
+ DateTime,
+ AnyUri,
+ String,
+}
+
+impl Dt {
+ pub fn iri(self) -> String {
+ let local = match self {
+ Dt::Boolean => "boolean",
+ Dt::Integer => "integer",
+ Dt::Decimal => "decimal",
+ Dt::Double => "double",
+ Dt::Date => "date",
+ Dt::DateTime => "dateTime",
+ Dt::AnyUri => "anyURI",
+ Dt::String => "string",
+ };
+ format!("{XSD}{local}")
+ }
+
+ /// The [`Dt`] an XSD datatype IRI names, for the ones this module knows.
+ pub fn from_iri(iri: &str) -> Option<Dt> {
+ Some(match iri.strip_prefix(XSD)? {
+ "boolean" => Dt::Boolean,
+ "integer" => Dt::Integer,
+ "decimal" => Dt::Decimal,
+ "double" | "float" => Dt::Double,
+ "date" => Dt::Date,
+ "dateTime" => Dt::DateTime,
+ "anyURI" => Dt::AnyUri,
+ "string" => Dt::String,
+ _ => return None,
+ })
+ }
+
+ /// Whether `v` is in this datatype's lexical space, as far as this
+ /// module's parser goes.
+ pub fn accepts(self, v: &str) -> bool {
+ let v = v.trim();
+ match self {
+ Dt::Boolean => matches!(v, "true" | "false" | "TRUE" | "FALSE" | "True" | "False"),
+ Dt::Integer => {
+ let d = v.strip_prefix(['+', '-']).unwrap_or(v);
+ !d.is_empty() && d.chars().all(|c| c.is_ascii_digit())
+ }
+ Dt::Decimal => {
+ let d = v.strip_prefix(['+', '-']).unwrap_or(v);
+ let mut dots = 0;
+ let mut digits = 0;
+ for c in d.chars() {
+ match c {
+ '.' => dots += 1,
+ c if c.is_ascii_digit() => digits += 1,
+ _ => return false,
+ }
+ }
+ digits > 0 && dots <= 1
+ }
+ Dt::Double => {
+ // A decimal, or a decimal with an exponent (`3e+05`), which a
+ // sheet exported from a spreadsheet application will contain
+ // for any large round number. INF and NaN as XSD writes them.
+ if matches!(v, "INF" | "-INF" | "NaN") {
+ return true;
+ }
+ let (mant, exp) = match v.split_once(['e', 'E']) {
+ Some((m, e)) => (m, Some(e)),
+ None => (v, None),
+ };
+ Dt::Decimal.accepts(mant)
+ && exp.is_none_or(|e| {
+ let d = e.strip_prefix(['+', '-']).unwrap_or(e);
+ !d.is_empty() && d.chars().all(|c| c.is_ascii_digit())
+ })
+ }
+ Dt::Date => {
+ let b = v.as_bytes();
+ b.len() == 10
+ && b[4] == b'-'
+ && b[7] == b'-'
+ && b.iter().enumerate().all(|(i, c)| i == 4 || i == 7 || c.is_ascii_digit())
+ }
+ Dt::DateTime => {
+ let (d, t) = match v.split_once('T') {
+ Some(x) => x,
+ None => return false,
+ };
+ let t = t.trim_end_matches('Z');
+ let t = t.split(['+']).next().unwrap_or(t);
+ let t = if t.len() > 8 && &t[8..9] == "-" { &t[..8] } else { t };
+ Dt::Date.accepts(d)
+ && t.len() >= 8
+ && &t[2..3] == ":"
+ && &t[5..6] == ":"
+ && t[..8].chars().enumerate().all(|(i, c)| i == 2 || i == 5 || c.is_ascii_digit())
+ }
+ Dt::AnyUri => (v.starts_with("http://") || v.starts_with("https://")) && !v.contains(' '),
+ Dt::String => true,
+ }
+ }
+
+ /// The narrowest type every value of `values` parses as.
+ fn infer<'a>(values: impl Iterator<Item = &'a str> + Clone) -> Dt {
+ for dt in [Dt::Boolean, Dt::Integer, Dt::Decimal, Dt::Double, Dt::Date, Dt::DateTime, Dt::AnyUri] {
+ if values.clone().all(|v| dt.accepts(v)) {
+ return dt;
+ }
+ }
+ Dt::String
+ }
+}
+
+/// What was measured about one induced property, and what was decided.
+#[derive(Debug, Clone, Serialize)]
+pub struct Column {
+ /// The property's local name.
+ pub property: String,
+ /// The sheet columns behind it: one, or a numbered group.
+ pub columns: Vec<String>,
+ pub rows: usize,
+ /// Rows with at least one value in these columns.
+ pub filled: usize,
+ /// Distinct values across the group.
+ pub distinct: usize,
+ /// The most values one row had across the group.
+ pub max_per_row: usize,
+ pub datatype: Dt,
+ /// `Some(class)`: the values are identifiers of rows of this sheet, so the
+ /// property is an object property ranging over the induced class.
+ pub refers_to: Option<String>,
+ /// Observed enumeration, when the column is a small closed set of strings.
+ pub values: Option<Vec<String>>,
+ /// Numeric or length bounds actually seen. Evidence, never a constraint.
+ pub observed: BTreeMap<&'static str, String>,
+ /// One sentence a reader can check against the rows.
+ pub evidence: String,
+}
+
+#[derive(Debug, Clone, Serialize)]
+pub struct Induced {
+ pub class: String,
+ pub class_iri: String,
+ pub base_iri: String,
+ pub id_column: String,
+ /// `true` when no column identified the rows and a row number was used.
+ pub id_synthesised: bool,
+ pub rows: usize,
+ pub columns: Vec<Column>,
+ /// The OWL ontology, Turtle.
+ pub ontology_ttl: String,
+ /// The SHACL shapes graph, Turtle. The rows satisfy it by construction.
+ pub shapes_ttl: String,
+ /// The mapping that loads the rows as instances of the class.
+ pub mapping: MappingConfig,
+ /// What this output is and is not.
+ pub means: &'static str,
+}
+
+const MEANS: &str = "an induced ontology is a HYPOTHESIS about the sheet, not a truth about the \
+ domain. Every class, property, datatype and shape here was read off the rows \
+ and carries the counts that produced it; the rows satisfy the shapes by \
+ construction, so a clean validation of this sheet against them says nothing. \
+ Cardinality is a shape and not an owl:FunctionalProperty on purpose (an axiom \
+ identifies, a shape rejects), observed numeric ranges are reported and never \
+ constrained, and a numbered column group is one multi-valued property. Strike \
+ what the domain does not support; the evidence column says what each line rests on";
+
+fn local_name(raw: &str) -> String {
+ let mut out = String::new();
+ let mut upper_next = false;
+ for c in raw.trim().chars() {
+ if c.is_ascii_alphanumeric() || c == '_' {
+ if upper_next && out.is_empty() {
+ out.push(c);
+ } else if upper_next {
+ out.extend(c.to_uppercase());
+ } else {
+ out.push(c);
+ }
+ upper_next = false;
+ } else {
+ upper_next = !out.is_empty();
+ }
+ }
+ if out.is_empty() {
+ "column".to_string()
+ } else if out.chars().next().is_some_and(|c| c.is_ascii_digit()) {
+ format!("c{out}")
+ } else {
+ out
+ }
+}
+
+fn class_name(stem: &str) -> String {
+ let mut s = String::new();
+ let mut up = true;
+ for c in stem.chars() {
+ if c.is_ascii_alphanumeric() {
+ if up {
+ s.extend(c.to_uppercase());
+ } else {
+ s.push(c);
+ }
+ up = false;
+ } else {
+ up = true;
+ }
+ }
+ if s.is_empty() {
+ "Row".to_string()
+ } else if s.chars().next().is_some_and(|c| c.is_ascii_digit()) {
+ format!("Sheet{s}")
+ } else {
+ s
+ }
+}
+
+/// `topping3` -> `("topping", 3)`, `address 2` -> `("address", 2)`; `abc` -> None.
+fn numbered(h: &str) -> Option<(String, u32)> {
+ let t = h.trim().trim_end_matches(|c: char| c.is_ascii_digit());
+ let digits = &h.trim()[t.len()..];
+ if digits.is_empty() || t.is_empty() {
+ return None;
+ }
+ let stem = t.trim_end_matches([' ', '_', '-', '#']);
+ if stem.is_empty() {
+ return None;
+ }
+ Some((stem.to_string(), digits.parse().ok()?))
+}
+
+fn ttl_str(s: &str) -> String {
+ let mut o = String::with_capacity(s.len() + 2);
+ o.push('"');
+ for c in s.chars() {
+ match c {
+ '\\' => o.push_str("\\\\"),
+ '"' => o.push_str("\\\""),
+ '\n' => o.push_str("\\n"),
+ '\r' => o.push_str("\\r"),
+ '\t' => o.push_str("\\t"),
+ c => o.push(c),
+ }
+ }
+ o.push('"');
+ o
+}
+
+/// Induce class, properties, shapes and mapping from `rows`.
+///
+/// `headers` fixes the column order (a `HashMap` row has none); `stem` names
+/// the class (a file stem, usually); `base_iri` roots every minted IRI.
+pub fn induce(rows: &[HashMap<String, String>], headers: &[String], stem: &str, base_iri: &str) -> Induced {
+ let n = rows.len();
+ let class = class_name(stem);
+ let ont = format!("{base_iri}ont#");
+ let class_iri = format!("{ont}{class}");
+
+ // 1. The identifier: the first column if it is filled and unique in every
+ // row, else any column named like an identifier that is, else a row
+ // number, and the report says which.
+ let filled_unique = |h: &String| -> bool {
+ let mut seen = BTreeSet::new();
+ rows.iter().all(|r| match r.get(h).map(|v| v.trim()) {
+ Some(v) if !v.is_empty() => seen.insert(v.to_string()),
+ _ => false,
+ })
+ };
+ let id_like = |h: &str| {
+ let l = h.to_ascii_lowercase();
+ l == "id" || l.ends_with("_id") || l.ends_with("id") || l.contains("key") || l.contains("code")
+ };
+ let (id_column, id_synthesised) = match headers.first() {
+ Some(h) if n > 0 && filled_unique(h) => (h.clone(), false),
+ _ => match headers.iter().find(|h| id_like(h) && filled_unique(h)) {
+ Some(h) => (h.clone(), false),
+ None => ("__row".to_string(), true),
+ },
+ };
+ let id_values: BTreeSet<String> = if id_synthesised {
+ BTreeSet::new()
+ } else {
+ rows.iter().filter_map(|r| r.get(&id_column)).map(|v| v.trim().to_string()).collect()
+ };
+
+ // 2. Group numbered columns. A stem with two or more members is one
+ // property; a lone `address1` stays a column called address1.
+ let mut groups: BTreeMap<String, Vec<(u32, String)>> = BTreeMap::new();
+ for h in headers {
+ if let Some((stem, k)) = numbered(h) {
+ groups.entry(stem).or_default().push((k, h.clone()));
+ }
+ }
+ let mut member_of: HashMap<String, String> = HashMap::new();
+ for (stem, members) in &groups {
+ if members.len() >= 2 {
+ for (_, h) in members {
+ member_of.insert(h.clone(), stem.clone());
+ }
+ }
+ }
+ let mut units: Vec<(String, Vec<String>)> = Vec::new();
+ let mut seen_group: BTreeSet<String> = BTreeSet::new();
+ for h in headers {
+ if h == &id_column && !id_synthesised {
+ continue;
+ }
+ match member_of.get(h) {
+ Some(stem) => {
+ if seen_group.insert(stem.clone()) {
+ let mut ms = groups[stem].clone();
+ ms.sort();
+ units.push((stem.clone(), ms.into_iter().map(|(_, h)| h).collect()));
+ }
+ }
+ None => units.push((h.clone(), vec![h.clone()])),
+ }
+ }
+
+ // 3. Profile each unit.
+ let mut columns = Vec::new();
+ let mut taken: BTreeSet<String> = BTreeSet::new();
+ for (raw_name, cols) in &units {
+ let mut property = local_name(raw_name);
+ while !taken.insert(property.clone()) {
+ property.push('_');
+ }
+ let per_row: Vec<Vec<&str>> = rows
+ .iter()
+ .map(|r| {
+ cols.iter()
+ .filter_map(|c| r.get(c).map(|v| v.trim()))
+ .filter(|v| !v.is_empty())
+ .collect()
+ })
+ .collect();
+ let filled = per_row.iter().filter(|v| !v.is_empty()).count();
+ let max_per_row = per_row.iter().map(|v| v.len()).max().unwrap_or(0);
+ let all: Vec<&str> = per_row.iter().flatten().copied().collect();
+ let distinct: BTreeSet<&str> = all.iter().copied().collect();
+ let datatype = if all.is_empty() { Dt::String } else { Dt::infer(all.iter().copied()) };
+
+ // A column whose every value is an identifier of some row of this
+ // sheet refers to the sheet's own class, the only referent a single
+ // sheet can offer. Containment alone is not enough: a `quantity`
+ // column holding 1..5 is contained in ids 1..100 and refers to
+ // nothing, which the first version of this got wrong on a two-row
+ // sheet. So the values must be non-numeric, or the column must be
+ // named like a reference (`manager_id`, `parent`, `ref`, `key`).
+ let named_like_ref = {
+ let l = raw_name.to_ascii_lowercase();
+ l.ends_with("_id") || l.ends_with("id") && l != "id" || l.contains("ref") || l.contains("parent")
+ || l.contains("manager") || l.ends_with("key")
+ };
+ let refers_to = (!id_synthesised
+ && !all.is_empty()
+ && !matches!(datatype, Dt::Boolean | Dt::Date | Dt::DateTime)
+ && (named_like_ref || !matches!(datatype, Dt::Integer | Dt::Decimal | Dt::Double))
+ && all.iter().all(|v| id_values.contains(*v))
+ && cols.iter().all(|c| c != &id_column))
+ .then(|| class.clone());
+
+ // A closed set needs more than a short column: at least two values
+ // (one value is a constant, not an enumeration), at most twelve, and
+ // each seen five times over on average. Thirty rows of a four-letter
+ // code qualify; thirty rows of names do not.
+ let values = (refers_to.is_none()
+ && datatype == Dt::String
+ && distinct.len() >= 2
+ && distinct.len() <= 12
+ && all.len() >= 5 * distinct.len())
+ .then(|| distinct.iter().map(|v| v.to_string()).collect::<Vec<_>>());
+
+ let mut observed = BTreeMap::new();
+ match datatype {
+ Dt::Integer | Dt::Decimal | Dt::Double => {
+ let nums: Vec<f64> = all.iter().filter_map(|v| v.parse::<f64>().ok()).collect();
+ if let (Some(lo), Some(hi)) = (
+ nums.iter().cloned().reduce(f64::min),
+ nums.iter().cloned().reduce(f64::max),
+ ) {
+ observed.insert("min", format!("{lo}"));
+ observed.insert("max", format!("{hi}"));
+ }
+ }
+ Dt::String | Dt::AnyUri => {
+ if let Some(m) = all.iter().map(|v| v.chars().count()).max() {
+ observed.insert("max_length", m.to_string());
+ }
+ }
+ _ => {}
+ }
+
+ let evidence = format!(
+ "{filled} of {n} rows filled, {} distinct value(s), at most {max_per_row} per row across {} column(s); every value parses as xsd:{}{}{}",
+ distinct.len(),
+ cols.len(),
+ datatype.iri().rsplit('#').next().unwrap_or(""),
+ match &refers_to {
+ Some(c) => format!("; every value is the {id_column} of a row{}, so it refers to a {c}", if named_like_ref { " and the column is named like a reference" } else { "" }),
+ None => String::new(),
+ },
+ match &values {
+ Some(v) => format!("; {} distinct values over {} occurrences, a closed set as far as this sheet goes", v.len(), all.len()),
+ None => String::new(),
+ },
+ );
+ columns.push(Column {
+ property,
+ columns: cols.clone(),
+ rows: n,
+ filled,
+ distinct: distinct.len(),
+ max_per_row,
+ datatype,
+ refers_to,
+ values,
+ observed,
+ evidence,
+ });
+ }
+
+ // 4. Render.
+ let ctx = Ctx { ont: &ont, class: &class, class_iri: &class_iri, stem, n, id_synthesised, id_column: &id_column };
+ let ontology_ttl = render_ontology(&ctx, &columns);
+ let shapes_ttl = render_shapes(&ctx, &columns);
+ let mut mappings = Vec::new();
+ for c in &columns {
+ for col in &c.columns {
+ mappings.push(FieldMapping {
+ field: col.clone(),
+ predicate: format!("{ont}{}", c.property),
+ datatype: c.refers_to.is_none().then(|| c.datatype.iri()),
+ class: c.refers_to.as_ref().map(|_| class_iri.clone()),
+ lookup: c.refers_to.is_some(),
+ });
+ }
+ }
+ let mapping = MappingConfig {
+ base_iri: base_iri.to_string(),
+ id_field: id_column.clone(),
+ class: class_iri.clone(),
+ mappings,
+ };
+
+ Induced {
+ class,
+ class_iri,
+ base_iri: base_iri.to_string(),
+ id_column,
+ id_synthesised,
+ rows: n,
+ columns,
+ ontology_ttl,
+ shapes_ttl,
+ mapping,
+ means: MEANS,
+ }
+}
+
+/// What both renderers need to know about the sheet as a whole.
+struct Ctx<'a> {
+ ont: &'a str,
+ class: &'a str,
+ class_iri: &'a str,
+ stem: &'a str,
+ n: usize,
+ id_synthesised: bool,
+ id_column: &'a str,
+}
+
+fn render_ontology(ctx: &Ctx<'_>, columns: &[Column]) -> String {
+ let Ctx { ont, class, class_iri, stem, n, id_synthesised, id_column } = *ctx;
+ let mut t = String::new();
+ t.push_str(&format!("@prefix : <{ont}> .\n"));
+ t.push_str("@prefix owl: <http://www.w3.org/2002/07/owl#> .\n");
+ t.push_str("@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .\n");
+ t.push_str("@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n");
+ t.push_str("@prefix dcterms: <http://purl.org/dc/terms/> .\n\n");
+ t.push_str(&format!(
+ "<{}> a owl:Ontology ;\n rdfs:comment {} .\n\n",
+ ont.trim_end_matches('#'),
+ ttl_str(&format!(
+ "Induced from the sheet {stem:?}: {n} rows, {} properties. {}",
+ columns.len(),
+ MEANS
+ ))
+ ));
+ t.push_str(&format!(
+ ":{class} a owl:Class ;\n rdfs:label {} ;\n rdfs:comment {} .\n\n",
+ ttl_str(class),
+ ttl_str(&format!(
+ "One instance per row of {stem:?}, {n} in the sheet. Identified by {}.",
+ if id_synthesised {
+ "row number, because no column was filled and unique in every row".to_string()
+ } else {
+ format!("the column {id_column:?}, filled and unique in every row")
+ }
+ ))
+ ));
+ let _ = class_iri;
+ for c in columns {
+ let (kind, range) = match &c.refers_to {
+ Some(cls) => ("owl:ObjectProperty", format!(":{cls}")),
+ None => ("owl:DatatypeProperty", format!("xsd:{}", c.datatype.iri().rsplit('#').next().unwrap_or("string"))),
+ };
+ t.push_str(&format!(
+ ":{p} a {kind} ;\n rdfs:label {} ;\n rdfs:domain :{class} ;\n rdfs:range {range} ;\n rdfs:comment {} .\n\n",
+ ttl_str(&c.columns.join(", ")),
+ ttl_str(&c.evidence),
+ p = c.property,
+ ));
+ }
+ t
+}
+
+fn render_shapes(ctx: &Ctx<'_>, columns: &[Column]) -> String {
+ let Ctx { ont, class, class_iri, n, .. } = *ctx;
+ let mut t = String::new();
+ t.push_str(&format!("@prefix : <{ont}> .\n"));
+ t.push_str("@prefix sh: <http://www.w3.org/ns/shacl#> .\n");
+ t.push_str("@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .\n\n");
+ t.push_str(&format!(
+ ":{class}Shape a sh:NodeShape ;\n sh:targetClass <{class_iri}> ;\n sh:description {} ;\n",
+ ttl_str(&format!(
+ "Induced from {n} rows. The rows satisfy this shape by construction; it constrains the NEXT row. {MEANS}"
+ ))
+ ));
+ let mut props = Vec::new();
+ for c in columns {
+ let mut p = format!(" sh:property [\n sh:path :{} ;\n", c.property);
+ match &c.refers_to {
+ Some(_) => p.push_str(&format!(" sh:class <{class_iri}> ;\n sh:nodeKind sh:IRI ;\n")),
+ None => p.push_str(&format!(
+ " sh:datatype xsd:{} ;\n",
+ c.datatype.iri().rsplit('#').next().unwrap_or("string")
+ )),
+ }
+ p.push_str(&format!(" sh:maxCount {} ;\n", c.max_per_row.max(1)));
+ let mut why = vec![format!(
+ "maxCount {} because no row had more values across {} column(s)",
+ c.max_per_row.max(1),
+ c.columns.len()
+ )];
+ if c.filled == n && n > 0 {
+ p.push_str(" sh:minCount 1 ;\n");
+ why.push(format!("minCount 1 because every one of {n} rows was filled"));
+ } else {
+ why.push(format!("no minCount because {} of {n} rows were empty", n - c.filled));
+ }
+ if let Some(vals) = &c.values {
+ let list: Vec<String> = vals.iter().map(|v| ttl_str(v)).collect();
+ p.push_str(&format!(" sh:in ( {} ) ;\n", list.join(" ")));
+ why.push(format!(
+ "in: {} distinct values over {} filled rows; a value outside this set is new, not wrong",
+ vals.len(),
+ c.filled
+ ));
+ }
+ for (k, v) in &c.observed {
+ why.push(format!("observed {k} {v}, reported and not constrained"));
+ }
+ p.push_str(&format!(" sh:description {} ;\n ]", ttl_str(&why.join("; "))));
+ props.push(p);
+ }
+ t.push_str(&props.join(" ;\n"));
+ t.push_str(" .\n");
+ t
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn rows(csv: &str) -> (Vec<HashMap<String, String>>, Vec<String>) {
+ let mut lines = csv.trim().lines();
+ let headers: Vec<String> = lines.next().unwrap().split(',').map(|s| s.to_string()).collect();
+ let rows = lines
+ .map(|l| {
+ headers
+ .iter()
+ .cloned()
+ .zip(l.split(',').map(|s| s.to_string()))
+ .collect::<HashMap<_, _>>()
+ })
+ .collect();
+ (rows, headers)
+ }
+
+ #[test]
+ fn datatypes_are_the_narrowest_every_value_parses_as() {
+ assert_eq!(Dt::infer(["1", "2", "-3"].into_iter()), Dt::Integer);
+ assert_eq!(Dt::infer(["1", "2.5"].into_iter()), Dt::Decimal);
+ assert_eq!(Dt::infer(["1", "3e+05"].into_iter()), Dt::Double);
+ assert_eq!(Dt::infer(["1", "x"].into_iter()), Dt::String);
+ assert_eq!(Dt::infer(["2014-07-11"].into_iter()), Dt::Date);
+ assert_eq!(Dt::infer(["2014-07-11T10:00:00Z"].into_iter()), Dt::DateTime);
+ assert_eq!(Dt::infer(["true", "false"].into_iter()), Dt::Boolean);
+ assert_eq!(Dt::infer(["https://a.b/c"].into_iter()), Dt::AnyUri);
+ }
+
+ #[test]
+ fn numbered_columns_become_one_property() {
+ let (r, h) = rows("name,topping1,topping2,topping3\nA,x,y,\nB,x,,\nC,z,y,w\n");
+ let i = induce(&r, &h, "pizza-menu", "http://ex.org/");
+ assert_eq!(i.class, "PizzaMenu");
+ assert_eq!(i.id_column, "name");
+ assert!(!i.id_synthesised);
+ assert_eq!(i.columns.len(), 1, "{:?}", i.columns);
+ let t = &i.columns[0];
+ assert_eq!(t.property, "topping");
+ assert_eq!(t.columns, vec!["topping1", "topping2", "topping3"]);
+ assert_eq!(t.max_per_row, 3);
+ assert_eq!(t.filled, 3);
+ assert!(i.shapes_ttl.contains("sh:maxCount 3"), "{}", i.shapes_ttl);
+ assert!(i.shapes_ttl.contains("sh:minCount 1"));
+ assert!(i.ontology_ttl.contains(":topping a owl:DatatypeProperty"));
+ assert!(!i.ontology_ttl.contains("a owl:FunctionalProperty"), "cardinality is a shape, not an axiom");
+ }
+
+ #[test]
+ fn a_self_reference_is_an_object_property_and_a_small_set_is_an_enumeration() {
+ let (r, h) = rows(
+ "emp_id,name,manager_id,grade,salary\n1,Ann,,A,100\n2,Bob,1,B,80\n3,Cy,1,B,80.5\n4,Di,2,A,90\n5,Ed,2,B,70\n6,Fi,3,A,60\n7,Gus,3,A,55\n8,Hal,4,B,50\n9,Ida,4,A,45\n10,Jo,5,B,40\n",
+ );
+ let i = induce(&r, &h, "staff", "http://ex.org/");
+ let by = |p: &str| i.columns.iter().find(|c| c.property == p).unwrap_or_else(|| panic!("{p}: {:?}", i.columns));
+ assert_eq!(by("manager_id").refers_to.as_deref(), Some("Staff"));
+ assert!(i.ontology_ttl.contains(":manager_id a owl:ObjectProperty"));
+ assert!(i.shapes_ttl.contains("sh:class <http://ex.org/ont#Staff>"));
+ assert_eq!(by("grade").values.as_ref().map(|v| v.len()), Some(2));
+ assert!(i.shapes_ttl.contains("sh:in ( \"A\" \"B\" )"));
+ assert_eq!(by("salary").datatype, Dt::Decimal);
+ assert_eq!(by("salary").observed.get("min").map(String::as_str), Some("40"));
+ assert!(!i.shapes_ttl.contains("sh:minInclusive"), "observed ranges are evidence, not constraints");
+ assert!(by("manager_id").filled < 10 && !i.shapes_ttl.contains("sh:path :manager_id ;\n sh:class <http://ex.org/ont#Staff> ;\n sh:nodeKind sh:IRI ;\n sh:maxCount 1 ;\n sh:minCount 1"));
+ // name is not an enumeration: ten distinct over ten values.
+ assert!(by("name").values.is_none());
+ }
+
+ /// The false positive the first version had: small integers contained in
+ /// the id range are a quantity, not a reference.
+ #[test]
+ fn an_integer_column_inside_the_id_range_is_not_a_reference() {
+ let (r, h) = rows("id,label,n\n1,one,1\n2,two,2\n3,three,1\n");
+ let i = induce(&r, &h, "nums", "http://ex.org/");
+ let n = i.columns.iter().find(|c| c.property == "n").unwrap();
+ assert!(n.refers_to.is_none(), "{:?}", n);
+ assert_eq!(n.datatype, Dt::Integer);
+ // ...but the same values under a reference-like name are one.
+ let (r, h) = rows("id,label,parent_id\n1,one,1\n2,two,2\n3,three,1\n");
+ let i = induce(&r, &h, "nums", "http://ex.org/");
+ assert_eq!(i.columns.iter().find(|c| c.property == "parent_id").unwrap().refers_to.as_deref(), Some("Nums"));
+ }
+
+ #[test]
+ fn no_identifier_means_a_row_number_and_says_so() {
+ let (r, h) = rows("colour,size\nred,1\nred,2\n");
+ let i = induce(&r, &h, "swatches", "http://ex.org/");
+ assert!(i.id_synthesised);
+ assert_eq!(i.id_column, "__row");
+ assert!(i.ontology_ttl.contains("row number, because no column was filled and unique"));
+ assert_eq!(i.columns.len(), 2);
+ }
+
+ #[test]
+ fn the_turtle_parses_and_the_mapping_loads_rows_as_instances() {
+ let (r, h) = rows("id,label,n\n1,one,1\n2,two,2\n");
+ let i = induce(&r, &h, "nums", "http://ex.org/");
+ let g = crate::graph::GraphStore::new();
+ g.load_turtle(&i.ontology_ttl, None).expect("ontology turtle parses");
+ g.load_turtle(&i.shapes_ttl, None).expect("shapes turtle parses");
+ let nt = i.mapping.rows_to_ntriples(&r);
+ assert!(nt.contains("<http://ex.org/1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://ex.org/ont#Nums>"), "{nt}");
+ assert!(nt.contains("\"1\"^^<http://www.w3.org/2001/XMLSchema#integer>"), "{nt}");
+ }
+}
diff --git a/src/ingest.rs b/src/ingest.rs
index dcd2f432..2f6ed7ad 100644
--- a/src/ingest.rs
+++ b/src/ingest.rs
@@ -418,6 +418,34 @@ impl DataIngester {
}
/// Collect unique keys from all rows, sorted alphabetically.
+ /// Column names in the order the FILE gives them, when the format has an
+ /// order (CSV: the header row), else sorted. `extract_headers` sorts,
+ /// which loses which column came first, and the first column is the
+ /// identifier candidate for induction.
+ pub fn headers_in_order(path: &str, rows: &[HashMap<String, String>]) -> Vec<String> {
+ let ordered: Option<Vec<String>> = match Self::detect_format(path) {
+ "csv" => std::fs::read_to_string(path).ok().and_then(|c| {
+ let mut r = csv::ReaderBuilder::new().has_headers(true).from_reader(c.as_bytes());
+ r.headers().ok().map(|h| h.iter().map(|x| x.to_string()).collect())
+ }),
+ _ => None,
+ };
+ match ordered {
+ Some(h) if !h.is_empty() => {
+ // The file's order for the columns it names, then any key a
+ // row carries that the header did not.
+ let mut out = h;
+ for k in Self::extract_headers(rows) {
+ if !out.contains(&k) {
+ out.push(k);
+ }
+ }
+ out
+ }
+ _ => Self::extract_headers(rows),
+ }
+ }
+
pub fn extract_headers(rows: &[HashMap<String, String>]) -> Vec<String> {
let mut keys: Vec<String> = rows
.iter()
diff --git a/src/inputs.rs b/src/inputs.rs
index 453cb14a..b81d814f 100644
--- a/src/inputs.rs
+++ b/src/inputs.rs
@@ -1596,3 +1596,17 @@ pub struct OntoTemporalQueryInput {
/// retired by then (temporal:recordedUntil closes the interval)
pub as_of: Option<String>,
}
+
+#[derive(Deserialize, JsonSchema)]
+pub struct OntoInduceInput {
+ /// Path to one data sheet (CSV, JSON, NDJSON, XML, YAML, XLSX, Parquet)
+ pub path: String,
+ /// Base IRI for everything minted (default: http://example.org/data/). The
+ /// class and properties live under `{base_iri}ont#`, the instances under `{base_iri}`.
+ pub base_iri: Option<String>,
+ /// Class name (default: derived from the file stem, `pizza-menu.csv` -> `PizzaMenu`)
+ pub class_name: Option<String>,
+ /// Load the induced ontology, its shapes and the rows into the store (default: true).
+ /// With false the result is returned and nothing in the store changes.
+ pub load: Option<bool>,
+}
diff --git a/src/lib.rs b/src/lib.rs
index 5e392938..b46419d0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -62,6 +62,7 @@ pub mod feedback;
pub mod graph;
#[cfg(feature = "embeddings")]
pub mod hnsw_index;
+pub mod induce;
pub mod ingest;
pub mod inputs;
pub mod kgcl;
diff --git a/src/mapping.rs b/src/mapping.rs
index 0b3e023d..6c04d760 100644
--- a/src/mapping.rs
+++ b/src/mapping.rs
@@ -87,8 +87,18 @@ impl MappingConfig {
// Lookup field: produce an IRI object
format!("<{}{}>", self.base_iri, sanitize_iri(value))
} else if let Some(ref dt) = mapping.datatype {
- // Typed literal
- format!("\"{}\"^^<{}>", escape_ntriples(value), dt)
+ // Typed literal, when the cell is in the datatype's lexical
+ // space. A cell that is not is minted as a plain string rather
+ // than an ill-typed literal: `"cheap"^^xsd:integer` answers
+ // xsd:integer to DATATYPE() and slips past every sh:datatype
+ // check, `"cheap"` is caught by the first one. Datatypes this
+ // crate cannot parse keep the declared type.
+ let ok = crate::induce::Dt::from_iri(dt).is_none_or(|d| d.accepts(value));
+ if ok {
+ format!("\"{}\"^^<{}>", escape_ntriples(value), dt)
+ } else {
+ format!("\"{}\"", escape_ntriples(value))
+ }
} else {
// Plain literal
format!("\"{}\"", escape_ntriples(value))
diff --git a/src/server.rs b/src/server.rs
index 6fc220cf..a62e3871 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -1042,6 +1042,44 @@ impl OpenOntologiesServer {
}
}
+ #[tool(name = "onto_induce", description = "ONE SHEET IN, ONE ONTOLOGY OUT, WITH THE EVIDENCE FOR EVERY LINE. Reads one data sheet (CSV, JSON, NDJSON, XML, YAML, XLSX, Parquet) and induces an OWL class with typed properties, a SHACL shape the rows satisfy by construction, and a mapping that loads the rows as instances; then loads all three unless load=false. WHAT IS DECIDED, AND FROM WHAT: the identifier is the first column if it is filled and unique in every row, else an id-like column that is, else a row number (and the report says which); each property's xsd datatype is the narrowest every value parses as (boolean, integer, decimal, date, dateTime, anyURI, string); a column whose every value is an identifier of a row becomes an object property ranging over the class; numbered columns (topping1..topping7) become ONE multi-valued property with sh:maxCount = the group size; a string column with two to twelve distinct values, each seen five times over on average, becomes an sh:in enumeration. Every induced statement carries a sentence of evidence (rows filled, distinct values, values per row, the parse) in rdfs:comment or sh:description. THREE DELIBERATE CHOICES, STATED: cardinality is a SHAPE and never owl:FunctionalProperty (under OWL RL a functional property with two values identifies the objects, prp-fp, instead of rejecting the row); observed numeric ranges are reported and never made sh:minInclusive/sh:maxInclusive; a numbered group is reported so a false merge is visible. WHAT THIS IS: a HYPOTHESIS about the sheet, not a truth about the domain, and the `means` field says so; a clean validation of this sheet against its own induced shapes says nothing, the shapes constrain the NEXT row. Returns class, columns with their profiles and evidence, ontology_ttl, shapes_ttl, mapping, and what was loaded.")]
+ async fn onto_induce(&self, Parameters(input): Parameters<OntoInduceInput>) -> String {
+ use crate::ingest::DataIngester;
+ let base_iri = input.base_iri.clone().unwrap_or_else(|| "http://example.org/data/".to_string());
+ let stem = input.class_name.clone().unwrap_or_else(|| {
+ std::path::Path::new(&input.path).file_stem().and_then(|s| s.to_str()).unwrap_or("Row").to_string()
+ });
+ let rows = match DataIngester::parse_file(&input.path) {
+ Ok(r) => r,
+ Err(e) => return Self::err_json(format!("Failed to parse {}: {}", input.path, e)),
+ };
+ if rows.is_empty() {
+ return Self::err_json("no data rows found; nothing to induce from");
+ }
+ let headers = DataIngester::headers_in_order(&input.path, &rows);
+ let induced = crate::induce::induce(&rows, &headers, &stem, &base_iri);
+ let mut v = match serde_json::to_value(&induced) {
+ Ok(v) => v,
+ Err(e) => return Self::err_json(e),
+ };
+ if input.load.unwrap_or(true) {
+ let loaded = self
+ .graph
+ .load_turtle(&induced.ontology_ttl, None)
+ .and_then(|a| self.graph.load_turtle(&induced.shapes_ttl, None).map(|b| a + b))
+ .and_then(|ab| self.graph.load_ntriples(&induced.mapping.rows_to_ntriples(&rows)).map(|c| (ab, c)));
+ match loaded {
+ Ok((schema, data)) => {
+ v["loaded"] = serde_json::json!({"schema_triples": schema, "instance_triples": data});
+ self.lineage().record(&self.session_id, "IN", "induce", &format!("{} rows -> {}", rows.len(), induced.class));
+ }
+ Err(e) => return Self::err_json(format!("induced, but loading failed: {e}")),
+ }
+ }
+ v["ok"] = serde_json::json!(true);
+ v.to_string()
+ }
+
#[tool(name = "onto_temporal_snapshot", description = "Which named graphs are in scope at a point in time, and which are excluded and why. Two independent clocks: valid_at asks what was TRUE then, as_of asks what was KNOWN then. Assertions live in named graphs described in the default graph with temporal:validFrom, validTo, recordedAt and recordedUntil; a graph with no description is timeless and always in scope. Both intervals are half-open, so an assertion whose recordedUntil has passed is excluded as no longer believed instead of being carried forward beside the correction that replaced it. Bounds on all four axes are read as instants on the UTC timeline from xsd:date, xsd:dateTime, xsd:gYearMonth or xsd:gYear; a less precise bound names the FIRST instant of its period, and a value with no timezone offset is UTC. A bound matching none of those, or two different instants on one axis, makes the graph INVALID: reported in `invalid` with a reason, never in scope and never timeless. A graph whose validFrom and validTo both read but together hold at no instant (the same instant twice, or validTo before validFrom) is not invalid: it is excluded at every instant asked about, with a reason naming which of the two it is; with no valid_at it is in scope like any other graph. The scans are capped: `complete` says whether they finished, and a run that was cut short also carries `truncated` and a `warning`, because a truncated validity scan makes this partition wrong rather than merely short. Lineage is asserted, never inferred: temporal:supersedes on the NEWER graph names the graph it replaces, and where the replaced graph carries no recordedUntil its closing bound is derived from the successor's recordedAt (the earliest, where there are several), so an excluded row closed that way carries `superseded_by`; an explicit recordedUntil always governs and a disagreement with the successor is reported, not reconciled. temporal:retracts names a graph withdrawn without replacement: from the retraction's recordedAt the retracted graph leaves in_scope and is listed under `retracted` with the retracting graph and instant; with no as_of the recorded axis is not consulted, for a retraction no more than for a recordedUntil, and the graph takes the ordinary path. `lineage`, present only when non-empty, reports what the links could not settle: a disagreement, a transaction interval that closes before it opens (a successor recorded before its predecessor, reported as inverted and believed at no instant, never clamped), an undated successor or retractor, more than one successor, a cycle, or a link that names nothing readable or is asserted by a graph whose own description could not be read.")]
async fn onto_temporal_snapshot(&self, Parameters(input): Parameters<OntoTemporalSnapshotInput>) -> String {
use crate::temporal::Temporal;
diff --git a/src/toolfilter.rs b/src/toolfilter.rs
index f83bfff8..6b3221e9 100644
--- a/src/toolfilter.rs
+++ b/src/toolfilter.rs
@@ -225,6 +225,7 @@ pub fn expand_group(name: &str) -> &'static [&'static str] {
"onto_version",
"onto_rollback",
"onto_ingest",
+ "onto_induce",
"onto_sql_ingest",
"onto_map",
"onto_shacl",
diff --git a/tests/induce_one_sheet_test.rs b/tests/induce_one_sheet_test.rs
new file mode 100644
index 00000000..30314b7c
--- /dev/null
+++ b/tests/induce_one_sheet_test.rs
@@ -0,0 +1,129 @@
+//! One sheet in, one ontology out, and the shapes it induces can FAIL.
+//!
+//! The rows satisfy their own induced shapes by construction, which is why a
+//! clean run over them proves nothing. This file therefore checks the other
+//! direction as well: change one cell so it breaks what the sheet implied and
+//! the induced shape must report it. A gate that cannot fail is not a gate.
+
+use std::collections::HashMap;
+use std::path::PathBuf;
+use std::sync::Arc;
+
+use open_ontologies::graph::GraphStore;
+use open_ontologies::induce::{induce, Dt};
+use open_ontologies::ingest::DataIngester;
+use open_ontologies::shacl::ShaclValidator;
+
+fn repo() -> PathBuf {
+ PathBuf::from(env!("CARGO_MANIFEST_DIR"))
+}
+
+fn sheet(rel: &str) -> (String, Vec<HashMap<String, String>>, Vec<String>) {
+ let path = repo().join(rel).to_string_lossy().to_string();
+ let rows = DataIngester::parse_file(&path).expect("fixture parses");
+ let headers = DataIngester::headers_in_order(&path, &rows);
+ (path, rows, headers)
+}
+
+#[test]
+fn the_pizza_menu_becomes_one_class_with_one_multivalued_topping() {
+ let (_, rows, headers) = sheet("benchmark/data/pizza-menu.csv");
+ assert_eq!(headers[0], "name", "the file's first column, not the alphabetical one");
+ let i = induce(&rows, &headers, "pizza-menu", "http://example.org/menu/");
+ assert_eq!(i.class, "PizzaMenu");
+ assert_eq!(i.id_column, "name");
+ assert!(!i.id_synthesised);
+ assert_eq!(i.columns.len(), 1, "seven topping columns are one property: {:?}", i.columns.iter().map(|c| &c.property).collect::<Vec<_>>());
+ let t = &i.columns[0];
+ assert_eq!(t.property, "topping");
+ assert_eq!(t.columns.len(), 7);
+ assert_eq!(t.datatype, Dt::String);
+ assert!(t.max_per_row >= 2 && t.max_per_row <= 7, "{}", t.max_per_row);
+ assert!(i.shapes_ttl.contains(&format!("sh:maxCount {}", t.max_per_row)));
+ assert!(t.evidence.contains("rows filled"), "{}", t.evidence);
+}
+
+#[test]
+fn the_epc_sample_gets_typed_columns_from_its_values() {
+ let (_, rows, headers) = sheet("benchmark/epc/epc-sample.csv");
+ let i = induce(&rows, &headers, "epc-sample", "http://example.org/epc/");
+ let by = |p: &str| i.columns.iter().find(|c| c.property == p).unwrap_or_else(|| panic!("no column {p}"));
+ assert_eq!(by("price").datatype, Dt::Double, "the fixture writes one price as 3e+05");
+ assert_eq!(by("dateoftransfer").datatype, Dt::Date);
+ assert_eq!(by("year").datatype, Dt::Integer);
+ assert!(by("price").observed.contains_key("min"), "observed range is reported");
+ assert!(!i.shapes_ttl.contains("sh:minInclusive"), "and never constrained");
+ assert!(by("propertytype").values.is_some(), "a handful of letters over 30 rows is an enumeration");
+ assert!(!i.ontology_ttl.contains("a owl:FunctionalProperty"));
+ assert!(i.means.starts_with("an induced ontology is a HYPOTHESIS"));
+}
+
+/// The gate can fail: the sheet's own rows conform, a mutated row does not.
+#[test]
+fn the_induced_shape_accepts_the_sheet_and_rejects_a_broken_row() {
+ let (_, mut rows, headers) = sheet("benchmark/epc/epc-sample.csv");
+ let i = induce(&rows, &headers, "epc-sample", "http://example.org/epc/");
+
+ let store = Arc::new(GraphStore::new());
+ store.load_turtle(&i.ontology_ttl, None).expect("ontology parses");
+ store.load_ntriples(&i.mapping.rows_to_ntriples(&rows)).expect("rows load");
+ let clean: serde_json::Value =
+ serde_json::from_str(&ShaclValidator::validate(&store, &i.shapes_ttl).unwrap()).unwrap();
+ assert_eq!(clean["conforms"], true, "the rows satisfy their own shape by construction: {clean}");
+ assert_eq!(clean["violation_count"], 0);
+
+ // Break one cell in a way the sheet never showed: a price that is not an integer.
+ rows[0].insert("price".into(), "cheap".into());
+ let broken = Arc::new(GraphStore::new());
+ broken.load_turtle(&i.ontology_ttl, None).unwrap();
+ broken.load_ntriples(&i.mapping.rows_to_ntriples(&rows)).unwrap();
+ let r: serde_json::Value =
+ serde_json::from_str(&ShaclValidator::validate(&broken, &i.shapes_ttl).unwrap()).unwrap();
+ assert_eq!(r["conforms"], false, "a non-integer price must be reported: {r}");
+ assert!(
+ r["violations"].as_array().unwrap().iter().any(|v| {
+ v["source_constraint_component"] == "http://www.w3.org/ns/shacl#DatatypeConstraintComponent"
+ && v["result_path"].as_str().map(|p| p.ends_with("#price")).unwrap_or(false)
+ }),
+ "{r}"
+ );
+}
+
+/// Batch, through the built binary: `induce FILE --out DIR` writes the four
+/// files, loads the store, and `stats` afterwards sees the triples.
+#[test]
+fn batch_induce_writes_the_files_and_loads() {
+ let tmp = tempfile::TempDir::new().unwrap();
+ let out = tmp.path().join("induced");
+ let script = tmp.path().join("script.txt");
+ std::fs::write(
+ &script,
+ format!(
+ "induce {} --out {}\nstats\n",
+ repo().join("benchmark/data/pizza-menu.csv").display(),
+ out.display()
+ ),
+ )
+ .unwrap();
+ let run = std::process::Command::new(env!("CARGO_BIN_EXE_open-ontologies"))
+ .arg("--data-dir")
+ .arg(tmp.path())
+ .arg("batch")
+ .arg(&script)
+ .output()
+ .expect("the binary runs");
+ let stdout = String::from_utf8_lossy(&run.stdout);
+ let lines: Vec<serde_json::Value> = stdout
+ .lines()
+ .filter(|l| l.starts_with('{'))
+ .map(|l| serde_json::from_str(l).unwrap_or_else(|e| panic!("{e}: {l}")))
+ .collect();
+ assert!(lines.len() >= 2, "stdout: {stdout}\nstderr: {}", String::from_utf8_lossy(&run.stderr));
+ let first = &lines[0]["result"];
+ assert_eq!(first["ok"], true, "{first}");
+ assert_eq!(first["class"], "PizzaMenu");
+ assert!(first["loaded"]["instance_triples"].as_u64().unwrap() > 0, "{first}");
+ for f in ["ontology.ttl", "shapes.ttl", "mapping.json", "induced.json"] {
+ assert!(out.join(f).exists(), "{f} not written");
+ }
+}
diff --git a/tests/readme_claims_test.rs b/tests/readme_claims_test.rs
index 8f2028aa..fdedc4b8 100644
--- a/tests/readme_claims_test.rs
+++ b/tests/readme_claims_test.rs
@@ -44,7 +44,7 @@ fn total_claims(n: usize) -> Vec<(&'static str, &'static str, String)> {
//
// The reasoning is the issue's: surface area reads as insecurity, and a
// number where a purpose belongs tells a visitor nothing about what this is
- // for. A reader who meets "120 tools" before meeting a verb cannot tell
+ // for. A reader who meets "121 tools" before meeting a verb cannot tell
// whether any of them is the one they need. The front page shows one loop
// instead, and the breadth moved to docs/tool-reference.md, linked once.
//
diff --git a/tests/tool_reference_test.rs b/tests/tool_reference_test.rs
index 9321513c..7fc65632 100644
--- a/tests/tool_reference_test.rs
+++ b/tests/tool_reference_test.rs
@@ -90,7 +90,7 @@ fn the_front_page_sells_the_loop_and_not_the_surface_area() {
let readme = read("README.md");
let fold = &readme[..readme.len().min(9000)];
- for banned in ["120 tools", "112 tools", "Terraforming MCP"] {
+ for banned in ["121 tools", "113 tools", "Terraforming MCP"] {
assert!(
!readme.contains(banned),
"the README still says {banned:?}. Surface area reads as insecurity, and a \
@@ -146,7 +146,7 @@ fn the_retired_words_do_not_come_back() {
{
let lower = t.to_lowercase();
let is_catalogue = p.ends_with("tool-reference.md");
- for w in ["120 tools", "112 tools", "terraforming mcp", "trustworthy"] {
+ for w in ["121 tools", "113 tools", "terraforming mcp", "trustworthy"] {
let counts_only = w.ends_with(" tools");
if is_catalogue && counts_only {
continue;
diff --git a/web/try/api/_samples/epc-sample.csv b/web/try/api/_samples/epc-sample.csv
new file mode 100644
index 00000000..5d55afd6
--- /dev/null
+++ b/web/try/api/_samples/epc-sample.csv
@@ -0,0 +1,31 @@
+"id","transactionid","oa11","postcode","price","dateoftransfer","propertytype","oldnew","duration","paon","saon","street","locality","towncity","district","county","categorytype","recordstatus","year","lsoa11","msoa11","laua","lad11nm","gor","rgn11nm","classt","propertytype_epc","inspectiondate","lodgementdate","tfarea","numberrooms","priceper","BUILDING_REFERENCE_NUMBER","CURRENT_ENERGY_RATING","POTENTIAL_ENERGY_RATING","CURRENT_ENERGY_EFFICIENCY","POTENTIAL_ENERGY_EFFICIENCY","BUILT_FORM","LOCAL_AUTHORITY","CONSTITUENCY","COUNTY","TRANSACTION_TYPE","ENVIRONMENT_IMPACT_CURRENT","ENVIRONMENT_IMPACT_POTENTIAL","ENERGY_CONSUMPTION_CURRENT","ENERGY_CONSUMPTION_POTENTIAL","CO2_EMISSIONS_CURRENT","CO2_EMISS_CURR_PER_FLOOR_AREA","CO2_EMISSIONS_POTENTIAL","LIGHTING_COST_CURRENT","LIGHTING_COST_POTENTIAL","HEATING_COST_CURRENT","HEATING_COST_POTENTIAL","HOT_WATER_COST_CURRENT","HOT_WATER_COST_POTENTIAL","ENERGY_TARIFF","MAINS_GAS_FLAG","FLOOR_LEVEL","FLAT_TOP_STOREY","FLAT_STOREY_COUNT","MAIN_HEATING_CONTROLS","MULTI_GLAZE_PROPORTION","GLAZED_TYPE","GLAZED_AREA","EXTENSION_COUNT","NUMBER_HEATED_ROOMS","LOW_ENERGY_LIGHTING","NUMBER_OPEN_FIREPLACES","HOTWATER_DESCRIPTION","HOT_WATER_ENERGY_EFF","HOT_WATER_ENV_EFF","FLOOR_DESCRIPTION","FLOOR_ENERGY_EFF","FLOOR_ENV_EFF","WINDOWS_DESCRIPTION","WINDOWS_ENERGY_EFF","WINDOWS_ENV_EFF","WALLS_DESCRIPTION","WALLS_ENERGY_EFF","WALLS_ENV_EFF","SECONDHEAT_DESCRIPTION","SHEATING_ENERGY_EFF","SHEATING_ENV_EFF","ROOF_DESCRIPTION","ROOF_ENERGY_EFF","ROOF_ENV_EFF","MAINHEAT_DESCRIPTION","MAINHEAT_ENERGY_EFF","MAINHEAT_ENV_EFF","MAINHEATCONT_DESCRIPTION","MAINHEATC_ENERGY_EFF","MAINHEATC_ENV_EFF","LIGHTING_DESCRIPTION","LIGHTING_ENERGY_EFF","LIGHTING_ENV_EFF","MAIN_FUEL","WIND_TURBINE_COUNT","HEAT_LOSS_CORRIDOOR","UNHEATED_CORRIDOR_LENGTH","FLOOR_HEIGHT","PHOTO_SUPPLY","SOLAR_WATER_HEATING_FLAG","MECHANICAL_VENTILATION","LOCAL_AUTHORITY_LABEL","CONSTITUENCY_LABEL"
+10000000,"{5F2B8B60-B9D0-4F00-8561-8BBF0C991BE1}","E00155821","KT22 7LN",187250,"2014-07-11","F","N","L","BURLEIGH COURT","FLAT 10","BELMONT ROAD","","LEATHERHEAD","MOLE VALLEY","SURREY","A","A",2014,"E01030550","E02006364","E07000210","Mole Valley","E12000008","South East",12,"Flat","2019-05-08","2019-05-08",46,2,4070.65217391304,4085051668,"C","C",78,78,"Semi-Detached","E07000210","E14000824","Surrey","rental (private)",81,81,147,147,1.2,26,1.2,39,39,179,179,118,118,"Unknown","Y","1st","N",NA,"2106",100,"double glazing installed during or after 2002","Normal",0,2,100,0,"From main system","Good","Good","(another dwelling below)","NO DATA!","N/A","Fully double glazed","Good","Good","Cavity wall, as built, insulated (assumed)","Good","Good","None","N/A","N/A","(another dwelling above)","N/A","N/A","Boiler and radiators, mains gas","Good","Good","Programmer, room thermostat and TRVs","Good","Good","Low energy lighting in all fixed outlets","Very Good","Very Good","mains gas (not community)",0,"unheated corridor",7.26,NA,NA,"N","natural","Mole Valley","Mole Valley"
+10000002,"{5F54B81D-B8BA-2B45-E053-6B04A8C01FB0}","E00155858","RH4 3QR",394000,"2017-10-23","T","N","F","61","","BAILEY ROAD","WESTCOTT","DORKING","MOLE VALLEY","SURREY","A","A",2017,"E01030558","E02006373","E07000210","Mole Valley","E12000008","South East",11,"House","2017-03-10","2017-03-11",77,5,5116.88311688312,5218350578,"D","B",60,81,"Mid-Terrace","E07000210","E14000824","Surrey","marketed sale",55,78,274,118,3.9,50,1.7,105,52,675,523,109,72,"Unknown","Y","NODATA!","",NA,"2106",100,"double glazing, unknown install date","Normal",1,5,0,1,"From main system","Good","Good","Suspended, no insulation (assumed)","NO DATA!","N/A","Fully double glazed","Average","Average","Cavity wall, as built, no insulation (assumed)","Poor","Poor","Room heaters, dual fuel (mineral and wood)","N/A","N/A","Pitched, 50 mm loft insulation","Poor","Poor","Boiler and radiators, mains gas","Good","Good","Programmer, room thermostat and TRVs","Good","Good","No low energy lighting","Very Poor","Very Poor","mains gas (not community)",0,"NO DATA!",NA,NA,NA,"N","natural","Mole Valley","Mole Valley"
+10000004,"{F5CB911D-B4EF-4F74-A696-1131D46A1019}","E00155626","KT21 2LJ",447000,"2013-10-24","S","N","F","58","","WEST FARM CLOSE","","ASHTEAD","MOLE VALLEY","SURREY","A","A",2013,"E01030511","E02006363","E07000210","Mole Valley","E12000008","South East",11,"Bungalow","2013-03-22","2013-03-24",139,5,3215.8273381295,9770914468,"C","B",73,83,"Semi-Detached","E07000210","E14000694","Surrey","marketed sale",70,80,137,83,3.9,28,2.5,97,66,626,569,94,94,"Single","Y","NODATA!","",NA,"2106",100,"double glazing installed before 2002","Normal",0,4,53,0,"From main system","Good","Good","Solid, no insulation (assumed)","N/A","N/A","Fully double glazed","Average","Average","Cavity wall, filled cavity","Good","Good","Room heaters, smokeless fuel","N/A","N/A","Pitched, 150 mm loft insulation","Good","Good","Boiler and radiators, mains gas","Good","Good","Programmer, room thermostat and TRVs","Good","Good","Low energy lighting in 53% of fixed outlets","Good","Good","mains gas (not community)",0,"NO DATA!",NA,NA,0,"","natural","Mole Valley","Epsom and Ewell"
+10000006,"{47844C80-5285-8986-E050-A8C063056488}","E00170378","KT22 7TQ",700700,"2017-01-23","D","N","F","12","","RANDALLS ROAD","","LEATHERHEAD","MOLE VALLEY","SURREY","A","A",2017,"E01030548","E02006364","E07000210","Mole Valley","E12000008","South East",11,"House","2016-07-02","2016-07-03",148,7,4734.45945945946,4521875478,"D","B",62,83,"Detached","E07000210","E14000824","Surrey","marketed sale",54,79,239,101,6.3,42,2.7,91,91,1130,670,148,90,"Single","Y","NODATA!","",NA,"2106",100,"double glazing installed during or after 2002","Normal",4,7,86,0,"From main system","Good","Good","Solid, no insulation (assumed)","NO DATA!","N/A","Fully double glazed","Good","Good","Cavity wall, as built, no insulation (assumed)","Poor","Poor","None","N/A","N/A","Pitched, 25 mm loft insulation","Poor","Poor","Boiler and radiators, mains gas","Good","Good","Programmer, room thermostat and TRVs","Good","Good","Low energy lighting in 86% of fixed outlets","Very Good","Very Good","mains gas (not community)",0,"NO DATA!",NA,2.56,NA,"N","natural","Mole Valley","Mole Valley"
+10000007,"{666758D7-4CCD-3363-E053-6B04A8C0D74E}","E00155596","KT21 2DJ",350000,"2018-01-03","F","N","L","WOODLODGE","5","WOODFIELD LANE","","ASHTEAD","MOLE VALLEY","SURREY","A","A",2018,"E01030507","E02006363","E07000210","Mole Valley","E12000008","South East",11,"Flat","2017-08-07","2017-08-07",63,4,5555.55555555556,651133578,"D","C",68,77,"Mid-Terrace","E07000210","E14000694","Surrey","marketed sale",67,78,228,151,2.5,40,1.7,73,45,442,295,101,101,"Single","Y","Ground","N",NA,"2104",100,"double glazing, unknown install date","Normal",0,4,40,0,"From main system","Very Good","Good","Solid, no insulation (assumed)","NO DATA!","N/A","Fully double glazed","Average","Average","Cavity wall, as built, no insulation (assumed)","Poor","Poor","None","N/A","N/A","(another dwelling above)","N/A","N/A","Boiler and radiators, mains gas","Good","Good","Programmer and room thermostat","Average","Average","Low energy lighting in 40% of fixed outlets","Average","Average","mains gas (not community)",0,"unheated corridor",7.2,NA,NA,"N","natural","Mole Valley","Epsom and Ewell"
+10000008,"{288DCE29-B9CB-E510-E050-A8C06205480E}","E00155821","KT22 7DX",135000,"2015-10-20","F","N","L","HOLLY COURT","FLAT 24","BELMONT ROAD","","LEATHERHEAD","MOLE VALLEY","SURREY","A","A",2015,"E01030550","E02006364","E07000210","Mole Valley","E12000008","South East",12,"Flat","2014-11-24","2014-11-24",44,2,3068.18181818182,1909030378,"B","B",82,83,"Mid-Terrace","E07000210","E14000824","Surrey","marketed sale",73,75,220,203,1.7,39,1.6,44,44,97,105,151,123,"dual","N","1st","N",NA,"2401",100,"double glazing, unknown install date","Normal",0,2,70,0,"Electric immersion, off-peak","Average","Very Poor","(other premises below)","N/A","N/A","Fully double glazed","Average","Average","Cavity wall, as built, insulated (assumed)","Good","Good","Portable electric heaters (assumed)","N/A","N/A","(another dwelling above)","N/A","N/A","Electric storage heaters","Average","Very Poor","Manual charge control","Poor","Poor","Low energy lighting in 70% of fixed outlets","Very Good","Very Good","electricity (not community)",0,"heated corridor",NA,NA,0,"","natural","Mole Valley","Mole Valley"
+1000001,"{8F8399C6-D908-4D5B-B125-0EA5CDAEE88C}","E00169542","LE3 9QA",82250,"2013-10-16","F","N","L","4D","","STRATHERN ROAD","","LEICESTER","LEICESTER","LEICESTER","A","A",2013,"E01013617","E02002830","E06000016","Leicester","E12000004","East Midlands",11,"Flat","2013-02-28","2013-02-28",62,3,1326.61290322581,7603065078,"C","C",74,78,"Semi-Detached","E06000016","E14000784",NA,"marketed sale",59,63,292,265,3.2,52,2.9,81,43,276,245,118,113,"dual","N","1st","N",NA,"2401",100,"double glazing installed before 2002","Normal",0,3,13,0,"Electric immersion, off-peak","Average","Very Poor","(other premises below)","N/A","N/A","Fully double glazed","Average","Average","Cavity wall, as built, insulated (assumed)","Good","Good","Room heaters, electric","N/A","N/A","(another dwelling above)","N/A","N/A","Electric storage heaters","Average","Very Poor","Manual charge control","Poor","Poor","Low energy lighting in 13% of fixed outlets","Poor","Poor","electricity (not community)",0,"unheated corridor",3.98,NA,0,"","natural","Leicester","Leicester West"
+10000012,"{6194948C-738A-4A2E-976D-7E0CECF3FDE8}","E00155769","KT22 9TB",640000,"2015-09-11","D","N","F","45","","THE GLADE","FETCHAM","LEATHERHEAD","MOLE VALLEY","SURREY","A","A",2015,"E01030541","E02006366","E07000210","Mole Valley","E12000008","South East",12,"Bungalow","2015-05-14","2015-05-15",115,5,5565.21739130435,310606378,"E","C",39,76,"Detached","E07000210","E14000824","Surrey","marketed sale",34,72,411,144,8.3,72,2.9,99,66,1497,803,239,78,"Single","Y","NODATA!","",NA,"2106",100,"double glazing installed before 2002","Normal",1,5,50,0,"From main system","Average","Average","Solid, no insulation (assumed)","NO DATA!","N/A","Fully double glazed","Average","Average","Cavity wall, as built, no insulation (assumed)","Poor","Poor","Room heaters, electric","N/A","N/A","Pitched, 100 mm loft insulation","Average","Average","Boiler and radiators, mains gas","Average","Average","Programmer, room thermostat and TRVs","Good","Good","Low energy lighting in 50% of fixed outlets","Good","Good","mains gas (not community)",0,"NO DATA!",NA,NA,NA,"N","natural","Mole Valley","Mole Valley"
+10000014,"{DF7FF768-C49A-46D2-AC47-EF0F96799040}","E00155731","RH4 1HH",138000,"2014-06-19","F","N","L","36","","CANTERBURY COURT","","DORKING","MOLE VALLEY","SURREY","A","A",2014,"E01030534","E02006370","E07000210","Mole Valley","E12000008","South East",11,"Flat","2011-04-20","2011-04-20",50.57,3,2728.89064662844,3234806868,"B","B",84,85,"Enclosed End-Terrace","E07000210","E14000824","Surrey","marketed sale",78,79,174,169,1.6,31,1.5,50,33,74,77,112,112,"Unknown","N","1st","N",NA,"2401",100,"double glazing installed before 2002","Normal",0,3,50,0,"Electric immersion, off-peak","Average","Very Poor","(other premises below)","N/A","N/A","Fully double glazed","Average","Average","Cavity wall, as built, insulated (assumed)","Good","Good","Room heaters, electric","N/A","N/A","(another dwelling above)","N/A","N/A","Electric storage heaters","Average","Very Poor","Manual charge control","Poor","Poor","Low energy lighting in 50% of fixed outlets","Good","Good","electricity (not community)",0,"heated corridor",NA,2.38,0,"","natural","Mole Valley","Mole Valley"
+10000015,"{87E1551E-9378-6405-E053-6C04A8C0B2EE}","E00155700","RH3 7EA",522500,"2019-04-23","D","N","F","BUCKLAND COURT COTTAGE","","REIGATE ROAD","BUCKLAND","BETCHWORTH","MOLE VALLEY","SURREY","A","A",2019,"E01030527","E02006369","E07000210","Mole Valley","E12000008","South East",11,"Bungalow","2018-02-15","2018-02-15",83,4,6295.18072289157,391638478,"E","B",44,84,"Detached","E07000210","E14000824","Surrey","marketed sale",37,81,437,108,6.4,77,1.6,86,58,1038,472,195,71,"Single","Y","NODATA!","",NA,"2104",30,"double glazing installed during or after 2002","Normal",1,4,50,0,"From main system","Average","Average","Suspended, no insulation (assumed)","NO DATA!","N/A","Some double glazing","Poor","Poor","Solid brick, as built, no insulation (assumed)","Very Poor","Very Poor","Room heaters, mains gas","N/A","N/A","Pitched, 300 mm loft insulation","Very Good","Very Good","Boiler and radiators, mains gas","Good","Good","Programmer and room thermostat","Average","Average","Low energy lighting in 50% of fixed outlets","Good","Good","mains gas (not community)",0,"NO DATA!",NA,NA,NA,"N","natural","Mole Valley","Mole Valley"
+10000016,"{766E340F-536A-4AAD-80FB-7C7DBACAC754}","E00170381","KT22 7UT",250000,"2012-03-20","F","N","L","TURNER COURT","FLAT 2","HIGHBURY DRIVE","","LEATHERHEAD","MOLE VALLEY","SURREY","A","A",2012,"E01030549","E02006364","E07000210","Mole Valley","E12000008","South East",11,"Flat","2011-02-21","2011-02-22",74.29,3,3365.19046978059,3285804868,"B","B",81,84,"End-Terrace","E07000210","E14000824","Surrey","marketed sale",81,82,138,127,1.7,23,1.6,89,44,257,263,97,97,"Single","Y","1st","N",4,"2106",100,"double glazing installed during or after 2002","Normal",0,3,0,0,"From main system","Very Good","Very Good","To external air, limited insulation (assumed)","N/A","N/A","Fully double glazed","Good","Good","Cavity wall, as built, insulated (assumed)","Good","Good","None","N/A","N/A","(another dwelling above)","N/A","N/A","Boiler and radiators, mains gas","Very Good","Very Good","Programmer, room thermostat and TRVs","Good","Good","No low energy lighting","Very Poor","Very Poor","mains gas - this is for backwards compatibility only and should not be used",0,"unheated corridor",1.3,2.36,0,"N","natural","Mole Valley","Mole Valley"
+10000020,"{49B7852A-7EEE-7921-E050-A8C063056E8D}","E00155711","RH5 5AB",645000,"2017-01-19","D","N","F","BAGGINS COTTAGE","","UNDERHILL ROAD","NEWDIGATE","DORKING","MOLE VALLEY","SURREY","A","A",2017,"E01030528","E02006374","E07000210","Mole Valley","E12000008","South East",11,"House","2011-01-12","2011-01-12",74.62,6,8643.79522916108,9737872868,"C","C",74,76,"Detached","E07000210","E14000824","Surrey","marketed sale",72,74,162,153,4,27,3.8,167,84,579,594,136,136,"Single","Y","NO DATA!","",NA,"2106",100,"double glazing installed during or after 2002","Normal",1,6,0,0,"From main system","Very Good","Very Good","Solid, insulated","N/A","N/A","Fully double glazed","Good","Good","Solid brick, with internal insulation","Good","Good","Room heaters, dual fuel (mineral and wood)","N/A","N/A","Roof room(s), insulated","Good","Good","Boiler and radiators, mains gas","Very Good","Very Good","Programmer, room thermostat and TRVs","Good","Good","No low energy lighting","Very Poor","Very Poor","mains gas - this is for backwards compatibility only and should not be used",0,"NO DATA!",NA,2.4,0,"N","natural","Mole Valley","Mole Valley"
+10000020,"{F8DC9177-95F9-41C1-84EB-38BA06C06672}","E00155711","RH5 5AB",447000,"2012-07-19","D","N","F","BAGGINS COTTAGE","","UNDERHILL ROAD","NEWDIGATE","DORKING","MOLE VALLEY","SURREY","A","A",2012,"E01030528","E02006374","E07000210","Mole Valley","E12000008","South East",11,"House","2011-01-12","2011-01-12",74.62,6,5990.35111230233,9737872868,"C","C",74,76,"Detached","E07000210","E14000824","Surrey","marketed sale",72,74,162,153,4,27,3.8,167,84,579,594,136,136,"Single","Y","NO DATA!","",NA,"2106",100,"double glazing installed during or after 2002","Normal",1,6,0,0,"From main system","Very Good","Very Good","Solid, insulated","N/A","N/A","Fully double glazed","Good","Good","Solid brick, with internal insulation","Good","Good","Room heaters, dual fuel (mineral and wood)","N/A","N/A","Roof room(s), insulated","Good","Good","Boiler and radiators, mains gas","Very Good","Very Good","Programmer, room thermostat and TRVs","Good","Good","No low energy lighting","Very Poor","Very Poor","mains gas - this is for backwards compatibility only and should not be used",0,"NO DATA!",NA,2.4,0,"N","natural","Mole Valley","Mole Valley"
+10000022,"{34428D7E-8128-B86C-E050-A8C06205059C}","E00155655","KT23 3EA",273032,"2016-03-30","T","N","F","21","","POST HOUSE LANE","BOOKHAM","LEATHERHEAD","MOLE VALLEY","SURREY","A","A",2016,"E01030516","E02006367","E07000210","Mole Valley","E12000008","South East",12,"House","2018-09-18","2018-09-18",84,5,3250.38095238095,465551568,"D","B",66,81,"Semi-Detached","E07000210","E14000824","Surrey","non marketed sale",61,77,243,135,3.6,43,2,58,58,566,533,163,85,"Single","Y","NODATA!","",NA,"2106",100,"double glazing, unknown install date","Normal",2,5,100,0,"From main system","Good","Good","Solid, no insulation (assumed)","NO DATA!","N/A","Fully double glazed","Average","Average","Cavity wall, filled cavity","Average","Average","None","N/A","N/A","Pitched, 270 mm loft insulation","Good","Good","Boiler and radiators, mains gas","Good","Good","Programmer, room thermostat and TRVs","Good","Good","Low energy lighting in all fixed outlets","Very Good","Very Good","mains gas (not community)",0,"NO DATA!",NA,NA,NA,"N","natural","Mole Valley","Mole Valley"
+10000027,"{F2963BC5-2616-4C21-833B-E18DE1BB35DE}","E00155858","RH4 3QR",317000,"2015-08-07","T","N","F","17","","BAILEY ROAD","WESTCOTT","DORKING","MOLE VALLEY","SURREY","A","A",2015,"E01030558","E02006373","E07000210","Mole Valley","E12000008","South East",11,"House","2015-05-14","2015-05-14",64,4,4953.125,5179206378,"D","B",58,84,"Mid-Terrace","E07000210","E14000824","Surrey","rental (private)",52,82,332,104,3.7,58,1.2,74,43,550,426,239,81,"Single","Y","NODATA!","",NA,"2106",100,"double glazing installed during or after 2002","Normal",0,4,27,1,"From main system, no cylinder thermostat","Average","Average","Suspended, no insulation (assumed)","NO DATA!","N/A","Fully double glazed","Good","Good","Solid brick, as built, no insulation (assumed)","Very Poor","Very Poor","None","N/A","N/A","Pitched, 150 mm loft insulation","Good","Good","Boiler and radiators, mains gas","Good","Good","Programmer, room thermostat and TRVs","Good","Good","Low energy lighting in 27% of fixed outlets","Average","Average","mains gas (not community)",0,"NO DATA!",NA,NA,NA,"N","natural","Mole Valley","Mole Valley"
+10000029,"{797D6CCC-2E3E-4FA4-B1AA-3172446F3E70}","E00155839","RH5 6JF",835000,"2015-07-17","D","N","F","FERN BANK","","ABINGER LANE","ABINGER COMMON","DORKING","MOLE VALLEY","SURREY","A","A",2015,"E01030555","E02006373","E07000210","Mole Valley","E12000008","South East",12,"House","2017-02-16","2017-03-14",180,7,4638.88888888889,513099468,"F","C",33,71,"Detached","E07000210","E14000824","Surrey","ECO assessment",26,57,309,119,15,82,6.7,157,90,1747,918,389,77,"Single","N","NODATA!","",NA,"2106",100,"double glazing, unknown install date","Normal",1,7,25,0,"Electric immersion, standard tariff","Very Poor","Poor","Solid, no insulation (assumed)","NO DATA!","N/A","Fully double glazed","Average","Average","Cob, as built","Average","Average","Room heaters, smokeless fuel","N/A","N/A","Pitched, no insulation","Very Poor","Very Poor","Boiler and radiators, oil","Poor","Average","Programmer, room thermostat and TRVs","Good","Good","Low energy lighting in 25% of fixed outlets","Average","Average","oil (not community)",0,"NO DATA!",NA,NA,NA,"N","natural","Mole Valley","Mole Valley"
+10000029,"{E11E3BE9-E337-478C-8F00-F6A92FFA1718}","E00155839","RH5 6JF",250000,"2013-10-22","D","N","F","FERN BANK","","ABINGER LANE","ABINGER COMMON","DORKING","MOLE VALLEY","SURREY","A","A",2013,"E01030555","E02006373","E07000210","Mole Valley","E12000008","South East",12,"House","2017-02-16","2017-03-14",180,7,1388.88888888889,513099468,"F","C",33,71,"Detached","E07000210","E14000824","Surrey","ECO assessment",26,57,309,119,15,82,6.7,157,90,1747,918,389,77,"Single","N","NODATA!","",NA,"2106",100,"double glazing, unknown install date","Normal",1,7,25,0,"Electric immersion, standard tariff","Very Poor","Poor","Solid, no insulation (assumed)","NO DATA!","N/A","Fully double glazed","Average","Average","Cob, as built","Average","Average","Room heaters, smokeless fuel","N/A","N/A","Pitched, no insulation","Very Poor","Very Poor","Boiler and radiators, oil","Poor","Average","Programmer, room thermostat and TRVs","Good","Good","Low energy lighting in 25% of fixed outlets","Average","Average","oil (not community)",0,"NO DATA!",NA,NA,NA,"N","natural","Mole Valley","Mole Valley"
+10000036,"{70DA407D-7E8D-45ED-BC71-355EF76C9EE3}","E00155747","RH4 3EF",220000,"2011-08-11","F","N","L","24","","SONDES FARM","","DORKING","MOLE VALLEY","SURREY","A","A",2011,"E01030535","E02006371","E07000210","Mole Valley","E12000008","South East",12,"Flat","2010-08-11","2010-08-12",94.43,4,2329.76808217727,8672868768,"C","C",73,80,"Detached","E07000210","E14000824","Surrey","marketed sale",71,78,195,149,3,32,2.3,115,57,379,334,166,131,"Single","Y","1st","Y",2,"2104",100,"double glazing installed before 2002","Normal",0,4,0,0,"From main system","Good","Good","(other premises below)","N/A","N/A","Fully double glazed","Average","Average","Timber frame, as built, insulated (assumed)","Good","Good","Room heaters, mains gas","N/A","N/A","Pitched, insulated (assumed)","Average","Average","Boiler and radiators, mains gas","Good","Good","Programmer and room thermostat","Average","Average","No low energy lighting","Very Poor","Very Poor","mains gas - this is for backwards compatibility only and should not be used",0,"heated corridor",NA,2.23,0,"N","natural","Mole Valley","Mole Valley"
+1000004,"{8F1B26BD-DFC9-53DB-E053-6C04A8C03649}","E00069522","LE3 0TR",95000,"2019-07-05","F","N","L","REGENCY COURT, 120 - 128","FLAT 1","HINCKLEY ROAD","","LEICESTER","LEICESTER","LEICESTER","A","A",2019,"E01013782","E02002849","E06000016","Leicester","E12000004","East Midlands",12,"Flat","2019-01-10","2019-01-10",42,2,2261.90476190476,9995482568,"C","C",70,74,"Semi-Detached","E06000016","E14000784",NA,"marketed sale",54,60,413,357,2.9,70,2.5,57,41,337,299,192,164,"Unknown","N","Ground","N",NA,"2401",100,"double glazing, unknown install date","Normal",0,2,60,0,"Electric immersion, off-peak","Average","Poor","Solid, limited insulation (assumed)","NO DATA!","N/A","Fully double glazed","Average","Average","Cavity wall, as built, insulated (assumed)","Good","Good","Portable electric heaters (assumed)","N/A","N/A","(another dwelling above)","N/A","N/A","Electric storage heaters","Average","Very Poor","Manual charge control","Poor","Poor","Low energy lighting in 60% of fixed outlets","Good","Good","electricity (not community)",0,"unheated corridor",7.96,NA,NA,"N","natural","Leicester","Leicester West"
+10000042,"{3209C493-49B9-4DEF-A08C-BDCCC63B175F}","E00155821","KT22 7LN",164500,"2012-09-28","F","N","L","BURLEIGH COURT","FLAT 16","BELMONT ROAD","","LEATHERHEAD","MOLE VALLEY","SURREY","A","A",2012,"E01030550","E02006364","E07000210","Mole Valley","E12000008","South East",11,"Flat","2010-10-29","2010-10-29",45.84,2,3588.56893542757,6521021868,"C","B",77,81,"Detached","E07000210","E14000824","Surrey","rental (private)",75,78,225,193,1.7,37,1.5,35,25,261,247,117,98,"Single","Y","2nd","Y",3,"2106",0,"not defined","Normal",0,2,60,0,"From main system","Good","Good","(other premises below)","N/A","N/A","Single glazed","Very Poor","Very Poor","Cavity wall, as built, insulated (assumed)","Good","Good","None","N/A","N/A","Pitched, 100 mm loft insulation","Average","Average","Boiler and radiators, mains gas","Good","Good","Programmer, room thermostat and TRVs","Good","Good","Low energy lighting in 60% of fixed outlets","Good","Good","mains gas - this is for backwards compatibility only and should not be used",0,"unheated corridor",2.8,2.37,0,"N","natural","Mole Valley","Mole Valley"
+10000047,"{61D8894E-5514-3DE6-E053-6C04A8C01207}","E00155760","KT22 9DN",3e+05,"2017-09-08","T","N","F","15","","ELMER MEWS","FETCHAM","LEATHERHEAD","MOLE VALLEY","SURREY","A","A",2017,"E01030539","E02006366","E07000210","Mole Valley","E12000008","South East",11,"House","2017-02-21","2017-02-21",58,3,5172.41379310345,4987810578,"D","B",60,89,"Enclosed End-Terrace","E07000210","E14000824","Surrey","marketed sale",55,89,315,57,3.2,55,0.6,65,41,491,315,191,66,"Unknown","Y","NODATA!","",NA,"2104",0,"not defined","Normal",1,3,43,0,"From main system","Average","Average","Suspended, no insulation (assumed)","NO DATA!","N/A","Single glazed","Very Poor","Very Poor","Cavity wall, as built, insulated (assumed)","Good","Good","None","N/A","N/A","Pitched, 100 mm loft insulation","Average","Average","Boiler and radiators, mains gas","Good","Good","Programmer and room thermostat","Average","Average","Low energy lighting in 43% of fixed outlets","Average","Average","mains gas (not community)",0,"NO DATA!",NA,NA,NA,"N","natural","Mole Valley","Mole Valley"
+1000005,"{4C4EDFFF-8C52-1854-E050-A8C063054F34}","E00069201","LE2 6GH",206000,"2017-03-20","S","N","F","48","","DEANCOURT ROAD","","LEICESTER","LEICESTER","LEICESTER","A","A",2017,"E01032599","E02006817","E06000016","Leicester","E12000004","East Midlands",11,"House","2016-11-25","2016-11-25",88,4,2340.90909090909,1122268478,"E","C",48,75,"Semi-Detached","E06000016","E14000783",NA,"marketed sale",40,68,408,196,6.3,72,3.1,86,57,1152,768,143,86,"Single","Y","NODATA!","",NA,"2106",100,"double glazing, unknown install date","Normal",1,4,50,0,"From main system","Good","Good","Suspended, no insulation (assumed)","NO DATA!","N/A","Fully double glazed","Average","Average","Solid brick, as built, no insulation (assumed)","Very Poor","Very Poor","Room heaters, mains gas","N/A","N/A","Pitched, no insulation (assumed)","Very Poor","Very Poor","Boiler and radiators, mains gas","Good","Good","Programmer, room thermostat and TRVs","Good","Good","Low energy lighting in 50% of fixed outlets","Good","Good","mains gas (not community)",0,"NO DATA!",NA,NA,NA,"N","natural","Leicester","Leicester South"
+10000052,"{79A74E22-27B4-1289-E053-6B04A8C01627}","E00155823","KT22 7JQ",335000,"2018-10-05","T","N","F","66","","TEAZLEWOOD PARK","","LEATHERHEAD","MOLE VALLEY","SURREY","A","A",2018,"E01030548","E02006364","E07000210","Mole Valley","E12000008","South East",11,"House","2010-07-21","2010-07-21",60.6,3,5528.05280528053,4136818768,"C","C",70,75,"Mid-Terrace","E07000210","E14000824","Surrey","marketed sale",66,71,265,223,2.7,44,2.3,67,36,330,334,188,133,"dual","Y","NO DATA!","",NA,"2504",100,"double glazing installed before 2002","Normal",0,3,13,0,"From main system, no cylinder thermostat","Poor","Average","Solid, no insulation (assumed)","N/A","N/A","Fully double glazed","Average","Average","Cavity wall, as built, insulated (assumed)","Good","Good","None","N/A","N/A","Pitched, 150 mm loft insulation","Good","Good","Warm air, mains gas","Good","Good","Programmer and room thermostat","Average","Average","Low energy lighting in 13% of fixed outlets","Poor","Poor","mains gas - this is for backwards compatibility only and should not be used",0,"NO DATA!",NA,2.31,0,"N","natural","Mole Valley","Mole Valley"
+10000055,"{37EABB84-72A2-4F2D-9698-2B800C42AF27}","E00155614","KT21 2AW",483000,"2012-01-06","D","N","F","1","","QUENNELL CLOSE","","ASHTEAD","MOLE VALLEY","SURREY","A","A",2012,"E01030509","E02006362","E07000210","Mole Valley","E12000008","South East",11,"Bungalow","2011-03-16","2011-03-16",95.77,3,5043.33298527723,3264484868,"E","E",53,54,"Detached","E07000210","E14000694","Surrey","marketed sale",52,52,325,321,5.1,53,5.1,78,52,896,903,133,133,"Unknown","Y","NO DATA!","",NA,"2106",100,"double glazing installed before 2002","Normal",0,3,50,1,"From main system","Very Good","Very Good","Suspended, no insulation (assumed)","N/A","N/A","Fully double glazed","Average","Average","Cavity wall, as built, no insulation (assumed)","Poor","Poor","Room heaters, electric","N/A","N/A","Pitched, 300+ mm loft insulation","Very Good","Very Good","Boiler and radiators, mains gas","Very Good","Very Good","Programmer, room thermostat and TRVs","Good","Good","Low energy lighting in 50% of fixed outlets","Good","Good","mains gas - this is for backwards compatibility only and should not be used",0,"NO DATA!",NA,2.512,0,"N","natural","Mole Valley","Epsom and Ewell"
+10000056,"{2693A8B3-FF41-423C-AE77-EBF6F611C032}","E00155748","RH4 2DF",328500,"2015-06-17","T","N","F","52","","BERESFORD ROAD","","DORKING","MOLE VALLEY","SURREY","A","A",2015,"E01030538","E02006371","E07000210","Mole Valley","E12000008","South East",12,"House","2015-03-10","2015-03-10",88,5,3732.95454545455,8607035968,"D","B",67,82,"End-Terrace","E07000210","E14000824","Surrey","marketed sale",66,81,214,111,3.3,37,1.7,69,55,595,553,150,83,"Single","Y","NODATA!","",NA,"2106",100,"double glazing installed during or after 2002","Normal",1,5,75,0,"From main system","Good","Good","Solid, no insulation (assumed)","NO DATA!","N/A","Fully double glazed","Good","Good","Cavity wall, filled cavity","Good","Good","Room heaters, electric","N/A","N/A","Pitched, 100 mm loft insulation","Average","Average","Boiler and radiators, mains gas","Good","Good","Programmer, room thermostat and TRVs","Good","Good","Low energy lighting in 75% of fixed outlets","Very Good","Very Good","mains gas (not community)",0,"NO DATA!",NA,NA,NA,"N","natural","Mole Valley","Mole Valley"
+10000058,"{6246B665-86CB-40CB-AAC3-084D3866152E}","E00155778","KT22 9UG",410000,"2014-12-15","T","N","F","12","","OSWALD CLOSE","FETCHAM","LEATHERHEAD","MOLE VALLEY","SURREY","A","A",2014,"E01030543","E02006366","E07000210","Mole Valley","E12000008","South East",11,"House","2014-07-07","2014-07-07",93,5,4408.60215053763,5352435278,"D","C",62,79,"End-Terrace","E07000210","E14000824","Surrey","marketed sale",59,77,223,118,4,43,2.2,81,54,647,610,189,79,"Single","Y","NODATA!","",NA,"2504",100,"double glazing, unknown install date","Normal",2,5,50,0,"From main system, no cylinder thermostat","Average","Average","Solid, no insulation (assumed)","N/A","N/A","Fully double glazed","Average","Average","Cavity wall, filled cavity","Good","Good","None","N/A","N/A","Pitched, 250 mm loft insulation","Good","Good","Warm air, mains gas","Good","Good","Programmer and room thermostat","Average","Average","Low energy lighting in 50% of fixed outlets","Good","Good","mains gas (not community)",0,"NO DATA!",NA,NA,0,"","natural","Mole Valley","Mole Valley"
+10000059,"{62D8A283-3CE6-4D3B-B848-439CAE2C09FB}","E00155823","KT22 7JR",280000,"2014-01-31","S","N","F","69","","TEAZLEWOOD PARK","","LEATHERHEAD","MOLE VALLEY","SURREY","A","A",2014,"E01030548","E02006364","E07000210","Mole Valley","E12000008","South East",11,"House","2013-04-30","2013-04-30",58,3,4827.58620689655,1534587078,"D","B",64,88,"Semi-Detached","E07000210","E14000824","Surrey","marketed sale",63,90,241,50,2.7,46,0.6,70,35,434,315,117,64,"Single","Y","NODATA!","",NA,"2104",40,"double glazing, unknown install date","Normal",0,3,0,0,"From main system","Good","Good","Solid, no insulation (assumed)","N/A","N/A","Partial double glazing","Poor","Poor","Cavity wall, as built, insulated (assumed)","Good","Good","None","N/A","N/A","Pitched, 200 mm loft insulation","Good","Good","Boiler and radiators, mains gas","Good","Good","Programmer and room thermostat","Average","Average","No low energy lighting","Very Poor","Very Poor","mains gas (not community)",0,"NO DATA!",NA,NA,0,"","natural","Mole Valley","Mole Valley"
+10000064,"{8F86FFE6-DE32-4069-9C8F-D293AB84CB0A}","E00155790","RH4 2PR",250000,"2013-09-10","S","N","F","15","","CLAYGATE ROAD","","DORKING","MOLE VALLEY","SURREY","A","A",2013,"E01030546","E02006372","E07000210","Mole Valley","E12000008","South East",12,"House","2014-02-27","2014-02-28",69,5,3623.1884057971,1656543768,"E","B",40,86,"Semi-Detached","E07000210","E14000824","Surrey","none of the above",37,87,418,70,5.6,81,1,67,43,921,395,235,73,"Single","Y","NODATA!","",NA,"2104",80,"double glazing installed during or after 2002","Normal",0,5,44,0,"From main system, no cylinder thermostat","Poor","Poor","Suspended, no insulation (assumed)","N/A","N/A","Mostly double glazing","Average","Average","Cavity wall, as built, no insulation (assumed)","Poor","Poor","Room heaters, mains gas","N/A","N/A","Pitched, no insulation","Very Poor","Very Poor","Boiler and radiators, mains gas","Good","Good","Programmer and room thermostat","Average","Average","Low energy lighting in 44% of fixed outlets","Average","Average","mains gas (not community)",0,"NO DATA!",NA,NA,0,"","natural","Mole Valley","Mole Valley"
+10000066,"{2FD36066-098A-4BF8-E050-A8C0620562B1}","E00155766","KT22 9HD",858500,"2016-02-16","D","N","F","59","","LOWER ROAD","FETCHAM","LEATHERHEAD","MOLE VALLEY","SURREY","A","A",2016,"E01030540","E02006366","E07000210","Mole Valley","E12000008","South East",11,"House","2015-10-05","2015-10-06",202,8,4250,9667659378,"E","C",49,71,"Detached","E07000210","E14000824","Surrey","marketed sale",39,62,317,173,11,56,6.2,196,98,1984,1356,167,105,"Unknown","Y","NODATA!","",NA,"2503",NA,"not defined","Much More Than Typical",1,8,0,1,"Electric immersion, off-peak","Average","Poor","Solid, no insulation (assumed)","NO DATA!","N/A","Multiple glazing throughout","Average","Average","Cavity wall, filled cavity","Good","Good","Room heaters, mains gas","N/A","N/A","Pitched, 100 mm loft insulation","Average","Average","Warm air, mains gas","Good","Good","Room thermostat only","Poor","Poor","No low energy lighting","Very Poor","Very Poor","mains gas (not community)",0,"NO DATA!",NA,NA,NA,"N","natural","Mole Valley","Mole Valley"
+10000067,"{79A74E22-2392-1289-E053-6B04A8C01627}","E00155745","RH4 3HX",435000,"2018-09-20","T","N","F","26","","MOUNT STREET","","DORKING","MOLE VALLEY","SURREY","A","A",2018,"E01030538","E02006371","E07000210","Mole Valley","E12000008","South East",12,"House","2017-11-09","2017-11-09",98,6,4438.77551020408,2881687868,"D","C",63,80,"Mid-Terrace","E07000210","E14000824","Surrey","marketed sale",62,80,243,126,3.8,39,1.9,102,63,762,623,93,61,"Single","Y","NODATA!","",NA,"2106",100,"double glazing installed during or after 2002","Normal",2,6,39,0,"From main system","Good","Good","Suspended, no insulation (assumed)","NO DATA!","N/A","Fully double glazed","Good","Good","Solid brick, as built, no insulation (assumed)","Very Poor","Very Poor","Room heaters, wood logs","N/A","N/A","Pitched, no insulation (assumed)","Very Poor","Very Poor","Boiler and radiators, mains gas","Good","Good","Programmer, room thermostat and TRVs","Good","Good","Low energy lighting in 39% of fixed outlets","Average","Average","mains gas (not community)",0,"NO DATA!",NA,NA,NA,"N","natural","Mole Valley","Mole Valley"
diff --git a/web/try/api/_samples/pizza-menu.csv b/web/try/api/_samples/pizza-menu.csv
new file mode 100644
index 00000000..0fc178d1
--- /dev/null
+++ b/web/try/api/_samples/pizza-menu.csv
@@ -0,0 +1,14 @@
+name,topping1,topping2,topping3,topping4,topping5,topping6,topping7
+Margherita,Mozzarella,Tomato,,,,,
+American,Mozzarella,Tomato,PeperoniSausage,,,,
+AmericanHot,Mozzarella,Tomato,PeperoniSausage,JalapenoPepper,HotGreenPepper,,
+Capricciosa,Mozzarella,Tomato,Ham,Olive,Anchovy,Caper,Peperonata
+Fiorentina,Mozzarella,Tomato,Spinach,Olive,Parmesan,Garlic,
+FourSeasons,Mozzarella,Tomato,PeperoniSausage,Mushroom,Olive,Anchovy,Caper
+LaReine,Mozzarella,Tomato,Ham,Mushroom,Olive,,
+Mushroom,Mozzarella,Tomato,Mushroom,,,,
+Napoletana,Mozzarella,Tomato,Anchovy,Caper,Olive,,
+Parmense,Mozzarella,Tomato,Ham,Parmesan,Asparagus,,
+SloppyGiuseppe,Mozzarella,Tomato,GreenPepper,Onion,HotSpicedBeef,,
+Soho,Mozzarella,Tomato,Olive,Parmesan,Garlic,Rocket,
+Veneziana,Mozzarella,Tomato,Olive,Caper,Onion,Sultana,PineKernel
diff --git a/web/try/api/_samples/staff.csv b/web/try/api/_samples/staff.csv
new file mode 100644
index 00000000..a705836c
--- /dev/null
+++ b/web/try/api/_samples/staff.csv
@@ -0,0 +1,9 @@
+emp_id,name,manager_id,grade,salary,started
+1,Ann Adair,,A,100000,2019-03-01
+2,Bob Baines,1,B,80000,2020-06-15
+3,Cy Chen,1,B,80500,2020-09-01
+4,Di Duarte,2,A,90000,2021-01-11
+5,Ed Evans,2,B,70000,2021-02-01
+6,Fi Fischer,3,A,60000,2022-05-23
+7,Gus Gray,3,C,52000,2022-08-08
+8,Hal Hume,4,C,51000,2023-01-09
diff --git a/web/try/api/index.py b/web/try/api/index.py
new file mode 100644
index 00000000..766bd1ed
--- /dev/null
+++ b/web/try/api/index.py
@@ -0,0 +1,209 @@
+"""Try it here: one sheet in, one ontology out, on the pinned engine.
+
+One Vercel Python function, no reimplementation. Every request writes the
+sheet to a scratch directory and runs the SAME `open-ontologies` binary a
+user would download, in `batch` mode, and returns what it printed. The page
+shows the engine's words, including the sentence that says an induced
+ontology is a hypothesis about the sheet and not a truth about the domain.
+
+Routes (all under /api/, the rewrite passes the tail as ?p=):
+ GET samples the bundled sample sheets
+ POST induce {name, csv, class?} -> the engine's induce report
+ POST check {name, csv, ontology_ttl, shapes_ttl, mapping} -> the engine's SHACL report
+ GET engine the pinned tag and binary hash
+"""
+from __future__ import annotations
+
+import hashlib
+import json
+import os
+import shutil
+import stat
+import subprocess
+import tempfile
+import time
+from http.server import BaseHTTPRequestHandler
+from pathlib import Path
+from urllib.parse import parse_qs, urlparse
+
+HERE = Path(__file__).resolve().parent
+SAMPLES = HERE / "_samples"
+MAX_BYTES = 1_000_000
+TIMEOUT_S = 40
+
+
+def engine() -> Path:
+ """The binary, executable, in a writable place. The deployment bundle is
+ read-only and may not keep the mode bit, so it is copied once per warm
+ instance into the scratch directory."""
+ override = os.environ.get("OO_BIN")
+ if override:
+ return Path(override)
+ src = HERE / "_bin" / "open-ontologies"
+ dst = Path(tempfile.gettempdir()) / "oo-engine" / "open-ontologies"
+ if not dst.exists() or dst.stat().st_size != src.stat().st_size:
+ dst.parent.mkdir(parents=True, exist_ok=True)
+ shutil.copyfile(src, dst)
+ dst.chmod(dst.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
+ return dst
+
+
+def engine_info() -> dict:
+ tag_file = HERE / "_bin" / "TAG"
+ tag = tag_file.read_text().strip() if tag_file.exists() else os.environ.get("OO_ENGINE_TAG", "local build")
+ try:
+ h = hashlib.sha256(engine().read_bytes()).hexdigest()
+ except Exception as e: # noqa: BLE001
+ h = f"unavailable: {e}"
+ return {"tag": tag, "sha256": h, "means": "every answer on this page is the output of this binary in batch mode; the page draws, it does not decide"}
+
+
+def run_batch(workdir: Path, script: str) -> list[dict]:
+ """Run one batch script and return the engine's JSON lines, in order."""
+ (workdir / "script.txt").write_text(script)
+ data_dir = workdir / "data"
+ data_dir.mkdir(exist_ok=True)
+ t0 = time.time()
+ proc = subprocess.run(
+ [str(engine()), "--data-dir", str(data_dir), "batch", str(workdir / "script.txt")],
+ capture_output=True, text=True, timeout=TIMEOUT_S, cwd=str(workdir),
+ )
+ out = []
+ for line in proc.stdout.splitlines():
+ if line.startswith("{"):
+ try:
+ out.append(json.loads(line))
+ except json.JSONDecodeError:
+ out.append({"command": "?", "result": {"error": f"unparseable engine line: {line[:200]}"}})
+ if not out:
+ raise RuntimeError(f"the engine printed nothing (exit {proc.returncode}): {proc.stderr[-800:]}")
+ out.append({"command": "_meta", "result": {"exit": proc.returncode, "seconds": round(time.time() - t0, 3), "stderr_tail": proc.stderr[-400:]}})
+ return out
+
+
+def safe_name(name: str) -> str:
+ base = Path(name or "sheet.csv").name
+ keep = "".join(c if c.isalnum() or c in "-_." else "_" for c in base)
+ if not keep.lower().endswith((".csv", ".json", ".ndjson", ".xml", ".yaml", ".yml")):
+ keep += ".csv"
+ return keep or "sheet.csv"
+
+
+def do_induce(body: dict) -> dict:
+ csv = body.get("csv") or ""
+ if not csv.strip():
+ return {"error": "the sheet is empty"}
+ if len(csv.encode()) > MAX_BYTES:
+ return {"error": f"the sheet is larger than {MAX_BYTES // 1000} kB; this page is for playing, run the engine locally for the real thing"}
+ name = safe_name(body.get("name", "sheet.csv"))
+ with tempfile.TemporaryDirectory(prefix="oo-try-") as td:
+ wd = Path(td)
+ (wd / name).write_text(csv)
+ out = wd / "induced"
+ cls = body.get("class") or ""
+ cls_arg = f" --class {''.join(c for c in cls if c.isalnum() or c in '-_')}" if cls.strip() else ""
+ base = "http://example.org/try/"
+ script = (
+ f"induce {wd / name} --out {out} --base-iri {base}{cls_arg}\n"
+ f"shacl {out / 'shapes.ttl'}\n"
+ "reason owl-rl\n"
+ "stats\n"
+ )
+ lines = run_batch(wd, script)
+ by = {l.get("command"): l.get("result") for l in lines}
+ ind = by.get("induce") or {}
+ if "error" in ind:
+ return {"error": ind["error"], "engine": lines}
+ return {
+ "induced": ind,
+ "shacl": by.get("shacl"),
+ "reason": by.get("reason"),
+ "stats": by.get("stats"),
+ "meta": by.get("_meta"),
+ "mapping_json": (out / "mapping.json").read_text() if (out / "mapping.json").exists() else None,
+ }
+
+
+def do_check(body: dict) -> dict:
+ csv = body.get("csv") or ""
+ if len(csv.encode()) > MAX_BYTES:
+ return {"error": "too large"}
+ for k in ("ontology_ttl", "shapes_ttl", "mapping"):
+ if not body.get(k):
+ return {"error": f"missing {k}; induce first"}
+ name = safe_name(body.get("name", "sheet.csv"))
+ with tempfile.TemporaryDirectory(prefix="oo-try-") as td:
+ wd = Path(td)
+ (wd / name).write_text(csv)
+ (wd / "ontology.ttl").write_text(body["ontology_ttl"])
+ (wd / "shapes.ttl").write_text(body["shapes_ttl"])
+ mapping = body["mapping"]
+ (wd / "mapping.json").write_text(mapping if isinstance(mapping, str) else json.dumps(mapping))
+ base = "http://example.org/try/"
+ script = (
+ f"load {wd / 'ontology.ttl'}\n"
+ f"ingest {wd / name} --mapping {wd / 'mapping.json'} --base-iri {base}\n"
+ f"shacl {wd / 'shapes.ttl'}\n"
+ )
+ lines = run_batch(wd, script)
+ by = {l.get("command"): l.get("result") for l in lines}
+ return {"ingest": by.get("ingest"), "shacl": by.get("shacl"), "meta": by.get("_meta")}
+
+
+def do_samples() -> dict:
+ items = []
+ for p in sorted(SAMPLES.glob("*.csv")):
+ text = p.read_text()
+ items.append({"name": p.name, "rows": max(0, text.count("\n") - 1), "csv": text})
+ return {"samples": items}
+
+
+class handler(BaseHTTPRequestHandler): # noqa: N801 (Vercel's expected name)
+ def _send(self, code: int, payload: dict) -> None:
+ data = json.dumps(payload).encode()
+ self.send_response(code)
+ self.send_header("Content-Type", "application/json; charset=utf-8")
+ self.send_header("Cache-Control", "no-store")
+ self.send_header("Content-Length", str(len(data)))
+ self.end_headers()
+ self.wfile.write(data)
+
+ def _route(self) -> str:
+ u = urlparse(self.path)
+ q = parse_qs(u.query)
+ if "p" in q:
+ return q["p"][0].strip("/")
+ return u.path.replace("/api/", "", 1).strip("/")
+
+ def do_GET(self): # noqa: N802
+ r = self._route()
+ try:
+ if r == "samples":
+ return self._send(200, do_samples())
+ if r == "engine":
+ return self._send(200, engine_info())
+ return self._send(404, {"error": f"no such route: {r}"})
+ except Exception as e: # noqa: BLE001
+ return self._send(500, {"error": str(e)})
+
+ def do_POST(self): # noqa: N802
+ r = self._route()
+ try:
+ n = int(self.headers.get("Content-Length") or 0)
+ if n > MAX_BYTES * 4:
+ return self._send(413, {"error": "request too large"})
+ body = json.loads(self.rfile.read(n) or b"{}")
+ if r == "induce":
+ res = do_induce(body)
+ elif r == "check":
+ res = do_check(body)
+ else:
+ return self._send(404, {"error": f"no such route: {r}"})
+ return self._send(400 if "error" in res else 200, res)
+ except subprocess.TimeoutExpired:
+ return self._send(504, {"error": f"the engine did not finish in {TIMEOUT_S} s"})
+ except Exception as e: # noqa: BLE001
+ return self._send(500, {"error": str(e)})
+
+ def log_message(self, *_): # quiet
+ pass
diff --git a/web/try/build.sh b/web/try/build.sh
new file mode 100644
index 00000000..e618bb0a
--- /dev/null
+++ b/web/try/build.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+# Fetch the PINNED engine release for the function. The page runs the same
+# binary a user would download; nothing here is a reimplementation of it.
+set -eu
+TAG="${OO_ENGINE_TAG:-v1.5.0}"
+mkdir -p api/_bin
+URL="https://github.com/fabio-rovai/open-ontologies/releases/download/${TAG}/open-ontologies-x86_64-unknown-linux-gnu"
+echo "engine: ${URL}"
+curl -fsSL -o api/_bin/open-ontologies "${URL}"
+curl -fsSL -o api/_bin/SHASUMS.txt "https://github.com/fabio-rovai/open-ontologies/releases/download/${TAG}/SHASUMS.txt"
+WANT=$(grep 'x86_64-unknown-linux-gnu' api/_bin/SHASUMS.txt | awk '{print $1}')
+GOT=$(sha256sum api/_bin/open-ontologies | awk '{print $1}')
+[ "$WANT" = "$GOT" ] || { echo "checksum mismatch: want $WANT got $GOT"; exit 1; }
+chmod +x api/_bin/open-ontologies
+echo "${TAG}" > api/_bin/TAG
+echo "engine ${TAG} pinned, sha256 ${GOT}"
diff --git a/web/try/local.py b/web/try/local.py
new file mode 100644
index 00000000..6fc00440
--- /dev/null
+++ b/web/try/local.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+"""Serve the page locally against a local engine: OO_BIN=target/debug/open-ontologies python3 local.py"""
+import os, sys
+from http.server import HTTPServer, SimpleHTTPRequestHandler
+from pathlib import Path
+sys.path.insert(0, str(Path(__file__).parent / "api"))
+from index import handler as api # noqa: E402
+
+PUBLIC = Path(__file__).parent / "public"
+
+class H(api):
+ def do_GET(self):
+ if self.path.startswith("/api/"):
+ return api.do_GET(self)
+ p = PUBLIC / (self.path.split("?")[0].strip("/") or "index.html")
+ if not p.exists():
+ self.send_response(404); self.end_headers(); return
+ data = p.read_bytes(); self.send_response(200)
+ self.send_header("Content-Type", "text/html; charset=utf-8" if p.suffix == ".html" else "application/octet-stream")
+ self.send_header("Content-Length", str(len(data))); self.end_headers(); self.wfile.write(data)
+
+port = int(os.environ.get("PORT", "8787"))
+print(f"engine: {os.environ.get('OO_BIN', '(bundled)')} -> http://127.0.0.1:{port}/")
+HTTPServer(("127.0.0.1", port), H).serve_forever()
diff --git a/web/try/public/index.html b/web/try/public/index.html
new file mode 100644
index 00000000..fc91125b
--- /dev/null
+++ b/web/try/public/index.html
@@ -0,0 +1,188 @@
+<!doctype html>
+<html lang="en">
+<head>
+<meta charset="utf-8">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<title>Open Ontologies: try it here</title>
+<meta name="description" content="Drop one spreadsheet. Get one ontology, one shape, and the evidence for every line, from the same engine you would download. Then break a cell and watch the shape catch it.">
+<style>
+:root{--bg:#fafafa;--panel:#fff;--ink:#1a1a1a;--muted:#505a5f;--dim:#7a8288;--line:#e5e7eb;--code:#f6f8fa;--accent:#0b5fff;--ok:#0a7d3e;--bad:#c81e1e;--warn:#9a6700;--focus:#ffdd00;
+--sans:ui-sans-serif,-apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;--mono:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
+*{box-sizing:border-box}html,body{margin:0;background:var(--bg);color:var(--ink);font:15px/1.55 var(--sans)}
+a{color:var(--accent)}code,pre,textarea.code{font-family:var(--mono);font-size:12.5px}
+header{border-bottom:1px solid var(--line);background:var(--panel)}
+.wrap{max-width:1120px;margin:0 auto;padding:0 20px}
+header .wrap{display:flex;align-items:baseline;gap:18px;padding:14px 20px}
+header h1{font-size:17px;margin:0;font-weight:800;letter-spacing:.2px}header h1 span{color:var(--muted);font-weight:500}
+header nav{margin-left:auto;font-size:13px;color:var(--muted)}header nav a{margin-left:14px}
+main{padding:26px 0 60px}
+h2{font-size:15px;margin:0 0 10px;letter-spacing:.4px;text-transform:uppercase;color:var(--muted)}
+.lede{font-size:18px;max-width:820px;margin:0 0 6px}.lede b{font-weight:800}
+.sub{color:var(--muted);max-width:820px;margin:0 0 22px}
+.grid{display:grid;grid-template-columns:1fr;gap:18px}
+.card{background:var(--panel);border:1px solid var(--line);border-radius:10px;padding:16px 18px}
+.drop{display:block;border:2px dashed #c9ced3;border-radius:10px;padding:22px;text-align:center;color:var(--muted);cursor:pointer;transition:.15s}
+.drop.on{border-color:var(--accent);background:#eef4ff;color:var(--ink)}
+.drop input{display:none}
+.samples{display:flex;gap:8px;flex-wrap:wrap;margin-top:12px}
+button{font:inherit;border:1px solid var(--line);background:var(--panel);border-radius:8px;padding:7px 12px;cursor:pointer}
+button:hover{border-color:#9aa3ab}button.primary{background:var(--accent);color:#fff;border-color:var(--accent);font-weight:700}
+button:disabled{opacity:.5;cursor:default}button:focus-visible,.drop:focus-visible{outline:3px solid var(--focus);outline-offset:2px}
+textarea.code{width:100%;min-height:150px;border:1px solid var(--line);border-radius:8px;padding:10px;background:var(--code);resize:vertical}
+.row{display:flex;gap:10px;align-items:center;flex-wrap:wrap;margin-top:10px}
+.status{font-size:13px;color:var(--muted)}.status.err{color:var(--bad)}
+.tabs{display:flex;gap:4px;border-bottom:1px solid var(--line);margin:14px 0 10px;flex-wrap:wrap}
+.tabs button{border:0;border-bottom:2px solid transparent;border-radius:0;padding:6px 10px;background:none;color:var(--muted)}
+.tabs button.on{color:var(--ink);border-bottom-color:var(--accent);font-weight:700}
+pre{background:var(--code);border:1px solid var(--line);border-radius:8px;padding:12px;overflow:auto;max-height:520px;margin:0;white-space:pre}
+table{border-collapse:collapse;width:100%;font-size:13px;table-layout:fixed}th,td{text-align:left;padding:6px 8px;border-bottom:1px solid var(--line);vertical-align:top;overflow-wrap:anywhere}
+.ev th:nth-child(1){width:11%}.ev th:nth-child(2){width:12%}.ev th:nth-child(3){width:9%}.ev th:nth-child(4),.ev th:nth-child(5),.ev th:nth-child(6){width:5.5%}.ev th:nth-child(7){width:15%}.ev td:last-child{font-size:12px;color:var(--muted)}
+.gridwrap table{table-layout:auto}
+th{font-size:11.5px;letter-spacing:.5px;text-transform:uppercase;color:var(--muted)}td.mono{font-family:var(--mono);font-size:12px}
+.pill{display:inline-block;border-radius:999px;padding:1px 8px;font-size:11.5px;font-weight:700;letter-spacing:.3px}
+.pill.ok{background:#e6f4ea;color:var(--ok)}.pill.bad{background:#fde8e8;color:var(--bad)}.pill.warn{background:#fff4d6;color:var(--warn)}.pill.dim{background:#eef0f2;color:var(--muted)}
+.summary{font-size:16px;margin:0 0 4px}.summary b{font-weight:800}
+.means{font-size:13px;color:var(--muted);border-left:3px solid var(--line);padding:6px 12px;margin:10px 0 0}
+.gridwrap{overflow:auto;max-height:420px;border:1px solid var(--line);border-radius:8px}
+.gridwrap td[contenteditable]{outline:none;font-family:var(--mono);font-size:12px;min-width:60px}
+.gridwrap td[contenteditable]:focus{background:#fffbe6}.gridwrap td.changed{background:#fff4d6}
+.viol{border-left:3px solid var(--bad);padding:6px 10px;margin:8px 0;background:#fff;border-radius:0 6px 6px 0;font-size:13px}
+.viol code{background:var(--code);padding:1px 4px;border-radius:4px}
+footer{border-top:1px solid var(--line);color:var(--muted);font-size:13px;padding:18px 0 40px}
+.hidden{display:none}
+.kv{display:grid;grid-template-columns:max-content 1fr;gap:4px 14px;font-size:13px;margin:8px 0}
+.kv dt{color:var(--muted)}.kv dd{margin:0}
+</style>
+</head>
+<body>
+<header><div class="wrap">
+ <h1>open-ontologies <span>· try it here</span></h1>
+ <nav><a href="https://github.com/fabio-rovai/open-ontologies">repository</a><a href="https://github.com/fabio-rovai/open-ontologies/blob/main/docs/tool-reference.md">tool reference</a><a href="#what">what this is</a></nav>
+</div></header>
+
+<main class="wrap">
+ <p class="lede"><b>One sheet in, one ontology out</b>, with the evidence for every line. Then break a cell and watch the shape catch it.</p>
+ <p class="sub">Everything below is the output of the engine you would download, run in batch mode on this page's server: <code>induce</code>, then <code>shacl</code>, then <code>reason owl-rl</code>. The page draws; it does not decide. Engine <span id="engine">…</span>.</p>
+
+ <div class="grid">
+ <section class="card">
+ <h2>1 · A sheet</h2>
+ <div style="display:grid;grid-template-columns:minmax(220px,1fr) 2fr;gap:14px"><div><label class="drop" id="drop" tabindex="0">Drop a CSV here, or click to choose one (up to 1 MB)<input type="file" id="file" accept=".csv,text/csv,.json,.ndjson"></label>
+ <div class="samples" id="samples"><span class="status">loading samples…</span></div></div>
+ <textarea class="code" id="csv" spellcheck="false" placeholder="…or paste CSV with a header row" style="min-height:190px"></textarea></div>
+ <div class="row">
+ <button class="primary" id="go">Induce the ontology</button>
+ <label class="status">class name <input id="cls" placeholder="from the file name" style="font:inherit;padding:4px 6px;border:1px solid var(--line);border-radius:6px;width:150px"></label>
+ <span class="status" id="st1"></span>
+ </div>
+ </section>
+
+ <section class="card" id="out" hidden>
+ <h2>2 · What the engine induced</h2>
+ <p class="summary" id="summary"></p>
+ <dl class="kv" id="kv"></dl>
+ <div class="tabs" id="tabs">
+ <button data-t="evidence" class="on">Evidence</button><button data-t="ontology">Ontology (Turtle)</button><button data-t="shapes">Shapes (Turtle)</button><button data-t="mapping">Mapping</button><button data-t="engine">Engine output</button>
+ </div>
+ <div id="t-evidence"></div>
+ <pre id="t-ontology" class="hidden"></pre>
+ <pre id="t-shapes" class="hidden"></pre>
+ <pre id="t-mapping" class="hidden"></pre>
+ <pre id="t-engine" class="hidden"></pre>
+ <p class="means" id="means"></p>
+ </section>
+ </div>
+
+ <section class="card" id="play" hidden style="margin-top:18px">
+ <h2>3 · Break it</h2>
+ <p class="sub" style="margin-bottom:8px">The rows satisfy their own induced shape <i>by construction</i>, so the clean report above proves nothing. The shape constrains the <b>next</b> row. Edit any cell below (a word where a number was, a value outside an enumeration, a second value where there was one, an empty required cell) and re-check. The violation you get is the engine's SHACL validator over the induced shapes, not a page rule.</p>
+ <div class="gridwrap" id="gridwrap"></div>
+ <div class="row">
+ <button class="primary" id="recheck">Re-check the edited rows</button>
+ <button id="reset">Reset rows</button>
+ <span class="status" id="st2"></span>
+ </div>
+ <div id="viols"></div>
+ </section>
+
+ <section id="what" style="margin-top:26px">
+ <h2>What this is, and is not</h2>
+ <p class="sub" style="margin-bottom:8px">An induced ontology is a <b>hypothesis about the sheet</b>, not a truth about the domain. Three choices are deliberate: cardinality becomes a <i>shape</i> and never <code>owl:FunctionalProperty</code>, because under OWL RL a functional property with two values does not reject the second row, it identifies the two objects (<code>prp-fp</code>); observed numeric ranges are reported and never made <code>sh:minInclusive</code>; numbered columns (<code>topping1…topping7</code>) become one multi-valued property, and the group is reported so a false merge is visible. Strike what your domain does not support; the evidence column says what each line rests on.</p>
+ <p class="sub">Same thing from an MCP client, on your own files: <code>onto_induce {"path": "sheet.csv"}</code>. From the shell: <code>open-ontologies batch</code> with <code>induce sheet.csv --out ./induced</code>.</p>
+ </section>
+</main>
+<footer><div class="wrap">Nothing you upload is kept: each request runs in a fresh scratch directory that is deleted when the response is sent. Limits: 1 MB per sheet, 40 s per run. <a href="https://github.com/fabio-rovai/open-ontologies">fabio-rovai/open-ontologies</a>, Apache-2.0.</div></footer>
+
+<script>
+const $=s=>document.querySelector(s);
+const api=(p,opt)=>fetch('/api/'+p,opt).then(async r=>{const j=await r.json().catch(()=>({error:'not JSON: '+r.status}));if(!r.ok&&!j.error)j.error='HTTP '+r.status;return j});
+let current={name:'sheet.csv',csv:'',induced:null,mapping:null,rows:[],headers:[]};
+
+api('engine').then(j=>{$('#engine').textContent=j.tag?`${j.tag}, sha256 ${String(j.sha256).slice(0,12)}…`:'unavailable'}).catch(()=>{$('#engine').textContent='unavailable'});
+api('samples').then(j=>{const box=$('#samples');box.innerHTML='<span class="status">samples:</span>';(j.samples||[]).forEach(s=>{const b=document.createElement('button');b.textContent=`${s.name} (${s.rows} rows)`;b.onclick=()=>{$('#csv').value=s.csv;current.name=s.name;$('#cls').value='';$('#st1').textContent=`loaded ${s.name}`};box.appendChild(b)});
+ // ?sample=epc-sample.csv&auto=1 loads a bundled sheet and runs it, so a link can carry a worked example.
+ const q=new URLSearchParams(location.search),want=q.get('sample');const hit=(j.samples||[]).find(s=>s.name===want);if(hit){$('#csv').value=hit.csv;current.name=hit.name;$('#st1').textContent=`loaded ${hit.name}`;if(q.get('auto')==='1')$('#go').click()}});
+
+const drop=$('#drop'),file=$('#file');
+drop.onclick=()=>file.click();drop.onkeydown=e=>{if(e.key==='Enter'||e.key===' ')file.click()};
+['dragenter','dragover'].forEach(ev=>drop.addEventListener(ev,e=>{e.preventDefault();drop.classList.add('on')}));
+['dragleave','drop'].forEach(ev=>drop.addEventListener(ev,e=>{e.preventDefault();drop.classList.remove('on')}));
+drop.addEventListener('drop',e=>{const f=e.dataTransfer.files[0];if(f)readFile(f)});
+file.onchange=()=>{if(file.files[0])readFile(file.files[0])};
+function readFile(f){if(f.size>1_000_000){$('#st1').textContent='that file is over 1 MB; run the engine locally for it';$('#st1').className='status err';return}
+ const r=new FileReader();r.onload=()=>{$('#csv').value=r.result;current.name=f.name;$('#st1').className='status';$('#st1').textContent=`loaded ${f.name}`};r.readAsText(f)}
+
+// A small CSV parser for the editable grid only; the ENGINE parses the sheet it is sent.
+function parseCsv(t){const rows=[];let row=[],cell='',q=false;for(let i=0;i<t.length;i++){const c=t[i];if(q){if(c==='"'){if(t[i+1]==='"'){cell+='"';i++}else q=false}else cell+=c}
+ else if(c==='"')q=true;else if(c===','){row.push(cell);cell=''}else if(c==='\n'){row.push(cell);rows.push(row);row=[];cell=''}else if(c!=='\r')cell+=c}
+ if(cell.length||row.length){row.push(cell);rows.push(row)}return rows.filter(r=>r.length>1||(r.length===1&&r[0]!==''))}
+function toCsv(headers,rows){const esc=v=>/[",\n]/.test(v)?'"'+v.replace(/"/g,'""')+'"':v;return [headers,...rows].map(r=>r.map(esc).join(',')).join('\n')+'\n'}
+
+$('#tabs').onclick=e=>{const b=e.target.closest('button');if(!b)return;[...$('#tabs').children].forEach(x=>x.classList.toggle('on',x===b));['evidence','ontology','shapes','mapping','engine'].forEach(t=>$('#t-'+t).classList.toggle('hidden',t!==b.dataset.t))};
+
+$('#go').onclick=async()=>{const csv=$('#csv').value;if(!csv.trim()){$('#st1').textContent='paste or choose a sheet first';return}
+ current.csv=csv;$('#go').disabled=true;$('#st1').className='status';$('#st1').textContent='running the engine…';
+ const j=await api('induce',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({name:current.name,csv,class:$('#cls').value})});
+ $('#go').disabled=false;
+ if(j.error){$('#st1').className='status err';$('#st1').textContent=j.error;if(j.engine)console.log(j.engine);return}
+ $('#st1').textContent=`done in ${j.meta?.seconds ?? '?'} s`;render(j)};
+
+function render(j){const ind=j.induced;current.induced=ind;current.mapping=j.mapping_json||JSON.stringify(ind.mapping);
+ $('#out').hidden=false;$('#play').hidden=false;
+ const props=ind.columns.length,obj=ind.columns.filter(c=>c.refers_to).length,enums=ind.columns.filter(c=>c.values).length,groups=ind.columns.filter(c=>c.columns.length>1).length;
+ $('#summary').innerHTML=`<b>${esc(ind.class)}</b>: ${ind.rows} rows → 1 class, ${props} propert${props===1?'y':'ies'}${obj?` (${obj} object)`:''}${groups?`, ${groups} numbered group${groups>1?'s':''} merged`:''}${enums?`, ${enums} enumeration${enums>1?'s':''}`:''}.`;
+ const sh=j.shacl||{},rs=j.reason||{};
+ const conf=sh.conforms===true?'<span class="pill ok">conforms</span>':sh.conforms===false?'<span class="pill bad">violations</span>':'<span class="pill warn">undetermined</span>';
+ $('#kv').innerHTML=`<dt>identifier</dt><dd><code>${esc(ind.id_column)}</code>${ind.id_synthesised?' <span class="pill dim">row number: no column was filled and unique</span>':''}</dd>
+ <dt>shape over its own rows</dt><dd>${conf} ${sh.violation_count??0} violation(s), ${sh.focus_nodes??'?'} focus nodes. Expected: the rows satisfy the shape by construction.</dd>
+ <dt>owl-rl closure</dt><dd>${rs.inferred_count!=null?`${rs.inferred_count} inferred triples over ${rs.initial_triples??'?'} asserted`:(rs.error||'not run')}</dd>
+ <dt>loaded</dt><dd>${ind.loaded?`${ind.loaded.schema_triples} schema + ${ind.loaded.instance_triples} instance triples`:'—'}</dd>`;
+ let t='<table class="ev"><thead><tr><th>property</th><th>columns</th><th>type</th><th>filled</th><th>distinct</th><th>per row</th><th>decision</th><th>evidence</th></tr></thead><tbody>';
+ ind.columns.forEach(c=>{const dec=[];if(c.refers_to)dec.push(`<span class="pill ok">object → ${esc(c.refers_to)}</span>`);if(c.values)dec.push(`<span class="pill warn">sh:in (${c.values.length})</span>`);if(c.columns.length>1)dec.push(`<span class="pill dim">group of ${c.columns.length}</span>`);if(c.filled===c.rows)dec.push('<span class="pill dim">minCount 1</span>');dec.push(`<span class="pill dim">maxCount ${Math.max(1,c.max_per_row)}</span>`);
+ t+=`<tr><td class="mono">${esc(c.property)}</td><td class="mono">${esc(c.columns.join(', '))}</td><td class="mono">${c.refers_to?'IRI':'xsd:'+esc(c.datatype)}</td><td>${c.filled}/${c.rows}</td><td>${c.distinct}</td><td>${c.max_per_row}</td><td>${dec.join(' ')}</td><td style="color:var(--muted)">${esc(c.evidence)}${Object.keys(c.observed||{}).length?'; observed '+esc(Object.entries(c.observed).map(([k,v])=>k+' '+v).join(', '))+' (reported, not constrained)':''}</td></tr>`});
+ $('#t-evidence').innerHTML=t+'</tbody></table>';
+ $('#t-ontology').textContent=ind.ontology_ttl;$('#t-shapes').textContent=ind.shapes_ttl;$('#t-mapping').textContent=pretty(current.mapping);
+ $('#t-engine').textContent=JSON.stringify({induce:{...ind,ontology_ttl:'(see tab)',shapes_ttl:'(see tab)',mapping:'(see tab)'},shacl:j.shacl,reason:j.reason,stats:j.stats,meta:j.meta},null,1);
+ $('#means').textContent='The engine says: '+ind.means;
+ const rows=parseCsv(current.csv);current.headers=rows[0]||[];current.rows=rows.slice(1);grid()}
+
+function grid(){const h=current.headers,rows=current.rows.slice(0,40);let t='<table><thead><tr><th>#</th>'+h.map(x=>`<th>${esc(x)}</th>`).join('')+'</tr></thead><tbody>';
+ rows.forEach((r,i)=>{t+=`<tr><td style="color:var(--dim)">${i+1}</td>`+h.map((_,k)=>`<td contenteditable data-r="${i}" data-c="${k}">${esc(r[k]??'')}</td>`).join('')+'</tr>'});
+ $('#gridwrap').innerHTML=t+'</tbody></table>'+(current.rows.length>40?`<div class="status" style="padding:6px 8px">showing 40 of ${current.rows.length} rows; all rows are re-checked</div>`:'');
+ $('#gridwrap').oninput=e=>{const td=e.target.closest('td[contenteditable]');if(!td)return;const r=+td.dataset.r,c=+td.dataset.c;current.rows[r][c]=td.textContent;td.classList.add('changed')};$('#viols').innerHTML='';$('#st2').textContent=''}
+$('#reset').onclick=()=>{const rows=parseCsv(current.csv);current.rows=rows.slice(1);grid()};
+$('#recheck').onclick=async()=>{if(!current.induced)return;$('#recheck').disabled=true;$('#st2').className='status';$('#st2').textContent='running the engine…';
+ const csv=toCsv(current.headers,current.rows);
+ const j=await api('check',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({name:current.name,csv,ontology_ttl:current.induced.ontology_ttl,shapes_ttl:current.induced.shapes_ttl,mapping:current.mapping})});
+ $('#recheck').disabled=false;if(j.error){$('#st2').className='status err';$('#st2').textContent=j.error;return}
+ const sh=j.shacl||{};$('#st2').textContent=`${j.meta?.seconds??'?'} s · ${j.ingest?.triples_loaded??'?'} triples loaded`;
+ const v=sh.violations||[];let html=sh.conforms===true?'<p class="status"><span class="pill ok">conforms</span> the edited rows still satisfy the induced shape. Try a word in a numeric column, or a value outside an enumeration.</p>':sh.conforms===false?`<p class="status"><span class="pill bad">${v.length} violation${v.length===1?'':'s'}</span> reported by the engine's SHACL validator:</p>`:`<p class="status"><span class="pill warn">undetermined</span> ${esc(JSON.stringify(sh.skipped_constraints||sh))}</p>`;
+ v.slice(0,50).forEach(x=>{html+=`<div class="viol"><code>${esc(short(x.focus_node))}</code> · <code>${esc(short(x.result_path||x.path||''))}</code> · ${esc(short(x.source_constraint_component||x.constraint||''))}<br>${esc(x.message||'')}</div>`});
+ if(v.length>50)html+=`<p class="status">…and ${v.length-50} more</p>`;$('#viols').innerHTML=html};
+
+function esc(s){return String(s??'').replace(/[&<>"]/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;'}[c]))}
+function short(s){s=String(s||'');const i=Math.max(s.lastIndexOf('#'),s.lastIndexOf('/'));return i>=0&&i<s.length-1?s.slice(i+1):s}
+function pretty(s){try{return JSON.stringify(typeof s==='string'?JSON.parse(s):s,null,1)}catch{return String(s)}}
+</script>
+</body>
+</html>
diff --git a/web/try/requirements.txt b/web/try/requirements.txt
new file mode 100644
index 00000000..e69de29b
diff --git a/web/try/vercel.json b/web/try/vercel.json
new file mode 100644
index 00000000..7d8ec6db
--- /dev/null
+++ b/web/try/vercel.json
@@ -0,0 +1,8 @@
+{
+ "buildCommand": "sh build.sh",
+ "outputDirectory": "public",
+ "rewrites": [{ "source": "/api/(.*)", "destination": "/api/index?p=$1" }],
+ "functions": {
+ "api/index.py": { "memory": 1024, "maxDuration": 60, "includeFiles": "api/_bin/**,api/_samples/**" }
+ }
+}