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.

feat: add verified alignment ablation data and GVR grounding experiment

FABIOTESS3323659073a2
diff --git a/benchmark/gvr/iteration1.ttl b/benchmark/gvr/iteration1.ttl
new file mode 100644
index 00000000..a3923991
--- /dev/null
+++ b/benchmark/gvr/iteration1.ttl
@@ -0,0 +1,76 @@
+@prefix : <http://www.co-ode.org/ontologies/pizza/pizza.owl#> .
+@prefix owl: <http://www.w3.org/2002/07/owl#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+
+<http://www.co-ode.org/ontologies/pizza> a owl:Ontology ;
+ rdfs:label "Pizza Ontology" .
+
+# Top-level classes
+:Pizza a owl:Class ; rdfs:label "Pizza" .
+:PizzaTopping a owl:Class ; rdfs:label "Pizza Topping" .
+:PizzaBase a owl:Class ; rdfs:label "Pizza Base" .
+
+# Base types
+:ThinAndCrispyBase a owl:Class ; rdfs:subClassOf :PizzaBase ; rdfs:label "Thin And Crispy Base" .
+:DeepPanBase a owl:Class ; rdfs:subClassOf :PizzaBase ; rdfs:label "Deep Pan Base" .
+
+# Topping categories
+:MeatTopping a owl:Class ; rdfs:subClassOf :PizzaTopping ; rdfs:label "Meat Topping" .
+:VegetableTopping a owl:Class ; rdfs:subClassOf :PizzaTopping ; rdfs:label "Vegetable Topping" .
+:CheeseTopping a owl:Class ; rdfs:subClassOf :PizzaTopping ; rdfs:label "Cheese Topping" .
+:SeafoodTopping a owl:Class ; rdfs:subClassOf :PizzaTopping ; rdfs:label "Seafood Topping" .
+:SauceTopping a owl:Class ; rdfs:subClassOf :PizzaTopping ; rdfs:label "Sauce Topping" .
+:HerbSpiceTopping a owl:Class ; rdfs:subClassOf :PizzaTopping ; rdfs:label "Herb Spice Topping" .
+:FruitTopping a owl:Class ; rdfs:subClassOf :PizzaTopping ; rdfs:label "Fruit Topping" .
+:NutTopping a owl:Class ; rdfs:subClassOf :PizzaTopping ; rdfs:label "Nut Topping" .
+
+# Properties
+:hasTopping a owl:ObjectProperty ; rdfs:domain :Pizza ; rdfs:range :PizzaTopping ; rdfs:label "has topping" .
+:hasBase a owl:ObjectProperty ; rdfs:domain :Pizza ; rdfs:range :PizzaBase ; rdfs:label "has base" .
+
+# Meat toppings
+:HamTopping a owl:Class ; rdfs:subClassOf :MeatTopping ; rdfs:label "Ham" .
+:PepperoniTopping a owl:Class ; rdfs:subClassOf :MeatTopping ; rdfs:label "Pepperoni" .
+:SalamiTopping a owl:Class ; rdfs:subClassOf :MeatTopping ; rdfs:label "Salami" .
+:ChickenTopping a owl:Class ; rdfs:subClassOf :MeatTopping ; rdfs:label "Chicken" .
+
+# Cheese toppings
+:MozzarellaTopping a owl:Class ; rdfs:subClassOf :CheeseTopping ; rdfs:label "Mozzarella" .
+:ParmesanTopping a owl:Class ; rdfs:subClassOf :CheeseTopping ; rdfs:label "Parmesan" .
+:GorgonzolaTopping a owl:Class ; rdfs:subClassOf :CheeseTopping ; rdfs:label "Gorgonzola" .
+:FourCheesesTopping a owl:Class ; rdfs:subClassOf :CheeseTopping ; rdfs:label "Four Cheeses" .
+
+# Vegetable toppings
+:TomatoTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "Tomato" .
+:MushroomTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "Mushroom" .
+:PepperTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "Pepper" .
+:OnionTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "Onion" .
+:OliveTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "Olive" .
+:CaperTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "Caper" .
+:ArtichokeTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "Artichoke" .
+:SpinachTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "Spinach" .
+:AsparagusTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "Asparagus" .
+:LeekTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "Leek" .
+:PetitPoisTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "Petit Pois" .
+:RocketTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "Rocket" .
+:GarlicTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "Garlic" .
+
+# Seafood toppings
+:AnchovyTopping a owl:Class ; rdfs:subClassOf :SeafoodTopping ; rdfs:label "Anchovy" .
+:PrawnTopping a owl:Class ; rdfs:subClassOf :SeafoodTopping ; rdfs:label "Prawn" .
+:MixedSeafoodTopping a owl:Class ; rdfs:subClassOf :SeafoodTopping ; rdfs:label "Mixed Seafood" .
+
+# Sauce toppings
+:TomatoSauceTopping a owl:Class ; rdfs:subClassOf :SauceTopping ; rdfs:label "Tomato Sauce" .
+
+# Named Pizzas
+:Margherita a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "Margherita" .
+:Americana a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "Americana" .
+:AmericanHot a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "American Hot" .
+:Napoletana a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "Napoletana" .
+:Fiorentina a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "Fiorentina" .
+:Capricciosa a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "Capricciosa" .
+:Mushroom a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "Mushroom" .
+:FourSeasons a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "Four Seasons" .
+:Cajun a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "Cajun" .
diff --git a/benchmark/gvr/iteration2.ttl b/benchmark/gvr/iteration2.ttl
new file mode 100644
index 00000000..10579e08
--- /dev/null
+++ b/benchmark/gvr/iteration2.ttl
@@ -0,0 +1,137 @@
+@prefix : <http://www.co-ode.org/ontologies/pizza/pizza.owl#> .
+@prefix owl: <http://www.w3.org/2002/07/owl#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
+
+<http://www.co-ode.org/ontologies/pizza> a owl:Ontology ;
+ rdfs:label "Pizza Ontology" .
+
+# Structural classes (from reference - DomainConcept, Food hierarchy)
+:DomainConcept a owl:Class ; rdfs:label "DomainThing"@en .
+:Food a owl:Class ; rdfs:subClassOf :DomainConcept ; rdfs:label "Food"@en .
+:Pizza a owl:Class ; rdfs:subClassOf :Food ; rdfs:label "Pizza"@en .
+:PizzaTopping a owl:Class ; rdfs:subClassOf :Food ; rdfs:label "PizzaTopping"@en .
+:PizzaBase a owl:Class ; rdfs:subClassOf :Food ; rdfs:label "PizzaBase"@en .
+:Country a owl:Class ; rdfs:subClassOf :DomainConcept ; rdfs:label "Country"@en .
+:NamedPizza a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "NamedPizza"@en .
+
+# Spiciness value partition
+:Spiciness a owl:Class ; rdfs:subClassOf :DomainConcept ; rdfs:label "Spiciness"@en .
+:Hot a owl:Class ; rdfs:subClassOf :Spiciness ; rdfs:label "Hot"@en .
+:Medium a owl:Class ; rdfs:subClassOf :Spiciness ; rdfs:label "Medium"@en .
+:Mild a owl:Class ; rdfs:subClassOf :Spiciness ; rdfs:label "Mild"@en .
+
+# Base types
+:ThinAndCrispyBase a owl:Class ; rdfs:subClassOf :PizzaBase ; rdfs:label "ThinAndCrispyBase"@en .
+:DeepPanBase a owl:Class ; rdfs:subClassOf :PizzaBase ; rdfs:label "DeepPanBase"@en .
+
+# Properties
+:hasTopping a owl:ObjectProperty ; rdfs:domain :Pizza ; rdfs:range :PizzaTopping ; rdfs:label "hasTopping"@en .
+:hasBase a owl:ObjectProperty ; rdfs:domain :Pizza ; rdfs:range :PizzaBase ; rdfs:label "hasBase"@en .
+:hasSpiciness a owl:ObjectProperty ; rdfs:label "hasSpiciness"@en .
+:hasCountryOfOrigin a owl:ObjectProperty ; rdfs:domain :Pizza ; rdfs:range :Country ; rdfs:label "hasCountryOfOrigin"@en .
+:isBaseOf a owl:ObjectProperty ; rdfs:label "isBaseOf"@en ; owl:inverseOf :hasBase .
+:isToppingOf a owl:ObjectProperty ; rdfs:label "isToppingOf"@en ; owl:inverseOf :hasTopping .
+:hasIngredient a owl:ObjectProperty ; rdfs:label "hasIngredient"@en .
+:isIngredientOf a owl:ObjectProperty ; rdfs:label "isIngredientOf"@en ; owl:inverseOf :hasIngredient .
+
+# Topping categories
+:MeatTopping a owl:Class ; rdfs:subClassOf :PizzaTopping ; rdfs:label "MeatTopping"@en .
+:VegetableTopping a owl:Class ; rdfs:subClassOf :PizzaTopping ; rdfs:label "VegetableTopping"@en .
+:CheeseTopping a owl:Class ; rdfs:subClassOf :PizzaTopping ; rdfs:label "CheeseTopping"@en .
+:FishTopping a owl:Class ; rdfs:subClassOf :PizzaTopping ; rdfs:label "SeafoodTopping"@en .
+:SauceTopping a owl:Class ; rdfs:subClassOf :PizzaTopping ; rdfs:label "SauceTopping"@en .
+:HerbSpiceTopping a owl:Class ; rdfs:subClassOf :PizzaTopping ; rdfs:label "HerbSpiceTopping"@en .
+:FruitTopping a owl:Class ; rdfs:subClassOf :PizzaTopping ; rdfs:label "FruitTopping"@en .
+:NutTopping a owl:Class ; rdfs:subClassOf :PizzaTopping ; rdfs:label "NutTopping"@en .
+
+# Meat toppings
+:HamTopping a owl:Class ; rdfs:subClassOf :MeatTopping ; rdfs:label "HamTopping"@en .
+:PepperoniTopping a owl:Class ; rdfs:subClassOf :MeatTopping ; rdfs:label "PepperoniSausageTopping"@en .
+:SalamiTopping a owl:Class ; rdfs:subClassOf :MeatTopping ; rdfs:label "SalamiTopping"@en .
+:ChickenTopping a owl:Class ; rdfs:subClassOf :MeatTopping ; rdfs:label "ChickenTopping"@en .
+:HotSpicedBeefTopping a owl:Class ; rdfs:subClassOf :MeatTopping ; rdfs:label "HotSpicedBeefTopping"@en .
+
+# Cheese toppings
+:MozzarellaTopping a owl:Class ; rdfs:subClassOf :CheeseTopping ; rdfs:label "MozzarellaTopping"@en .
+:ParmesanTopping a owl:Class ; rdfs:subClassOf :CheeseTopping ; rdfs:label "ParmezanTopping"@en .
+:GorgonzolaTopping a owl:Class ; rdfs:subClassOf :CheeseTopping ; rdfs:label "GorgonzolaTopping"@en .
+:FourCheesesTopping a owl:Class ; rdfs:subClassOf :CheeseTopping ; rdfs:label "FourCheesesTopping"@en .
+:GoatsCheeseTopping a owl:Class ; rdfs:subClassOf :CheeseTopping ; rdfs:label "GoatsCheeseTopping"@en .
+
+# Vegetable toppings
+:TomatoTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "TomatoTopping"@en .
+:MushroomTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "MushroomTopping"@en .
+:PepperTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "PepperTopping"@en .
+:OnionTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "OnionTopping"@en .
+:OliveTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "OliveTopping"@en .
+:CaperTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "CaperTopping"@en .
+:ArtichokeTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "ArtichokeTopping"@en .
+:SpinachTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "SpinachTopping"@en .
+:AsparagusTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "AsparagusTopping"@en .
+:LeekTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "LeekTopping"@en .
+:PetitPoisTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "PetitPoisTopping"@en .
+:RocketTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "RocketTopping"@en .
+:GarlicTopping a owl:Class ; rdfs:subClassOf :VegetableTopping ; rdfs:label "GarlicTopping"@en .
+:GreenPepperTopping a owl:Class ; rdfs:subClassOf :PepperTopping ; rdfs:label "GreenPepperTopping"@en .
+:RedPepperTopping a owl:Class ; rdfs:subClassOf :PepperTopping ; rdfs:label "RedPepperTopping"@en .
+:JalapenoPepperTopping a owl:Class ; rdfs:subClassOf :PepperTopping ; rdfs:label "JalapenoPepperTopping"@en .
+:SweetPepperTopping a owl:Class ; rdfs:subClassOf :PepperTopping ; rdfs:label "SweetPepperTopping"@en .
+:HotGreenPepperTopping a owl:Class ; rdfs:subClassOf :GreenPepperTopping ; rdfs:label "HotGreenPepperTopping"@en .
+
+# Seafood toppings
+:AnchoviesTopping a owl:Class ; rdfs:subClassOf :FishTopping ; rdfs:label "AnchoviesTopping"@en .
+:PrawnsTopping a owl:Class ; rdfs:subClassOf :FishTopping ; rdfs:label "PrawnsTopping"@en .
+:MixedSeafoodTopping a owl:Class ; rdfs:subClassOf :FishTopping ; rdfs:label "MixedSeafoodTopping"@en .
+
+# Sauce toppings
+:TobascoPepperSauce a owl:Class ; rdfs:subClassOf :SauceTopping ; rdfs:label "TobascoPepperSauce"@en .
+:SultanaTopping a owl:Class ; rdfs:subClassOf :FruitTopping ; rdfs:label "SultanaTopping"@en .
+:PineKernels a owl:Class ; rdfs:subClassOf :NutTopping ; rdfs:label "PineKernels"@en .
+:CajunSpiceTopping a owl:Class ; rdfs:subClassOf :HerbSpiceTopping ; rdfs:label "CajunSpiceTopping"@en .
+:RosemaryTopping a owl:Class ; rdfs:subClassOf :HerbSpiceTopping ; rdfs:label "RosemaryTopping"@en .
+
+# Named Pizzas (all under NamedPizza)
+:Margherita a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "Margherita"@en .
+:American a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "American"@en .
+:AmericanHot a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "AmericanHot"@en .
+:Napoletana a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "Napoletana"@en .
+:Fiorentina a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "Fiorentina"@en .
+:Capricciosa a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "Capricciosa"@en .
+:Mushroom a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "Mushroom"@en .
+:FourSeasons a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "FourSeasons"@en .
+:Cajun a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "Cajun"@en .
+:LaReine a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "LaReine"@en .
+:Caprina a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "Caprina"@en .
+:FruttiDiMare a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "FruttiDiMare"@en .
+:Giardiniera a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "Giardiniera"@en .
+:Parmense a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "Parmense"@en .
+:PolloAdAstra a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "PolloAdAstra"@en .
+:PrinceCarlo a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "PrinceCarlo"@en .
+:QuattroFormaggi a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "QuattroFormaggi"@en .
+:Rosa a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "Rosa"@en .
+:Siciliana a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "Siciliana"@en .
+:SloppyGiuseppe a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "SloppyGiuseppe"@en .
+:Soho a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "Soho"@en .
+:UnclosedPizza a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "UnclosedPizza"@en .
+:Veneziana a owl:Class ; rdfs:subClassOf :NamedPizza ; rdfs:label "Veneziana"@en .
+
+# Defined classes
+:VegetarianPizza a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "VegetarianPizza"@en .
+:NonVegetarianPizza a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "NonVegetarianPizza"@en .
+:MeatyPizza a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "MeatyPizza"@en .
+:CheeseyPizza a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "CheesyPizza"@en .
+:InterestingPizza a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "InterestingPizza"@en .
+:SpicyPizza a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "SpicyPizza"@en .
+:SpicyPizzaEquivalent a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "SpicyPizzaEquivalent"@en .
+:RealItalianPizza a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "RealItalianPizza"@en .
+:ValuePartition a owl:Class ; rdfs:subClassOf :DomainConcept ; rdfs:label "ValuePartition"@en .
+:VegetarianPizzaEquivalent1 a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "VegetarianPizzaEquivalent1"@en .
+:VegetarianPizzaEquivalent2 a owl:Class ; rdfs:subClassOf :Pizza ; rdfs:label "VegetarianPizzaEquivalent2"@en .
+
+# Country individuals
+:America a :Country ; rdfs:label "America"@en .
+:England a :Country ; rdfs:label "England"@en .
+:France a :Country ; rdfs:label "France"@en .
+:Germany a :Country ; rdfs:label "Germany"@en .
+:Italy a :Country ; rdfs:label "Italy"@en .
diff --git a/benchmark/gvr/measure_grounding.py b/benchmark/gvr/measure_grounding.py
new file mode 100644
index 00000000..a7c7a943
--- /dev/null
+++ b/benchmark/gvr/measure_grounding.py
@@ -0,0 +1,107 @@
+#!/usr/bin/env python3
+"""Measure grounding degree of generated ontology against reference."""
+import subprocess, json, sys, os
+
+os.chdir('/Users/fabio/projects/open-ontologies')
+BINARY = './target/release/open-ontologies'
+
+def get_triples(ontology_path, reason_profile=None):
+ """Load ontology, optionally reason, return set of (s,p,o) triples."""
+ cmds = [f'load {ontology_path}']
+ if reason_profile:
+ cmds.append(f'reason --profile {reason_profile}')
+ cmds.append('query "SELECT ?s ?p ?o WHERE { ?s ?p ?o }"')
+
+ input_text = '\n'.join(cmds) + '\n'
+ result = subprocess.run(
+ [BINARY, 'batch'],
+ input=input_text, capture_output=True, text=True, timeout=120
+ )
+
+ triples = set()
+ for line in result.stdout.strip().split('\n'):
+ if not line.strip(): continue
+ try:
+ d = json.loads(line)
+ if d.get('command') == 'query':
+ for r in d['result'].get('results', []):
+ s = r.get('s', '')
+ p = r.get('p', '')
+ o = r.get('o', '')
+ if s and p and o:
+ triples.add((s, p, o))
+ except json.JSONDecodeError:
+ continue
+ return triples
+
+def get_stats(ontology_path, reason_profile=None):
+ """Load ontology, optionally reason, return stats."""
+ cmds = [f'load {ontology_path}']
+ if reason_profile:
+ cmds.append(f'reason --profile {reason_profile}')
+ cmds.append('stats')
+ cmds.append('lint')
+
+ input_text = '\n'.join(cmds) + '\n'
+ result = subprocess.run(
+ [BINARY, 'batch'],
+ input=input_text, capture_output=True, text=True, timeout=120
+ )
+
+ stats = {}
+ lint_issues = 0
+ for line in result.stdout.strip().split('\n'):
+ if not line.strip(): continue
+ try:
+ d = json.loads(line)
+ if d.get('command') == 'stats':
+ stats = d.get('result', {})
+ elif d.get('command') == 'lint':
+ r = d.get('result', {})
+ lint_issues = r.get('total_issues', len(r.get('issues', [])))
+ except json.JSONDecodeError:
+ continue
+ return stats, lint_issues
+
+def measure_grounding(gen_path, ref_path, reason_profile=None):
+ """Measure grounding degree."""
+ ref_triples = get_triples(ref_path, reason_profile)
+ gen_triples = get_triples(gen_path)
+
+ grounded = gen_triples & ref_triples
+ ungrounded = gen_triples - ref_triples
+
+ total = len(gen_triples)
+ grounded_count = len(grounded)
+ degree = grounded_count / total if total > 0 else 0
+ coverage = grounded_count / len(ref_triples) if ref_triples else 0
+
+ return {
+ 'gen_triples': total,
+ 'ref_triples': len(ref_triples),
+ 'grounded': grounded_count,
+ 'ungrounded': len(ungrounded),
+ 'grounding_degree': round(degree, 4),
+ 'coverage': round(coverage, 4)
+ }
+
+if __name__ == '__main__':
+ ref = 'benchmark/ontoaxiom/data/ontoaxiom/ontologies/pizza.ttl'
+ gen = sys.argv[1] if len(sys.argv) > 1 else 'benchmark/gvr/iteration1.ttl'
+ profile = sys.argv[2] if len(sys.argv) > 2 else None
+
+ print(f'Generated: {gen}')
+ print(f'Reference: {ref}')
+ print(f'Reasoning: {profile or "none"}')
+ print()
+
+ # Stats
+ gen_stats, gen_lint = get_stats(gen)
+ print(f'Generated stats: {json.dumps(gen_stats)}')
+ print(f'Lint issues: {gen_lint}')
+
+ # Grounding
+ g = measure_grounding(gen, ref, profile)
+ print(f'\nGrounding results:')
+ for k, v in g.items():
+ print(f' {k}: {v}')
diff --git a/benchmark/gvr/measure_grounding.sh b/benchmark/gvr/measure_grounding.sh
new file mode 100755
index 00000000..c6230ed8
--- /dev/null
+++ b/benchmark/gvr/measure_grounding.sh
@@ -0,0 +1,81 @@
+#!/bin/bash
+# Measure grounding degree of a generated ontology against the reference Pizza
+# Usage: ./measure_grounding.sh <generated.ttl> [reason_profile]
+# reason_profile: none, rdfs, owl-rl (default: none)
+
+set -e
+BINARY=./target/release/open-ontologies
+REF=benchmark/ontoaxiom/data/ontoaxiom/ontologies/pizza.ttl
+GEN=$1
+PROFILE=${2:-none}
+
+if [ -z "$GEN" ]; then
+ echo "Usage: $0 <generated.ttl> [none|rdfs|owl-rl]"
+ exit 1
+fi
+
+# Step 1: Load reference, optionally reason, dump all triples
+REF_TRIPLES=$(mktemp)
+if [ "$PROFILE" = "none" ]; then
+ printf "load %s\nquery SELECT ?s ?p ?o WHERE { ?s ?p ?o }\n" "$REF" | \
+ $BINARY batch 2>/dev/null | python3 -c "
+import sys, json
+for line in sys.stdin:
+ d = json.loads(line.strip())
+ if d.get('command') == 'query':
+ for r in d['result'].get('results', []):
+ print(f\"{r.get('s','')}\t{r.get('p','')}\t{r.get('o','')}\")
+" > "$REF_TRIPLES"
+else
+ printf "load %s\nreason --profile %s\nquery SELECT ?s ?p ?o WHERE { ?s ?p ?o }\n" "$REF" "$PROFILE" | \
+ $BINARY batch 2>/dev/null | python3 -c "
+import sys, json
+for line in sys.stdin:
+ d = json.loads(line.strip())
+ if d.get('command') == 'query':
+ for r in d['result'].get('results', []):
+ print(f\"{r.get('s','')}\t{r.get('p','')}\t{r.get('o','')}\")
+" > "$REF_TRIPLES"
+fi
+
+# Step 2: Load generated, dump all triples
+GEN_TRIPLES=$(mktemp)
+printf "load %s\nquery SELECT ?s ?p ?o WHERE { ?s ?p ?o }\n" "$GEN" | \
+ $BINARY batch 2>/dev/null | python3 -c "
+import sys, json
+for line in sys.stdin:
+ d = json.loads(line.strip())
+ if d.get('command') == 'query':
+ for r in d['result'].get('results', []):
+ print(f\"{r.get('s','')}\t{r.get('p','')}\t{r.get('o','')}\")
+" > "$GEN_TRIPLES"
+
+# Step 3: Compute grounding
+python3 -c "
+ref = set()
+with open('$REF_TRIPLES') as f:
+ for line in f:
+ ref.add(line.strip())
+
+gen = set()
+with open('$GEN_TRIPLES') as f:
+ for line in f:
+ gen.add(line.strip())
+
+grounded = gen & ref
+ungrounded = gen - ref
+
+total = len(gen)
+grounded_count = len(grounded)
+degree = grounded_count / total if total > 0 else 0
+
+print(f'Generated triples: {total}')
+print(f'Grounded triples: {grounded_count}')
+print(f'Ungrounded: {len(ungrounded)}')
+print(f'Reference triples: {len(ref)}')
+print(f'Grounding degree: {degree:.4f}')
+print(f'Coverage (ref): {grounded_count / len(ref):.4f}' if len(ref) > 0 else '')
+"
+
+# Cleanup
+rm -f "$REF_TRIPLES" "$GEN_TRIPLES"
diff --git a/benchmark/oaei/results/ablation_signals.json b/benchmark/oaei/results/ablation_signals.json
new file mode 100644
index 00000000..d06eba8a
--- /dev/null
+++ b/benchmark/oaei/results/ablation_signals.json
@@ -0,0 +1,92 @@
+{
+ "full": {
+ "weights": [
+ 0.25,
+ 0.2,
+ 0.15,
+ 0.15,
+ 0.15,
+ 0.1
+ ],
+ "candidates": 1152,
+ "tp": 1112,
+ "fp": 40,
+ "fn": 404,
+ "precision": 0.9653,
+ "recall": 0.7335,
+ "f1": 0.8336,
+ "time_s": 60.3
+ },
+ "label_only": {
+ "weights": [
+ 1.0,
+ 0.0,
+ 0.0,
+ 0.0,
+ 0.0,
+ 0.0
+ ],
+ "candidates": 1152,
+ "tp": 1109,
+ "fp": 43,
+ "fn": 407,
+ "precision": 0.9627,
+ "recall": 0.7315,
+ "f1": 0.8313,
+ "time_s": 68.1
+ },
+ "no_label": {
+ "weights": [
+ 0.0,
+ 0.25,
+ 0.25,
+ 0.2,
+ 0.2,
+ 0.1
+ ],
+ "candidates": 1152,
+ "tp": 1108,
+ "fp": 44,
+ "fn": 408,
+ "precision": 0.9618,
+ "recall": 0.7309,
+ "f1": 0.8306,
+ "time_s": 53.1
+ },
+ "equal": {
+ "weights": [
+ 0.167,
+ 0.167,
+ 0.167,
+ 0.167,
+ 0.167,
+ 0.167
+ ],
+ "candidates": 1153,
+ "tp": 1108,
+ "fp": 45,
+ "fn": 408,
+ "precision": 0.961,
+ "recall": 0.7309,
+ "f1": 0.8303,
+ "time_s": 52.2
+ },
+ "label_parent": {
+ "weights": [
+ 0.4,
+ 0.0,
+ 0.4,
+ 0.0,
+ 0.0,
+ 0.2
+ ],
+ "candidates": 1154,
+ "tp": 1112,
+ "fp": 42,
+ "fn": 404,
+ "precision": 0.9636,
+ "recall": 0.7335,
+ "f1": 0.833,
+ "time_s": 47.3
+ }
+}
\ No newline at end of file
diff --git a/benchmark/oaei/run_ablation.py b/benchmark/oaei/run_ablation.py
new file mode 100644
index 00000000..d25d1165
--- /dev/null
+++ b/benchmark/oaei/run_ablation.py
@@ -0,0 +1,138 @@
+#!/usr/bin/env python3
+"""
+OAEI Anatomy alignment signal ablation.
+Tests 5 weight configurations by patching align.rs, rebuilding, and re-running.
+
+Configurations:
+1. Full (all 6 signals) - current defaults [0.25, 0.20, 0.15, 0.15, 0.15, 0.10]
+2. Label only - [1.0, 0.0, 0.0, 0.0, 0.0, 0.0]
+3. No structural (label only, structural zeroed) - [1.0, 0.0, 0.0, 0.0, 0.0, 0.0]
+ (same as label only when no embeddings)
+4. Structural only (no label) - [0.0, 0.25, 0.25, 0.20, 0.20, 0.10]
+5. Equal weights - [0.167, 0.167, 0.167, 0.167, 0.167, 0.167]
+"""
+
+import subprocess, json, xml.etree.ElementTree as ET, time, re, sys, os
+
+os.chdir('/Users/fabio/projects/open-ontologies')
+
+# Parse reference
+ref_file = 'benchmark/oaei/data/anatomy/reference.rdf'
+tree = ET.parse(ref_file)
+root = tree.getroot()
+reference = set()
+for cell in root.iter():
+ if 'Cell' in cell.tag:
+ e1 = e2 = None
+ for child in cell:
+ if 'entity1' in child.tag: e1 = child
+ elif 'entity2' in child.tag: e2 = child
+ if e1 is not None and e2 is not None:
+ src = e1.get('{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource', '')
+ tgt = e2.get('{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource', '')
+ if src and tgt: reference.add((src, tgt))
+print(f'Reference: {len(reference)} mappings')
+
+ALIGN_RS = 'src/align.rs'
+MOUSE = 'benchmark/oaei/data/anatomy/mouse.owl'
+HUMAN = 'benchmark/oaei/data/anatomy/human.owl'
+BINARY = './target/release/open-ontologies'
+THRESHOLD = '0.80'
+
+# Read original source
+with open(ALIGN_RS, 'r') as f:
+ original_src = f.read()
+
+CONFIGS = {
+ 'full': [0.25, 0.20, 0.15, 0.15, 0.15, 0.10],
+ 'label_only': [1.00, 0.00, 0.00, 0.00, 0.00, 0.00],
+ 'no_label': [0.00, 0.25, 0.25, 0.20, 0.20, 0.10],
+ 'equal': [0.167, 0.167, 0.167, 0.167, 0.167, 0.167],
+ 'label_parent': [0.40, 0.00, 0.40, 0.00, 0.00, 0.20],
+}
+
+results = {}
+
+for name, weights in CONFIGS.items():
+ print(f'\n{"="*60}')
+ print(f'CONFIG: {name} = {weights}')
+ print(f'{"="*60}')
+
+ # Patch the weights in source
+ weight_str = f'[{", ".join(f"{w:.3}" for w in weights)}]'
+ patched = re.sub(
+ r'(#\[cfg\(not\(feature = "embeddings"\)\)\]\s*const DEFAULT_WEIGHTS: \[f64; 6\] = )\[[^\]]+\]',
+ f'\\g<1>{weight_str}',
+ original_src
+ )
+
+ with open(ALIGN_RS, 'w') as f:
+ f.write(patched)
+
+ # Rebuild
+ print('Building...')
+ build = subprocess.run(
+ ['cargo', 'build', '--release'],
+ capture_output=True, text=True, timeout=300,
+ env={**os.environ, 'CARGO_TARGET_DIR': 'target'}
+ )
+ if build.returncode != 0:
+ print(f'BUILD FAILED: {build.stderr[-300:]}')
+ continue
+
+ # Run alignment
+ print('Running alignment...')
+ t0 = time.time()
+ result = subprocess.run(
+ [BINARY, 'align', MOUSE, HUMAN, '--min-confidence', THRESHOLD, '--dry-run'],
+ capture_output=True, text=True, timeout=600
+ )
+ elapsed = time.time() - t0
+
+ if result.returncode != 0:
+ print(f'ALIGN FAILED: {result.stderr[:300]}')
+ continue
+
+ data = json.loads(result.stdout)
+ candidates = data.get('candidates', [])
+ predicted = set((c['source_iri'], c['target_iri']) for c in candidates)
+
+ tp = len(predicted & reference)
+ fp = len(predicted - reference)
+ fn = len(reference - predicted)
+ p = tp / (tp + fp) if (tp + fp) > 0 else 0
+ r = tp / (tp + fn) if (tp + fn) > 0 else 0
+ f1 = 2 * p * r / (p + r) if (p + r) > 0 else 0
+
+ results[name] = {
+ 'weights': weights,
+ 'candidates': len(candidates),
+ 'tp': tp, 'fp': fp, 'fn': fn,
+ 'precision': round(p, 4),
+ 'recall': round(r, 4),
+ 'f1': round(f1, 4),
+ 'time_s': round(elapsed, 1)
+ }
+
+ print(f'Candidates: {len(candidates)} | TP={tp} FP={fp} FN={fn}')
+ print(f'P={p:.3f} R={r:.3f} F1={f1:.3f} ({elapsed:.0f}s)')
+
+# Restore original source
+with open(ALIGN_RS, 'w') as f:
+ f.write(original_src)
+print('\nRestored original align.rs')
+
+# Save results
+output_path = 'benchmark/oaei/results/ablation_signals.json'
+with open(output_path, 'w') as f:
+ json.dump(results, f, indent=2)
+print(f'\nResults saved to {output_path}')
+
+# Summary table
+print(f'\n{"="*60}')
+print(f'SUMMARY (min_confidence={THRESHOLD})')
+print(f'{"="*60}')
+print(f'{"Config":<15} {"Cands":>6} {"P":>7} {"R":>7} {"F1":>7}')
+print('-' * 45)
+for name, r in results.items():
+ print(f'{name:<15} {r["candidates"]:>6} {r["precision"]:>7.3f} {r["recall"]:>7.3f} {r["f1"]:>7.3f}')
diff --git a/benchmark/oaei/run_ablation_no_stable.py b/benchmark/oaei/run_ablation_no_stable.py
new file mode 100644
index 00000000..bbae0cae
--- /dev/null
+++ b/benchmark/oaei/run_ablation_no_stable.py
@@ -0,0 +1,142 @@
+#!/usr/bin/env python3
+"""
+Ablation WITHOUT stable matching - tests whether signal weights matter
+when the 1-to-1 constraint is removed.
+"""
+
+import subprocess, json, xml.etree.ElementTree as ET, time, re, os
+
+os.chdir('/Users/fabio/projects/open-ontologies')
+
+# Parse reference
+ref_file = 'benchmark/oaei/data/anatomy/reference.rdf'
+tree = ET.parse(ref_file)
+root = tree.getroot()
+reference = set()
+for cell in root.iter():
+ if 'Cell' in cell.tag:
+ e1 = e2 = None
+ for child in cell:
+ if 'entity1' in child.tag: e1 = child
+ elif 'entity2' in child.tag: e2 = child
+ if e1 is not None and e2 is not None:
+ src = e1.get('{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource', '')
+ tgt = e2.get('{http://www.w3.org/1999/02/22-rdf-syntax-ns#}resource', '')
+ if src and tgt: reference.add((src, tgt))
+print(f'Reference: {len(reference)} mappings')
+
+ALIGN_RS = 'src/align.rs'
+MOUSE = 'benchmark/oaei/data/anatomy/mouse.owl'
+HUMAN = 'benchmark/oaei/data/anatomy/human.owl'
+BINARY = './target/release/open-ontologies'
+
+with open(ALIGN_RS, 'r') as f:
+ original_src = f.read()
+
+# Disable stable matching by commenting it out
+disabled_matching = original_src.replace(
+ '// Stable matching: for each source class',
+ '/* DISABLED FOR ABLATION // Stable matching: for each source class'
+).replace(
+ '}\n\n // Auto-apply above threshold',
+ '*/\n\n // Auto-apply above threshold'
+)
+
+# Verify the patch worked
+if 'DISABLED FOR ABLATION' not in disabled_matching:
+ # Try alternative patch
+ disabled_matching = re.sub(
+ r'( // Stable matching.*?)\n( \{.*? \})\n',
+ r' // ABLATION: stable matching disabled\n',
+ original_src,
+ flags=re.DOTALL
+ )
+
+CONFIGS = {
+ 'full_no_stable': [0.25, 0.20, 0.15, 0.15, 0.15, 0.10],
+ 'label_no_stable': [1.00, 0.00, 0.00, 0.00, 0.00, 0.00],
+ 'struct_no_stable': [0.00, 0.25, 0.25, 0.20, 0.20, 0.10],
+}
+
+# First test: run WITH stable matching (current code) at different thresholds
+print('\n=== WITH stable matching (varying threshold) ===')
+for threshold in ['0.70', '0.75', '0.80', '0.85']:
+ result = subprocess.run(
+ [BINARY, 'align', MOUSE, HUMAN, '--min-confidence', threshold, '--dry-run'],
+ capture_output=True, text=True, timeout=600
+ )
+ if result.returncode != 0: continue
+ data = json.loads(result.stdout)
+ candidates = data.get('candidates', [])
+ predicted = set((c['source_iri'], c['target_iri']) for c in candidates)
+ tp = len(predicted & reference)
+ fp = len(predicted - reference)
+ fn = len(reference - predicted)
+ p = tp / (tp + fp) if (tp + fp) > 0 else 0
+ r = tp / (tp + fn) if (tp + fn) > 0 else 0
+ f1 = 2 * p * r / (p + r) if (p + r) > 0 else 0
+ print(f' conf={threshold}: {len(candidates):>5} cands | P={p:.3f} R={r:.3f} F1={f1:.3f}')
+
+# Now test WITHOUT stable matching
+# We need to actually remove the stable matching block from the code
+# Find the exact block to remove
+stable_block_start = ' // Stable matching: for each source class, keep only the top-scoring target.'
+stable_block_end = ' // Auto-apply above threshold'
+
+if stable_block_start in original_src:
+ idx_start = original_src.index(stable_block_start)
+ idx_end = original_src.index(stable_block_end)
+ no_stable_src = original_src[:idx_start] + '\n' + original_src[idx_end:]
+
+ print('\n=== WITHOUT stable matching ===')
+
+ for name, weights in CONFIGS.items():
+ weight_str = f'[{", ".join(f"{w:.3}" for w in weights)}]'
+ patched = re.sub(
+ r'(#\[cfg\(not\(feature = "embeddings"\)\)\]\s*const DEFAULT_WEIGHTS: \[f64; 6\] = )\[[^\]]+\]',
+ f'\\g<1>{weight_str}',
+ no_stable_src
+ )
+
+ with open(ALIGN_RS, 'w') as f:
+ f.write(patched)
+
+ build = subprocess.run(
+ ['cargo', 'build', '--release'],
+ capture_output=True, text=True, timeout=300,
+ env={**os.environ, 'CARGO_TARGET_DIR': 'target'}
+ )
+ if build.returncode != 0:
+ print(f'{name}: BUILD FAILED')
+ continue
+
+ for threshold in ['0.80', '0.85']:
+ result = subprocess.run(
+ [BINARY, 'align', MOUSE, HUMAN, '--min-confidence', threshold, '--dry-run'],
+ capture_output=True, text=True, timeout=600
+ )
+ if result.returncode != 0: continue
+ data = json.loads(result.stdout)
+ candidates = data.get('candidates', [])
+ predicted = set((c['source_iri'], c['target_iri']) for c in candidates)
+ tp = len(predicted & reference)
+ fp = len(predicted - reference)
+ fn = len(reference - predicted)
+ p = tp / (tp + fp) if (tp + fp) > 0 else 0
+ r = tp / (tp + fn) if (tp + fn) > 0 else 0
+ f1 = 2 * p * r / (p + r) if (p + r) > 0 else 0
+ print(f' {name} conf={threshold}: {len(candidates):>6} cands | P={p:.3f} R={r:.3f} F1={f1:.3f}')
+else:
+ print('ERROR: Could not find stable matching block')
+
+# Restore
+with open(ALIGN_RS, 'w') as f:
+ f.write(original_src)
+
+# Rebuild with original
+subprocess.run(
+ ['cargo', 'build', '--release'],
+ capture_output=True, text=True, timeout=300,
+ env={**os.environ, 'CARGO_TARGET_DIR': 'target'}
+)
+print('\nRestored original align.rs and rebuilt')