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 LUBM performance benchmark with chart generation

FABIOTESSe6e15c5809ec
diff --git a/benchmark/reasoner/generate_lubm.py b/benchmark/reasoner/generate_lubm.py
new file mode 100755
index 00000000..4ca0379c
--- /dev/null
+++ b/benchmark/reasoner/generate_lubm.py
@@ -0,0 +1,178 @@
+#!/usr/bin/env python3
+"""Generate LUBM-style university ontology at configurable scale.
+
+Produces valid OWL Turtle with class hierarchies, object/datatype properties,
+someValuesFrom restrictions, cardinality restrictions, and disjoint classes.
+"""
+import sys
+import os
+
+
+def generate(num_axioms: int, output_path: str):
+ """Generate a university ontology with roughly num_axioms axioms."""
+ lines = []
+ lines.append("@prefix owl: <http://www.w3.org/2002/07/owl#> .")
+ lines.append("@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .")
+ lines.append("@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .")
+ lines.append("@prefix ub: <http://lubm.example.org/> .")
+ lines.append("")
+
+ # Base classes
+ base_classes = [
+ "Thing", "Person", "Student", "Faculty", "Staff",
+ "Professor", "AssociateProfessor", "AssistantProfessor", "FullProfessor",
+ "Lecturer", "GraduateStudent", "UndergraduateStudent",
+ "ResearchAssistant", "TeachingAssistant",
+ "Organization", "University", "Department", "College",
+ "Course", "GraduateCourse", "UndergraduateCourse",
+ "Publication", "Article", "Book", "TechnicalReport",
+ "ResearchGroup", "Work", "Schedule",
+ ]
+
+ hierarchy = {
+ "Person": "Thing", "Student": "Person", "Faculty": "Person", "Staff": "Person",
+ "Professor": "Faculty", "Lecturer": "Faculty",
+ "AssociateProfessor": "Professor", "AssistantProfessor": "Professor", "FullProfessor": "Professor",
+ "GraduateStudent": "Student", "UndergraduateStudent": "Student",
+ "ResearchAssistant": "GraduateStudent", "TeachingAssistant": "GraduateStudent",
+ "Organization": "Thing", "University": "Organization",
+ "Department": "Organization", "College": "Organization",
+ "Course": "Thing", "GraduateCourse": "Course", "UndergraduateCourse": "Course",
+ "Publication": "Thing", "Article": "Publication", "Book": "Publication",
+ "TechnicalReport": "Publication",
+ "ResearchGroup": "Organization", "Work": "Thing", "Schedule": "Thing",
+ }
+
+ axiom_count = 0
+
+ # Emit base classes
+ for cls in base_classes:
+ parent = hierarchy.get(cls)
+ if parent:
+ lines.append(f"ub:{cls} a owl:Class ; rdfs:subClassOf ub:{parent} ; rdfs:label \"{cls}\" .")
+ else:
+ lines.append(f"ub:{cls} a owl:Class ; rdfs:label \"{cls}\" .")
+ axiom_count += 2 # type + label (or subclass)
+
+ lines.append("")
+
+ # Object properties
+ obj_props = [
+ ("memberOf", "Person", "Organization"),
+ ("worksFor", "Faculty", "Organization"),
+ ("headOf", "Professor", "Department"),
+ ("teacherOf", "Faculty", "Course"),
+ ("takesCourse", "Student", "Course"),
+ ("advisor", "GraduateStudent", "Professor"),
+ ("publicationAuthor", "Publication", "Person"),
+ ("subOrganizationOf", "Organization", "Organization"),
+ ("researchInterest", "Faculty", "Thing"),
+ ("affiliatedOrganization", "Person", "Organization"),
+ ]
+
+ for name, domain, range_ in obj_props:
+ lines.append(f"ub:{name} a owl:ObjectProperty ;")
+ lines.append(f" rdfs:domain ub:{domain} ; rdfs:range ub:{range_} ;")
+ lines.append(f' rdfs:label "{name}" .')
+ axiom_count += 4
+
+ lines.append("")
+
+ # Datatype properties
+ dt_props = [
+ ("name", "Thing", "xsd:string"),
+ ("emailAddress", "Person", "xsd:string"),
+ ("telephone", "Person", "xsd:string"),
+ ("age", "Person", "xsd:integer"),
+ ("title", "Publication", "xsd:string"),
+ ("publicationDate", "Publication", "xsd:date"),
+ ("credits", "Course", "xsd:integer"),
+ ]
+
+ for name, domain, range_ in dt_props:
+ lines.append(f"ub:{name} a owl:DatatypeProperty ;")
+ lines.append(f" rdfs:domain ub:{domain} ; rdfs:range {range_} ;")
+ lines.append(f' rdfs:label "{name}" .')
+ axiom_count += 4
+
+ lines.append("")
+
+ # Disjoint classes
+ disjoint_pairs = [
+ ("Student", "Faculty"), ("GraduateStudent", "UndergraduateStudent"),
+ ("Professor", "Lecturer"), ("Article", "Book"),
+ ("GraduateCourse", "UndergraduateCourse"),
+ ]
+
+ for a, b in disjoint_pairs:
+ lines.append(f"[] a owl:AllDisjointClasses ; owl:members ( ub:{a} ub:{b} ) .")
+ axiom_count += 1
+
+ lines.append("")
+
+ # Generate scaled classes + restrictions to reach target axiom count
+ dept_count = 0
+ while axiom_count < num_axioms:
+ dept_count += 1
+ dept = f"Department{dept_count}"
+ lines.append(f"ub:{dept} a owl:Class ; rdfs:subClassOf ub:Department ;")
+ lines.append(f' rdfs:label "{dept}" .')
+ axiom_count += 3
+
+ # someValuesFrom restriction
+ if axiom_count < num_axioms:
+ lines.append(f"ub:{dept} rdfs:subClassOf [")
+ lines.append(f" a owl:Restriction ;")
+ lines.append(f" owl:onProperty ub:subOrganizationOf ;")
+ lines.append(f" owl:someValuesFrom ub:University")
+ lines.append(f"] .")
+ axiom_count += 1
+
+ # Cardinality restriction
+ if axiom_count < num_axioms:
+ lines.append(f"ub:{dept} rdfs:subClassOf [")
+ lines.append(f" a owl:Restriction ;")
+ lines.append(f" owl:onProperty ub:headOf ;")
+ lines.append(f" owl:minCardinality 1")
+ lines.append(f"] .")
+ axiom_count += 1
+
+ # Faculty for department
+ if axiom_count < num_axioms:
+ fac = f"FacultyOf{dept}"
+ lines.append(f"ub:{fac} a owl:Class ;")
+ lines.append(f" rdfs:subClassOf ub:Faculty ;")
+ lines.append(f' rdfs:label "{fac}" ;')
+ lines.append(f" owl:equivalentClass [")
+ lines.append(f" a owl:Restriction ;")
+ lines.append(f" owl:onProperty ub:worksFor ;")
+ lines.append(f" owl:hasValue ub:{dept}")
+ lines.append(f" ] .")
+ axiom_count += 4
+
+ # Course for department
+ if axiom_count < num_axioms:
+ crs = f"CourseOf{dept}"
+ lines.append(f"ub:{crs} a owl:Class ;")
+ lines.append(f" rdfs:subClassOf ub:Course ;")
+ lines.append(f' rdfs:label "{crs}" .')
+ axiom_count += 3
+
+ lines.append("")
+
+ with open(output_path, "w") as f:
+ f.write("\n".join(lines))
+
+ print(f"Generated {output_path}: ~{axiom_count} axioms, {dept_count} departments")
+
+
+if __name__ == "__main__":
+ output_dir = os.path.join(os.path.dirname(__file__), "results")
+ os.makedirs(output_dir, exist_ok=True)
+
+ sizes = [1000, 5000, 10000, 50000]
+ if len(sys.argv) > 1:
+ sizes = [int(s) for s in sys.argv[1:]]
+
+ for size in sizes:
+ generate(size, os.path.join(output_dir, f"lubm_{size}.owl"))
diff --git a/benchmark/reasoner/plot_results.py b/benchmark/reasoner/plot_results.py
new file mode 100755
index 00000000..e44c1b7a
--- /dev/null
+++ b/benchmark/reasoner/plot_results.py
@@ -0,0 +1,63 @@
+#!/usr/bin/env python3
+"""Plot LUBM benchmark results as comparison chart."""
+import json
+import os
+import sys
+
+try:
+ import matplotlib.pyplot as plt
+ import matplotlib
+ matplotlib.use("Agg")
+except ImportError:
+ print("matplotlib not installed — run: pip install matplotlib")
+ sys.exit(1)
+
+
+def main():
+ results_dir = os.path.join(os.path.dirname(__file__), "results")
+ results_file = os.path.join(results_dir, "lubm_results.json")
+
+ if not os.path.exists(results_file):
+ print(f"No results file found at {results_file}")
+ print("Run run_lubm_performance.sh first.")
+ sys.exit(1)
+
+ with open(results_file) as f:
+ data = json.load(f)
+
+ sizes = [d["size"] for d in data]
+ oo_times = [d["oo_ms"] for d in data]
+ hermit_times = [d.get("hermit_ms") for d in data]
+ pellet_times = [d.get("pellet_ms") for d in data]
+
+ fig, ax = plt.subplots(figsize=(10, 6))
+
+ x = range(len(sizes))
+ width = 0.25
+
+ ax.bar([i - width for i in x], oo_times, width, label="Open Ontologies", color="#2563eb")
+
+ if any(t is not None and t != "null" for t in hermit_times):
+ ht = [t if t is not None and t != "null" else 0 for t in hermit_times]
+ ax.bar(x, ht, width, label="HermiT", color="#dc2626")
+
+ if any(t is not None and t != "null" for t in pellet_times):
+ pt = [t if t is not None and t != "null" else 0 for t in pellet_times]
+ ax.bar([i + width for i in x], pt, width, label="Pellet", color="#16a34a")
+
+ ax.set_xlabel("Ontology Size (axioms)")
+ ax.set_ylabel("Classification Time (ms)")
+ ax.set_title("LUBM Performance: Open Ontologies vs Java Reasoners")
+ ax.set_xticks(x)
+ ax.set_xticklabels([f"{s:,}" for s in sizes])
+ ax.legend()
+ ax.grid(axis="y", alpha=0.3)
+
+ output_path = os.path.join(results_dir, "lubm_chart.png")
+ plt.tight_layout()
+ plt.savefig(output_path, dpi=150)
+ print(f"Chart saved to {output_path}")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/benchmark/reasoner/run_lubm_performance.sh b/benchmark/reasoner/run_lubm_performance.sh
new file mode 100755
index 00000000..c76f1e77
--- /dev/null
+++ b/benchmark/reasoner/run_lubm_performance.sh
@@ -0,0 +1,81 @@
+#!/bin/bash
+set -e
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+OO_BIN="${OO_BIN:-open-ontologies}"
+RESULTS_DIR="$SCRIPT_DIR/results"
+SIZES="1000 5000 10000 50000"
+
+mkdir -p "$RESULTS_DIR"
+
+echo "=== LUBM Performance Benchmark ==="
+echo ""
+
+# 1. Generate ontologies at each scale
+echo "Generating LUBM ontologies..."
+python3 "$SCRIPT_DIR/generate_lubm.py" $SIZES
+echo ""
+
+# 2. Run benchmarks
+RESULTS_FILE="$RESULTS_DIR/lubm_results.json"
+echo "[" > "$RESULTS_FILE"
+FIRST=true
+
+for SIZE in $SIZES; do
+ OWL_FILE="$RESULTS_DIR/lubm_${SIZE}.owl"
+ if [ ! -f "$OWL_FILE" ]; then
+ echo "SKIP: $OWL_FILE not found"
+ continue
+ fi
+
+ echo "--- Size: $SIZE axioms ---"
+
+ # Open Ontologies
+ START_MS=$(python3 -c "import time; print(int(time.time()*1000))")
+ $OO_BIN load "$OWL_FILE" > /dev/null 2>&1
+ OO_OUT=$($OO_BIN reason --profile owl-dl 2>/dev/null || echo '{"error":"failed"}')
+ END_MS=$(python3 -c "import time; print(int(time.time()*1000))")
+ OO_MS=$((END_MS - START_MS))
+ echo " Open Ontologies: ${OO_MS}ms"
+
+ # Java reasoners (if available)
+ HERMIT_MS="null"
+ PELLET_MS="null"
+ if ls "$SCRIPT_DIR/lib/"*.jar 1>/dev/null 2>&1; then
+ START_MS=$(python3 -c "import time; print(int(time.time()*1000))")
+ java -cp "$SCRIPT_DIR:$SCRIPT_DIR/lib/*" JavaReasoner hermit "$OWL_FILE" "$RESULTS_DIR/hermit_lubm_${SIZE}.json" 2>/dev/null || true
+ END_MS=$(python3 -c "import time; print(int(time.time()*1000))")
+ HERMIT_MS=$((END_MS - START_MS))
+ echo " HermiT: ${HERMIT_MS}ms"
+
+ START_MS=$(python3 -c "import time; print(int(time.time()*1000))")
+ java -cp "$SCRIPT_DIR:$SCRIPT_DIR/lib/*" JavaReasoner pellet "$OWL_FILE" "$RESULTS_DIR/pellet_lubm_${SIZE}.json" 2>/dev/null || true
+ END_MS=$(python3 -c "import time; print(int(time.time()*1000))")
+ PELLET_MS=$((END_MS - START_MS))
+ echo " Pellet: ${PELLET_MS}ms"
+ fi
+
+ if [ "$FIRST" = true ]; then
+ FIRST=false
+ else
+ echo "," >> "$RESULTS_FILE"
+ fi
+
+ cat >> "$RESULTS_FILE" <<ENTRY
+ {"size": $SIZE, "oo_ms": $OO_MS, "hermit_ms": $HERMIT_MS, "pellet_ms": $PELLET_MS}
+ENTRY
+
+ echo ""
+done
+
+echo "]" >> "$RESULTS_FILE"
+
+echo "Results saved to $RESULTS_FILE"
+echo ""
+
+# 3. Plot if matplotlib available
+if python3 -c "import matplotlib" 2>/dev/null; then
+ echo "Generating chart..."
+ python3 "$SCRIPT_DIR/plot_results.py"
+else
+ echo "SKIP: matplotlib not installed — run 'pip install matplotlib' to generate charts"
+fi