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(case-studies): insurance register ontology (IRO) rules on the lite engine

FABIOTESS7dee644340e2
diff --git a/README.md b/README.md
index a34f199d..6b451778 100644
--- a/README.md
+++ b/README.md
@@ -331,6 +331,8 @@ The benchmarks below are not a feature tour. Each one exists to answer a specifi
| **RQ5** | Does a closed-world vocabulary check catch generated terms that open-world SHACL validation silently accepts? | [`onto-correctness-bench`](case-studies/onto-correctness-bench/): 3 vocabularies, 418 fabricated terms, 300 graphs | **Yes, completely.** SHACL returned `conforms=true` on **300/300** graphs containing a fabricated term. The closed-world gate flagged **300/300**, with zero false positives on clean graphs. Open-world semantics treat an undeclared predicate as merely unknown, so SHACL is structurally unable to see it. |
| **RQ6** | Can the SHACL-SPARQL governance rules an ontology ships actually be executed as written at national scale, or does the reference store force a workaround? | [`investment-fund-ontology`](case-studies/investment-fund-ontology/): 1.29M-triple US fund universe, 4 layer-3 rules, rdflib 7.6.0 A/B | **Store-specific.** rdflib finishes the anti-join (0.1s) and nested aggregate (0.8s) but times out (>300s) on both multi-way self-joins — exactly the cross-source reconciliation rules the ontology exists for. This repo's Oxigraph engine runs load + all four rules, unmodified, in 2.1s, reproducing the reference pipeline's published counts (73 / 0 / 214 / 2,148) exactly. The shapes also forced two validator fixes here: `sh:inversePath` support and `sh:severity` reporting. |
+| **RQ7** | When the graph is register-scale (276k triples) rather than fund-universe-scale (1.29M), does the reference store still force the set-based workaround, and do the rule counts survive entity resolution? | [`insurance-register-ontology`](case-studies/insurance-register-ontology/): 276,683-triple EEA insurance register, 6 layer-3 rules, rdflib 7.6.0 A/B | **The workaround becomes speed, not survival.** At this scale rdflib completes all six rules (133.2s total, 97s of it in one double anti-join) against 2s to 9s for the Oxigraph engine; nothing times out. Counts match the reference pipeline exactly on R1-R4 (643 / 4 / 118 / 42). R5 falls from 227 to 20 and R6 rises from 283 to 291 because the graph runs the same rule text after entity resolution, which absorbs the legitimate branch shares and attributes 8 more zombie passports via the LEI join; both differences were verified set-based. The shapes forced two more validator fixes: `sh:pattern` and `sh:hasValue`. |
+
RQ2 and RQ4 are the ones worth reading if you are deciding whether to trust this repo. Both are negative results about work done here.
## Benchmarks
diff --git a/case-studies/insurance-register-ontology/README.md b/case-studies/insurance-register-ontology/README.md
new file mode 100644
index 00000000..d9817292
--- /dev/null
+++ b/case-studies/insurance-register-ontology/README.md
@@ -0,0 +1,63 @@
+# Case study: the Insurance Register Ontology's governance rules, executed as written
+
+**Ontology under test:** the [Insurance Register Ontology (IRO)](https://github.com/fabio-rovai/insurance-register-ontology), an open OWL 2 ontology + SKOS registries + SHACL governance layer for the authorization, cross-border operation, and identifier fabric of EEA insurance and reinsurance undertakings, built against the full EIOPA Register of Insurance Undertakings joined with same-day GLEIF API records: a 276,683-triple graph (14 Aug 2026 build). The four Turtle files here are vendored from IRO at that state (same author, CC BY 4.0). Background article: [gov.tesseract.academy/research/insurance-register-ontology](https://gov.tesseract.academy/research/insurance-register-ontology).
+
+**The question this case study answers:** IRO ships its six layer-3 business rules (R1-R6) as standard SHACL-SPARQL "for platforms that execute it natively", but its reference pipeline runs them set-based in Python over the source CSVs. The sibling [IFO case study](../investment-fund-ontology/) established that rdflib times out on multi-way self-joins at 1.29M triples. The insurance register is 4.7 times smaller. So two questions: do the six rules run *as written* on Open Ontologies' Oxigraph-backed engine and reproduce the pipeline's published findings, and at register scale is the set-based workaround still forced, or merely faster?
+
+**Answer: all six rules run as written and the counts agree, and the scale finding is honest rather than dramatic.** At 276,683 triples rdflib completes every rule; nothing times out. What remains is a two-orders-of-magnitude gap on the worst rule (97 seconds versus well under a second for R1's double anti-join) and roughly 133 seconds versus single-digit seconds for the whole suite. Register-scale graphs sit inside the zone where rdflib survives; IFO's 1.29M-triple fund universe is where it stops. The workaround is about scale, not about SPARQL dialect: the identical query text produced identical counts on both engines.
+
+## The A/B, measured on the same graph, same machine, same SPARQL text
+
+Full 276,683-triple `iro_graph.ttl` (IRO build of 14 Aug 2026), Apple silicon laptop carrying unrelated concurrent load (which is why engine wall clock is quoted as a range). rdflib 7.6.0 (the library IRO's pipeline uses) vs this repo's `open-ontologies` binary (Oxigraph 0.5). Every number below was measured for this case study; nothing is copied from the IFO table.
+
+| Step | rdflib 7.6.0 | Open Ontologies |
+|---|---|---|
+| Load 276,683 triples | 5.6s | 0.8s |
+| R1: active undertaking with no LEI (double `FILTER NOT EXISTS`) | 97.0s, 643 findings | 643 findings |
+| R2: LEI fails ISO 7064 check digits | 0.0s, 4 | 4 |
+| R3: active undertaking, LEI LAPSED in GLEIF | 7.3s, 118 | 118 |
+| R4: active undertaking, GLEIF entity INACTIVE | 22.4s, 42 | 42 |
+| R5: LEI shared by more than one entity node (self-join) | 0.2s, 20 | 20 |
+| R6: open operation for an ended registration (zombie passport) | 0.8s, 291 | 291 |
+| **Load + all six rules, one process** | **133.2s** | **2s to 9s across repeated runs** |
+
+Three things worth being precise about:
+
+1. **R1-R4 now have three independent executors agreeing exactly.** IRO's set-based Python pipeline published 643 / 4 / 118 / 42 in its governance report for this build; rdflib's SPARQL engine and Oxigraph both reproduce those counts from the graph. Same constraints, three executors, identical results. These figures are pinned to the 14 Aug 2026 EIOPA export and same-day GLEIF harvest; both are living systems, so a rebuilt graph will differ.
+2. **R5 and R6 differ from the published CSV-level numbers, and the difference is entity resolution, not error.** The pipeline's R5 counted 227 LEIs filed for more than one register key; the graph rule finds 20 LEI nodes identifying more than one entity node, because the build deliberately joins branch rows onto their home undertaking (by register key first, then by unambiguous LEI), absorbing the 207 legitimate branch shares before the rule ever runs. All 3 hard entity collapses the report singled out (including the SCOR France / SCOR Ireland pair) are among the 20; this was checked by listing the 20 values. R6 runs the other way: the graph finds 291 zombie passports against the report's 283, and replicating both join disciplines set-based over the same CSV confirms the 8 extra are open operations whose own register key has no domestic row at all, so only the LEI join can attribute them to their ended home registration. The same rule text measures a sharper universe after entity resolution: fewer false shares, more true zombies.
+3. **rdflib's pain point here is the anti-join stack, not the self-join.** R5's self-join over 3,630 LEI nodes takes 0.2s; what costs 97s is R1's double `FILTER NOT EXISTS` over undertakings and registrations, with R4 (22.4s) and R3 (7.3s) close behind. At IFO's 1.29M triples the killer was the multi-way self-join. The lesson is that rdflib's failure mode depends on where the graph is big, and the only executor that was indifferent to the question in both case studies is the Oxigraph engine.
+
+## What the demo runs
+
+```
+./run-demo.sh
+```
+
+**Part 1, self-contained** (vendored files plus a synthetic subgraph, no data download, no EIOPA or GLEIF data): loads `iro-core.ttl` + `operation-modes.ttl` + `iro-example-synthetic.ttl`, then
+
+- reads the SKOS registries as data: the five operation modes grounded in Directive 2009/138/EC with the register's own notations, and the identifier schemes grouped by declared scope (the LEI entity-scoped, the NCA code authority-scoped), which is IRO's load-bearing design idea;
+- executes all six layer-3 rules as plain SPARQL against engineered defects with known counts (1 / 2 / 1 / 1 / 1 / 1), each defect a miniature of a defect class the real build surfaced: the letter-O-for-zero LEI transposition, the 19-character truncated LEI, two reinsurers filed under one LEI, the passport outliving its authorization, and the active undertaking with no LEI at all;
+- counts identifier assertions per source system (provenance as a query);
+- validates the layer-1/2 shapes: 5 findings, 4 Violation and 1 Warning, exercising `sh:pattern`, `sh:hasValue`, `sh:minCount`, `sh:severity`, and the `sh:inversePath` registration shape.
+
+The synthetic subgraph is exactly that and says so in its header: every undertaking, authority, and identifier value in `iro-example-synthetic.ttl` is invented. The "valid" LEI values use a deliberately fake `9999` prefix but carry real ISO 7064 MOD 97-10 check digits, generated and verified with the source repository's own `pipeline/checksums.py`; the two "impossible" values fail that arithmetic on purpose. The letter-O value passes the 20-character syntax pattern (a letter O is alphanumeric) and fails only the checksum, which is why IRO keeps arithmetic in code and policy in shapes.
+
+**Part 2, full EEA register** (runs when `iro_graph.ttl` is present, else prints how to build it): loads the 276,683-triple graph and executes the six rules as plain SPARQL, printing counts next to the pipeline's published figures, then closes with the passporting-fabric query: top exporters of open freedom-of-services operations DE 2,794, IE 1,658, FR 1,280, LU 1,166, NL 1,140, MT 915, matching the governance report exactly.
+
+To build the full graph: clone IRO, run `pipeline/fetch_eiopa.py`, `pipeline/harvest_gleif.py`, and `pipeline/build_graph.py`, and point `IRO_GRAPH` at `data/build/iro_graph.ttl` (default location is `~/projects/insurance-register-ontology/data/build/iro_graph.ttl`). **No EIOPA register data is redistributed by this case study or this repository**; you fetch the export from EIOPA yourself, exactly as the source repository does. GLEIF records are CC0, but none are vendored here either.
+
+## What this case study forced the validator to fix
+
+IRO's layer-2 LEI shape is precisely a `sh:pattern` + `sh:hasValue` pair: 20-character ISO 17442 syntax, and the recorded checksum state must be `true`. This repo's SHACL validator executed neither constraint before this case study; both property shapes were silently skipped, so the shapes file would have reported a clean pass over data containing a 19-character LEI. Both are now implemented as SPARQL translations (`!REGEX` over the string form; `FILTER NOT EXISTS` for the required term), with regression tests in `tests/shacl_test.rs` covering the truncated-LEI and false-checksum cases. The demo's Part 1 SHACL run is the acceptance test: 5 findings with the right constraints and severities, including the Warning-graded unregistered undertaking via `sh:inversePath`.
+
+## Files
+
+| File | Vendored from IRO | Role |
+|---|---|---|
+| `iro-core.ttl` | `ontology/iro-core.ttl` | Core OWL: `InsuranceUndertaking`, reified `Registration` and `CrossBorderOperation`, `RegisteredPresence`, reified identifier assertions with GLEIF reconciliation facets |
+| `operation-modes.ttl` | `skos/operation-modes.ttl` | SKOS registries: 5 operation modes grounded in Directive 2009/138/EC, identifier schemes with scope levels, source systems |
+| `iro-shapes.ttl` | `shapes/iro-shapes.ttl` | Layer-1/2 SHACL: syntax, checksum policy, structure |
+| `iro-rules.ttl` | `shapes/iro-rules.ttl` | Layer-3 SHACL-SPARQL business rules R1-R6 (the `sh:select` bodies Part 2 executes) |
+| `iro-example-synthetic.ttl` | written for this case study | Synthetic example subgraph, engineered defects with known counts; contains no EIOPA or GLEIF data |
+
+Vendored files are CC BY 4.0 (per IRO's LICENSE; ontology, SKOS registries, and shapes carry that licence, pipeline code is MIT). Attribution: [github.com/fabio-rovai/insurance-register-ontology](https://github.com/fabio-rovai/insurance-register-ontology) and the write-up at [gov.tesseract.academy/research/insurance-register-ontology](https://gov.tesseract.academy/research/insurance-register-ontology).
diff --git a/case-studies/insurance-register-ontology/iro-core.ttl b/case-studies/insurance-register-ontology/iro-core.ttl
new file mode 100644
index 00000000..ff423f68
--- /dev/null
+++ b/case-studies/insurance-register-ontology/iro-core.ttl
@@ -0,0 +1,142 @@
+@prefix iro: <https://gov.tesseract.academy/def/insurance#> .
+@prefix irosch: <https://gov.tesseract.academy/def/insurance/scheme#> .
+@prefix owl: <http://www.w3.org/2002/07/owl#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
+@prefix dcterms: <http://purl.org/dc/terms/> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+<https://gov.tesseract.academy/def/insurance>
+ a owl:Ontology ;
+ dcterms:title "Insurance Register Ontology (IRO)"@en ;
+ dcterms:creator "Fabio Rovai" ;
+ dcterms:license <https://creativecommons.org/licenses/by/4.0/> ;
+ rdfs:comment "An open OWL 2 ontology for the authorization, cross-border operation, and identifier fabric of insurance and reinsurance undertakings. First instantiated against the EIOPA Register of Insurance Undertakings joined with GLEIF LEI records. Identifiers are reified assertions carrying scheme, source system, and computed validation state, the same design stance as the Investment Fund Ontology (https://github.com/fabio-rovai/investment-fund-ontology), of which this is the second vertical instantiation."@en .
+
+#################################################################
+# Core entities
+#################################################################
+
+iro:InsuranceUndertaking a owl:Class ;
+ rdfs:label "insurance or reinsurance undertaking"@en ;
+ rdfs:comment "An undertaking authorised to pursue insurance or reinsurance activity (Solvency II, Directive 2009/138/EC, Article 13(1)-(4)). The EIOPA register does not distinguish direct insurers from pure reinsurers in its public export, so this class deliberately spans both; a subclass assertion requires evidence the export does not carry."@en .
+
+iro:SupervisoryAuthority a owl:Class ;
+ rdfs:label "national competent authority"@en ;
+ rdfs:comment "The national supervisory authority (NCA) responsible for the home authorization of an undertaking."@en .
+
+iro:Country a owl:Class ;
+ rdfs:label "country"@en .
+
+#################################################################
+# Authorization and operation, reified, because both are
+# relations with their own lifecycle, not edges.
+#################################################################
+
+iro:Registration a owl:Class ;
+ rdfs:label "home registration"@en ;
+ rdfs:comment "The home-state authorization of an undertaking by its NCA: who authorised whom, where, from when to when. Reified so that the registration's own start and end dates, and the source system asserting it, are first-class."@en .
+
+iro:CrossBorderOperation a owl:Class ;
+ rdfs:label "cross-border operation"@en ;
+ rdfs:comment "One undertaking operating in one host country under one operation mode (freedom of services, EEA branch, third-country branch...). One row of the EU passporting fabric, reified with its own dates."@en .
+
+iro:registrationOf a owl:ObjectProperty ;
+ rdfs:domain iro:Registration ; rdfs:range iro:InsuranceUndertaking ;
+ rdfs:label "registration of"@en .
+
+iro:registeredBy a owl:ObjectProperty ;
+ rdfs:domain iro:Registration ; rdfs:range iro:SupervisoryAuthority ;
+ rdfs:label "registered by"@en .
+
+iro:homeCountry a owl:ObjectProperty ;
+ rdfs:domain iro:InsuranceUndertaking ; rdfs:range iro:Country ;
+ rdfs:label "home country"@en .
+
+iro:operationOf a owl:ObjectProperty ;
+ rdfs:domain iro:CrossBorderOperation ; rdfs:range iro:InsuranceUndertaking ;
+ rdfs:label "operation of"@en .
+
+iro:hostCountry a owl:ObjectProperty ;
+ rdfs:domain iro:CrossBorderOperation ; rdfs:range iro:Country ;
+ rdfs:label "host country"@en .
+
+iro:operationMode a owl:ObjectProperty ;
+ rdfs:domain iro:CrossBorderOperation ; rdfs:range skos:Concept ;
+ rdfs:label "operation mode"@en ;
+ rdfs:comment "Points into the SKOS registry of operation modes (domestic, EEA freedom of services, EEA branch, third-country branch, FPS for EEA branches)."@en .
+
+iro:registrationStart a owl:DatatypeProperty ;
+ rdfs:range xsd:date ; rdfs:label "registration start date"@en .
+iro:registrationEnd a owl:DatatypeProperty ;
+ rdfs:range xsd:date ; rdfs:label "registration end date"@en .
+iro:operationStart a owl:DatatypeProperty ;
+ rdfs:range xsd:date ; rdfs:label "operation start date"@en .
+iro:operationEnd a owl:DatatypeProperty ;
+ rdfs:range xsd:date ; rdfs:label "operation end date"@en .
+
+iro:legalName a owl:DatatypeProperty ;
+ rdfs:label "legal name"@en .
+iro:internationalName a owl:DatatypeProperty ;
+ rdfs:label "international name"@en .
+
+#################################################################
+# The identifier fabric, reified assertions, as in IFO.
+# An Identifier here is an identifier ASSERTION: a value, in a
+# scheme, made by a source system, with a computed validation
+# state. Cross-system disagreement becomes a query.
+#################################################################
+
+iro:Identifier a owl:Class ;
+ rdfs:label "identifier assertion"@en ;
+ rdfs:comment "A reified identifier assertion: scheme + value + asserting source system + computed checksum state. Deliberately NOT identifier-as-designator: two systems asserting different LEIs for one undertaking is representable, queryable state, not an error in the model."@en .
+
+iro:LEI a owl:Class ; rdfs:subClassOf iro:Identifier ;
+ rdfs:label "LEI assertion"@en .
+iro:NationalIdentificationCode a owl:Class ; rdfs:subClassOf iro:Identifier ;
+ rdfs:label "national identification code assertion"@en ;
+ rdfs:comment "The NCA-scoped identification code the EIOPA register carries per undertaking. Uniqueness is scoped to the issuing NCA, not global, which is precisely the kind of scope fact the scheme registry declares as data."@en .
+
+iro:identifiedBy a owl:ObjectProperty ;
+ rdfs:range iro:Identifier ; rdfs:label "identified by"@en .
+iro:identifies a owl:ObjectProperty ;
+ owl:inverseOf iro:identifiedBy ;
+ rdfs:domain iro:Identifier ; rdfs:label "identifies"@en .
+iro:identifierValue a owl:DatatypeProperty ;
+ rdfs:domain iro:Identifier ; rdfs:label "identifier value"@en .
+iro:identifierScheme a owl:ObjectProperty ;
+ rdfs:domain iro:Identifier ; rdfs:range skos:Concept ;
+ rdfs:label "identifier scheme"@en .
+iro:sourceSystem a owl:ObjectProperty ;
+ rdfs:domain iro:Identifier ; rdfs:label "source system"@en .
+iro:checksumValid a owl:DatatypeProperty ;
+ rdfs:domain iro:Identifier ; rdfs:range xsd:boolean ;
+ rdfs:label "checksum valid"@en ;
+ rdfs:comment "Computed by the pipeline (ISO 7064 MOD 97-10 for LEI), asserted into the graph; shapes require the recorded result. Arithmetic in code, policy in shapes."@en .
+
+#################################################################
+# GLEIF reconciliation facets, the cross-source layer.
+#################################################################
+
+iro:gleifEntityStatus a owl:DatatypeProperty ;
+ rdfs:domain iro:LEI ;
+ rdfs:label "GLEIF entity status"@en ;
+ rdfs:comment "ACTIVE or INACTIVE per the GLEIF record for this LEI at harvest time."@en .
+
+iro:gleifRegistrationStatus a owl:DatatypeProperty ;
+ rdfs:domain iro:LEI ;
+ rdfs:label "GLEIF registration status"@en ;
+ rdfs:comment "ISSUED, LAPSED, RETIRED, MERGED, ANNULLED... per GLEIF at harvest time. A LAPSED LEI is still a valid identifier whose annual renewal was not made."@en .
+
+iro:gleifLegalName a owl:DatatypeProperty ;
+ rdfs:domain iro:LEI ;
+ rdfs:label "GLEIF legal name"@en .
+
+iro:inGleif a owl:DatatypeProperty ;
+ rdfs:domain iro:LEI ; rdfs:range xsd:boolean ;
+ rdfs:label "present in GLEIF"@en ;
+ rdfs:comment "Whether the harvested GLEIF API returned any record for this LEI value."@en .
+
+iro:RegisteredPresence a owl:Class ;
+ rdfs:label "registered presence"@en ;
+ rdfs:comment "A registered market presence that has no home-registration row in this register and could not be joined to a home undertaking by key or unambiguous LEI: third-country branches by construction, plus branch rows the register itself does not key back to their head office. Kept distinct rather than silently merged, the join failure is data, not noise."@en .
diff --git a/case-studies/insurance-register-ontology/iro-example-synthetic.ttl b/case-studies/insurance-register-ontology/iro-example-synthetic.ttl
new file mode 100644
index 00000000..c4268976
--- /dev/null
+++ b/case-studies/insurance-register-ontology/iro-example-synthetic.ttl
@@ -0,0 +1,366 @@
+@prefix iro: <https://gov.tesseract.academy/def/insurance#> .
+@prefix irosch: <https://gov.tesseract.academy/def/insurance/scheme#> .
+@prefix exd: <https://gov.tesseract.academy/id/insurance-example#> .
+@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+#################################################################
+# SYNTHETIC example subgraph for the Insurance Register Ontology
+# (IRO) case study. Every undertaking, authority, registration,
+# operation, and identifier value in this file is INVENTED. This
+# is NOT EIOPA data and NOT GLEIF data; no row of any real
+# register appears here. The EIOPA register export is not
+# redistributed by this repository.
+#
+# The file is engineered so that each of IRO's six layer-3 rules
+# (R1-R6 in iro-rules.ttl) fires a known number of times, and the
+# layer-1/2 shapes (iro-shapes.ttl) find a known set of defects.
+# Each defect reproduces, in miniature, a defect class the real
+# 14 Aug 2026 EIOPA/GLEIF build actually surfaced (letter-O
+# transposition, 19-character truncation, shared LEI, zombie
+# passport...).
+#
+# All "valid" LEI values below use the reserved-looking synthetic
+# prefix 9999.. and carry REAL ISO 7064 MOD 97-10 check digits,
+# verified against the source repository's pipeline/checksums.py.
+# The two "impossible" values fail the same arithmetic on purpose.
+#################################################################
+
+#################################################################
+# Countries and (synthetic) supervisory authorities
+#################################################################
+
+exd:country-DE a iro:Country ; rdfs:label "Germany" .
+exd:country-GR a iro:Country ; rdfs:label "Greece" .
+exd:country-IE a iro:Country ; rdfs:label "Ireland" .
+exd:country-AT a iro:Country ; rdfs:label "Austria" .
+exd:country-FR a iro:Country ; rdfs:label "France" .
+exd:country-SE a iro:Country ; rdfs:label "Sweden" .
+exd:country-FI a iro:Country ; rdfs:label "Finland" .
+exd:country-IT a iro:Country ; rdfs:label "Italy" .
+exd:country-ES a iro:Country ; rdfs:label "Spain" .
+exd:country-IS a iro:Country ; rdfs:label "Iceland" .
+
+exd:nca-DE a iro:SupervisoryAuthority ; iro:legalName "Example Prudential Supervisory Authority (DE)" .
+exd:nca-GR a iro:SupervisoryAuthority ; iro:legalName "Example Insurance Supervisory Authority (GR)" .
+exd:nca-IE a iro:SupervisoryAuthority ; iro:legalName "Example Central Authority (IE)" .
+exd:nca-AT a iro:SupervisoryAuthority ; iro:legalName "Example Financial Market Authority (AT)" .
+exd:nca-FR a iro:SupervisoryAuthority ; iro:legalName "Example Prudential Authority (FR)" .
+exd:nca-SE a iro:SupervisoryAuthority ; iro:legalName "Example Financial Inspectorate (SE)" .
+
+# Synthetic source systems, declared as such so that the
+# provenance queries have honest answers. These stand in for the
+# roles EIOPA-DATINS and GLEIF-API play in the real build.
+exd:ExampleRegister a skos:Concept ;
+ skos:prefLabel "synthetic example register (not EIOPA data)"@en .
+exd:ExampleLEICheck a skos:Concept ;
+ skos:prefLabel "synthetic LEI reconciliation source (not GLEIF data)"@en .
+
+#################################################################
+# U1 Aquila Insurance SE (DE): the clean record. Active home
+# registration, one valid LEI, reconciliation source agrees,
+# two open freedom-of-services passports.
+#################################################################
+
+exd:u-aquila a iro:InsuranceUndertaking ;
+ iro:legalName "Aquila Insurance SE" ;
+ iro:homeCountry exd:country-DE ;
+ iro:identifiedBy exd:lei-aquila , exd:nat-aquila .
+
+exd:reg-aquila a iro:Registration ;
+ iro:registrationOf exd:u-aquila ;
+ iro:registeredBy exd:nca-DE ;
+ iro:registrationStart "2001-03-15"^^xsd:date .
+
+exd:lei-aquila a iro:Identifier , iro:LEI ;
+ iro:identifierValue "999900AQUILAINSDE008" ;
+ iro:identifierScheme irosch:LEI ;
+ iro:sourceSystem exd:ExampleRegister ;
+ iro:checksumValid true ;
+ iro:inGleif true ;
+ iro:gleifRegistrationStatus "ISSUED" ;
+ iro:gleifEntityStatus "ACTIVE" ;
+ iro:gleifLegalName "Aquila Insurance SE" ;
+ iro:identifies exd:u-aquila .
+
+exd:nat-aquila a iro:Identifier , iro:NationalIdentificationCode ;
+ iro:identifierValue "DE-EX-1001" ;
+ iro:identifierScheme irosch:NationalIdentificationCode ;
+ iro:sourceSystem exd:ExampleRegister ;
+ iro:identifies exd:u-aquila .
+
+exd:op-aquila-fr a iro:CrossBorderOperation ;
+ iro:operationOf exd:u-aquila ;
+ iro:hostCountry exd:country-FR ;
+ iro:operationMode irosch:EEAFreedomOfServices ;
+ iro:operationStart "2015-01-01"^^xsd:date .
+
+exd:op-aquila-it a iro:CrossBorderOperation ;
+ iro:operationOf exd:u-aquila ;
+ iro:hostCountry exd:country-IT ;
+ iro:operationMode irosch:EEAFreedomOfServices ;
+ iro:operationStart "2016-07-01"^^xsd:date .
+
+#################################################################
+# U2 Boreas Re AG (DE): active registration, NO LEI assertion
+# from any source system. Fires R1 (the 19.5% finding class).
+#################################################################
+
+exd:u-boreas a iro:InsuranceUndertaking ;
+ iro:legalName "Boreas Re AG" ;
+ iro:homeCountry exd:country-DE ;
+ iro:identifiedBy exd:nat-boreas .
+
+exd:reg-boreas a iro:Registration ;
+ iro:registrationOf exd:u-boreas ;
+ iro:registeredBy exd:nca-DE ;
+ iro:registrationStart "1998-11-02"^^xsd:date .
+
+exd:nat-boreas a iro:Identifier , iro:NationalIdentificationCode ;
+ iro:identifierValue "DE-EX-1002" ;
+ iro:identifierScheme irosch:NationalIdentificationCode ;
+ iro:sourceSystem exd:ExampleRegister ;
+ iro:identifies exd:u-boreas .
+
+#################################################################
+# U3 Cyclades Insurance A.E. (GR): the letter-O transposition.
+# The filed value has a letter O where the checksum-valid form
+# 9999000CYCLADESGR047 has a zero, so ISO 7064 fails and the
+# recorded checksum state is false. Fires R2 and the layer-2
+# hasValue policy; the SYNTAX pattern still passes, because a
+# letter O is alphanumeric, which is exactly why checksum
+# arithmetic exists. Mirrors LEI 5493O00MN7XN3BBKCE67 filed in
+# the real register.
+#################################################################
+
+exd:u-cyclades a iro:InsuranceUndertaking ;
+ iro:legalName "Cyclades Insurance A.E." ;
+ iro:homeCountry exd:country-GR ;
+ iro:identifiedBy exd:lei-cyclades , exd:nat-cyclades .
+
+exd:reg-cyclades a iro:Registration ;
+ iro:registrationOf exd:u-cyclades ;
+ iro:registeredBy exd:nca-GR ;
+ iro:registrationStart "2005-04-20"^^xsd:date .
+
+exd:lei-cyclades a iro:Identifier , iro:LEI ;
+ iro:identifierValue "9999O00CYCLADESGR047" ;
+ iro:identifierScheme irosch:LEI ;
+ iro:sourceSystem exd:ExampleRegister ;
+ iro:checksumValid false ;
+ iro:inGleif false ;
+ iro:identifies exd:u-cyclades .
+
+exd:nat-cyclades a iro:Identifier , iro:NationalIdentificationCode ;
+ iro:identifierValue "GR-EX-2001" ;
+ iro:identifierScheme irosch:NationalIdentificationCode ;
+ iro:sourceSystem exd:ExampleRegister ;
+ iro:identifies exd:u-cyclades .
+
+#################################################################
+# U4 Danu Life dac (IE): authorised and writing business, but the
+# LEI's annual renewal was not made, so the reconciliation source
+# reports LAPSED. Fires R3.
+#################################################################
+
+exd:u-danu a iro:InsuranceUndertaking ;
+ iro:legalName "Danu Life dac" ;
+ iro:homeCountry exd:country-IE ;
+ iro:identifiedBy exd:lei-danu .
+
+exd:reg-danu a iro:Registration ;
+ iro:registrationOf exd:u-danu ;
+ iro:registeredBy exd:nca-IE ;
+ iro:registrationStart "2010-09-01"^^xsd:date .
+
+exd:lei-danu a iro:Identifier , iro:LEI ;
+ iro:identifierValue "999900DANULIFEIE0094" ;
+ iro:identifierScheme irosch:LEI ;
+ iro:sourceSystem exd:ExampleRegister ;
+ iro:checksumValid true ;
+ iro:inGleif true ;
+ iro:gleifRegistrationStatus "LAPSED" ;
+ iro:gleifEntityStatus "ACTIVE" ;
+ iro:gleifLegalName "Danu Life Designated Activity Company" ;
+ iro:identifies exd:u-danu .
+
+exd:op-danu-de a iro:CrossBorderOperation ;
+ iro:operationOf exd:u-danu ;
+ iro:hostCountry exd:country-DE ;
+ iro:operationMode irosch:EEAFreedomOfServices ;
+ iro:operationStart "2018-05-01"^^xsd:date .
+
+#################################################################
+# U5 Eir Versicherung AG (AT): the register says authorised, the
+# reconciliation source says the legal entity is INACTIVE. One of
+# the two systems is wrong about a live insurer. Fires R4.
+#################################################################
+
+exd:u-eir a iro:InsuranceUndertaking ;
+ iro:legalName "Eir Versicherung AG" ;
+ iro:homeCountry exd:country-AT ;
+ iro:identifiedBy exd:lei-eir .
+
+exd:reg-eir a iro:Registration ;
+ iro:registrationOf exd:u-eir ;
+ iro:registeredBy exd:nca-AT ;
+ iro:registrationStart "1995-06-30"^^xsd:date .
+
+exd:lei-eir a iro:Identifier , iro:LEI ;
+ iro:identifierValue "999900EIRVERSAT00055" ;
+ iro:identifierScheme irosch:LEI ;
+ iro:sourceSystem exd:ExampleRegister ;
+ iro:checksumValid true ;
+ iro:inGleif true ;
+ iro:gleifRegistrationStatus "ISSUED" ;
+ iro:gleifEntityStatus "INACTIVE" ;
+ iro:gleifLegalName "Eir Versicherung AG in Abwicklung" ;
+ iro:identifies exd:u-eir .
+
+exd:op-eir-it a iro:CrossBorderOperation ;
+ iro:operationOf exd:u-eir ;
+ iro:hostCountry exd:country-IT ;
+ iro:operationMode irosch:EEABranch ;
+ iro:operationStart "2003-02-01"^^xsd:date .
+
+#################################################################
+# U6/U7 Fjord Re France SA and Fjord Re Ireland dac: two distinct
+# reinsurance legal entities filed under ONE LEI value. Fires R5.
+# Mirrors the SCOR France / SCOR Ireland collapse in the real
+# register.
+#################################################################
+
+exd:u-fjord-fr a iro:InsuranceUndertaking ;
+ iro:legalName "Fjord Re France SA" ;
+ iro:homeCountry exd:country-FR ;
+ iro:identifiedBy exd:lei-fjord .
+
+exd:reg-fjord-fr a iro:Registration ;
+ iro:registrationOf exd:u-fjord-fr ;
+ iro:registeredBy exd:nca-FR ;
+ iro:registrationStart "2007-01-15"^^xsd:date .
+
+exd:u-fjord-ie a iro:InsuranceUndertaking ;
+ iro:legalName "Fjord Re Ireland dac" ;
+ iro:homeCountry exd:country-IE ;
+ iro:identifiedBy exd:lei-fjord .
+
+exd:reg-fjord-ie a iro:Registration ;
+ iro:registrationOf exd:u-fjord-ie ;
+ iro:registeredBy exd:nca-IE ;
+ iro:registrationStart "2012-03-01"^^xsd:date .
+
+exd:lei-fjord a iro:Identifier , iro:LEI ;
+ iro:identifierValue "999900FJORDREFRIE062" ;
+ iro:identifierScheme irosch:LEI ;
+ iro:sourceSystem exd:ExampleRegister ;
+ iro:checksumValid true ;
+ iro:inGleif true ;
+ iro:gleifRegistrationStatus "ISSUED" ;
+ iro:gleifEntityStatus "ACTIVE" ;
+ iro:gleifLegalName "Fjord Re France SA" ;
+ iro:identifies exd:u-fjord-fr , exd:u-fjord-ie .
+
+exd:op-fjord-es a iro:CrossBorderOperation ;
+ iro:operationOf exd:u-fjord-fr ;
+ iro:hostCountry exd:country-ES ;
+ iro:operationMode irosch:EEAFreedomOfServices ;
+ iro:operationStart "2019-11-01"^^xsd:date .
+
+#################################################################
+# U8 Hestia Mutual Insurance Association (AT): a 19-character LEI,
+# a truncation, not a typo. Fails the layer-2 syntax pattern AND
+# ISO 7064, so it also fires R2. Mirrors the three 19-character
+# values found in BaFin's own register file.
+#################################################################
+
+exd:u-hestia a iro:InsuranceUndertaking ;
+ iro:legalName "Hestia Mutual Insurance Association" ;
+ iro:homeCountry exd:country-AT ;
+ iro:identifiedBy exd:lei-hestia .
+
+exd:reg-hestia a iro:Registration ;
+ iro:registrationOf exd:u-hestia ;
+ iro:registeredBy exd:nca-AT ;
+ iro:registrationStart "1989-01-01"^^xsd:date .
+
+exd:lei-hestia a iro:Identifier , iro:LEI ;
+ iro:identifierValue "999900HESTIAMUTAT04" ;
+ iro:identifierScheme irosch:LEI ;
+ iro:sourceSystem exd:ExampleRegister ;
+ iro:checksumValid false ;
+ iro:inGleif false ;
+ iro:identifies exd:u-hestia .
+
+#################################################################
+# U9 Grimma Assurans AB (SE): home registration ENDED 2024-06-30,
+# but one freedom-of-services operation into Finland is still
+# open. The passport outlives the authorization it derives from.
+# Fires R6. Its national-code assertion also carries no source
+# system, which the layer-1 provenance shape must catch.
+#################################################################
+
+exd:u-grimma a iro:InsuranceUndertaking ;
+ iro:legalName "Grimma Assurans AB" ;
+ iro:homeCountry exd:country-SE ;
+ iro:identifiedBy exd:nat-grimma .
+
+exd:reg-grimma a iro:Registration ;
+ iro:registrationOf exd:u-grimma ;
+ iro:registeredBy exd:nca-SE ;
+ iro:registrationStart "2002-08-01"^^xsd:date ;
+ iro:registrationEnd "2024-06-30"^^xsd:date .
+
+exd:nat-grimma a iro:Identifier , iro:NationalIdentificationCode ;
+ iro:identifierValue "SE-EX-9001" ;
+ iro:identifierScheme irosch:NationalIdentificationCode ;
+ iro:identifies exd:u-grimma .
+
+exd:op-grimma-fi a iro:CrossBorderOperation ;
+ iro:operationOf exd:u-grimma ;
+ iro:hostCountry exd:country-FI ;
+ iro:operationMode irosch:EEAFreedomOfServices ;
+ iro:operationStart "2011-04-01"^^xsd:date .
+
+#################################################################
+# U10 Halcyon Insurance hf. (IS): an undertaking node with no
+# registration attached at all, either an export gap or a join
+# failure. The layer-2 inverse-path shape reports it as a
+# Warning, and because R1 requires a live registration to reason
+# from, R1 deliberately does NOT fire here.
+#################################################################
+
+exd:u-halcyon a iro:InsuranceUndertaking ;
+ iro:legalName "Halcyon Insurance hf." ;
+ iro:homeCountry exd:country-IS .
+
+#################################################################
+# P1 Zephyr Insurance Company Ltd: a third-country branch with no
+# home registration row in the register, kept as a
+# RegisteredPresence rather than silently merged. Its open
+# third-country-branch operation does NOT fire R6, because there
+# is no ended home registration to contradict.
+#################################################################
+
+exd:p-zephyr a iro:RegisteredPresence ;
+ iro:legalName "Zephyr Insurance Company Ltd (German branch)" ;
+ iro:homeCountry exd:country-DE ;
+ iro:identifiedBy exd:lei-zephyr .
+
+exd:lei-zephyr a iro:Identifier , iro:LEI ;
+ iro:identifierValue "999900ZEPHYRJP000037" ;
+ iro:identifierScheme irosch:LEI ;
+ iro:sourceSystem exd:ExampleRegister ;
+ iro:checksumValid true ;
+ iro:inGleif true ;
+ iro:gleifRegistrationStatus "ISSUED" ;
+ iro:gleifEntityStatus "ACTIVE" ;
+ iro:gleifLegalName "Zephyr Insurance Company Ltd" ;
+ iro:identifies exd:p-zephyr .
+
+exd:op-zephyr-de a iro:CrossBorderOperation ;
+ iro:operationOf exd:p-zephyr ;
+ iro:hostCountry exd:country-DE ;
+ iro:operationMode irosch:ThirdCountryBranch ;
+ iro:operationStart "2014-10-01"^^xsd:date .
diff --git a/case-studies/insurance-register-ontology/iro-rules.ttl b/case-studies/insurance-register-ontology/iro-rules.ttl
new file mode 100644
index 00000000..451f6523
--- /dev/null
+++ b/case-studies/insurance-register-ontology/iro-rules.ttl
@@ -0,0 +1,153 @@
+@prefix iro: <https://gov.tesseract.academy/def/insurance#> .
+@prefix irosch: <https://gov.tesseract.academy/def/insurance/scheme#> .
+@prefix sh: <http://www.w3.org/ns/shacl#> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+#################################################################
+# IRO layer-3 rules: cross-source business rules over the
+# EIOPA register joined with GLEIF.
+#
+# Shipped as standard SHACL-SPARQL for platforms that execute it
+# natively. The reference pipeline executes the identical SPARQL
+# set-based (pipeline/governance_report.py), and the same rules
+# run as written on an Oxigraph-backed engine; see the rdflib
+# measurement in the Investment Fund Ontology case study at
+# github.com/fabio-rovai/open-ontologies (multi-way self-joins
+# are the rdflib failure mode, not anti-joins).
+#################################################################
+
+# R1: an active domestic undertaking with no LEI assertion.
+# EIOPA's Guidelines on the use of the Legal Entity Identifier
+# (EIOPA-BoS-14-026) ask NCAs to ensure that undertakings within
+# the scope of Solvency II hold an LEI. Warning, not Violation:
+# the guideline binds comply-or-explain at NCA level.
+iro:ActiveUndertakingNoLEIShape a sh:NodeShape ;
+ sh:targetClass iro:InsuranceUndertaking ;
+ sh:severity sh:Warning ;
+ sh:sparql [
+ a sh:SPARQLConstraint ;
+ sh:message "Active undertaking carries no LEI assertion from any source system: a coverage gap in the identifier fabric the EIOPA LEI guidelines exist to close." ;
+ sh:prefixes <https://gov.tesseract.academy/def/insurance> ;
+ sh:select """
+ PREFIX iro: <https://gov.tesseract.academy/def/insurance#>
+ SELECT $this WHERE {
+ ?reg iro:registrationOf $this .
+ FILTER NOT EXISTS { ?reg iro:registrationEnd ?end . }
+ FILTER NOT EXISTS {
+ $this iro:identifiedBy ?id .
+ ?id a iro:LEI .
+ }
+ }
+ """ ;
+ ] .
+
+# R2: checksum-invalid LEI. Violation: the value cannot exist in
+# the global LEI system, so every downstream join built on it is
+# dead on arrival.
+iro:InvalidLEIShape a sh:NodeShape ;
+ sh:targetClass iro:LEI ;
+ sh:sparql [
+ a sh:SPARQLConstraint ;
+ sh:message "LEI value fails ISO 7064 check digits: not a possible LEI. Filed in an official register, it silently severs the undertaking from GLEIF." ;
+ sh:prefixes <https://gov.tesseract.academy/def/insurance> ;
+ sh:select """
+ PREFIX iro: <https://gov.tesseract.academy/def/insurance#>
+ SELECT $this ?value WHERE {
+ $this iro:identifierValue ?value ;
+ iro:checksumValid false .
+ }
+ """ ;
+ ] .
+
+# R3: active undertaking whose LEI registration has LAPSED in
+# GLEIF. The identifier still denotes the right entity; its
+# annual renewal was not made. A staleness signal, not an error.
+iro:ActiveUndertakingLapsedLEIShape a sh:NodeShape ;
+ sh:targetClass iro:InsuranceUndertaking ;
+ sh:severity sh:Warning ;
+ sh:sparql [
+ a sh:SPARQLConstraint ;
+ sh:message "Active undertaking's LEI is LAPSED in GLEIF: the entity is authorised to write business but is not maintaining its global identifier." ;
+ sh:prefixes <https://gov.tesseract.academy/def/insurance> ;
+ sh:select """
+ PREFIX iro: <https://gov.tesseract.academy/def/insurance#>
+ SELECT $this ?value WHERE {
+ ?reg iro:registrationOf $this .
+ FILTER NOT EXISTS { ?reg iro:registrationEnd ?end . }
+ $this iro:identifiedBy ?id .
+ ?id a iro:LEI ;
+ iro:identifierValue ?value ;
+ iro:gleifRegistrationStatus "LAPSED" .
+ }
+ """ ;
+ ] .
+
+# R4: active undertaking whose LEI's ENTITY is INACTIVE per GLEIF.
+# The register says authorised, GLEIF says the legal entity has
+# ceased. One of the two systems is wrong about a live insurer.
+iro:ActiveUndertakingGleifInactiveShape a sh:NodeShape ;
+ sh:targetClass iro:InsuranceUndertaking ;
+ sh:severity sh:Warning ;
+ sh:sparql [
+ a sh:SPARQLConstraint ;
+ sh:message "Undertaking is register-active but its LEI's entity status is INACTIVE in GLEIF: cross-source contradiction about whether the insurer exists." ;
+ sh:prefixes <https://gov.tesseract.academy/def/insurance> ;
+ sh:select """
+ PREFIX iro: <https://gov.tesseract.academy/def/insurance#>
+ SELECT $this ?value WHERE {
+ ?reg iro:registrationOf $this .
+ FILTER NOT EXISTS { ?reg iro:registrationEnd ?end . }
+ $this iro:identifiedBy ?id .
+ ?id a iro:LEI ;
+ iro:identifierValue ?value ;
+ iro:gleifEntityStatus "INACTIVE" .
+ }
+ """ ;
+ ] .
+
+# R5: one LEI identifying more than one distinct undertaking.
+# Sometimes legitimate (branch structures), sometimes two
+# different companies on one identifier. Warning: a prompt to
+# check entity structure.
+iro:SharedLEIShape a sh:NodeShape ;
+ sh:targetClass iro:LEI ;
+ sh:severity sh:Warning ;
+ sh:sparql [
+ a sh:SPARQLConstraint ;
+ sh:message "LEI identifies more than one distinct undertaking in the register: entity collapse or a mis-filed identifier." ;
+ sh:prefixes <https://gov.tesseract.academy/def/insurance> ;
+ sh:select """
+ PREFIX iro: <https://gov.tesseract.academy/def/insurance#>
+ SELECT $this ?value WHERE {
+ $this iro:identifies ?u1, ?u2 .
+ FILTER (STR(?u1) < STR(?u2))
+ $this iro:identifierValue ?value .
+ }
+ """ ;
+ ] .
+
+# R6: an operation with no end date belonging to an undertaking
+# whose home registration HAS ended: a passport outliving its
+# authorization. Violation.
+iro:ZombiePassportShape a sh:NodeShape ;
+ sh:targetClass iro:CrossBorderOperation ;
+ sh:sparql [
+ a sh:SPARQLConstraint ;
+ sh:message "Open cross-border operation for an undertaking whose home registration has ended: the passport outlives the authorization it derives from." ;
+ sh:prefixes <https://gov.tesseract.academy/def/insurance> ;
+ sh:select """
+ PREFIX iro: <https://gov.tesseract.academy/def/insurance#>
+ SELECT $this WHERE {
+ $this iro:operationOf ?u .
+ FILTER NOT EXISTS { $this iro:operationEnd ?oe . }
+ ?reg iro:registrationOf ?u ;
+ iro:registrationEnd ?re .
+ }
+ """ ;
+ ] .
+
+<https://gov.tesseract.academy/def/insurance>
+ sh:declare [
+ sh:prefix "iro" ;
+ sh:namespace "https://gov.tesseract.academy/def/insurance#"^^xsd:anyURI ;
+ ] .
diff --git a/case-studies/insurance-register-ontology/iro-shapes.ttl b/case-studies/insurance-register-ontology/iro-shapes.ttl
new file mode 100644
index 00000000..5796bf61
--- /dev/null
+++ b/case-studies/insurance-register-ontology/iro-shapes.ttl
@@ -0,0 +1,91 @@
+@prefix iro: <https://gov.tesseract.academy/def/insurance#> .
+@prefix irosch: <https://gov.tesseract.academy/def/insurance/scheme#> .
+@prefix sh: <http://www.w3.org/ns/shacl#> .
+@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
+
+#################################################################
+# IRO layers 1-2: syntax, checksum policy, structure.
+# Arithmetic lives in pipeline/checksums.py; shapes require the
+# recorded result.
+#################################################################
+
+iro:IdentifierShape a sh:NodeShape ;
+ sh:targetClass iro:Identifier ;
+ sh:property [
+ sh:path iro:identifierValue ;
+ sh:minCount 1 ;
+ sh:message "Identifier assertion without a value." ;
+ ] ;
+ sh:property [
+ sh:path iro:identifierScheme ;
+ sh:minCount 1 ;
+ sh:message "Identifier assertion without a scheme: an identifier with no scheme is a string, not an identifier." ;
+ ] ;
+ sh:property [
+ sh:path iro:sourceSystem ;
+ sh:minCount 1 ;
+ sh:message "Identifier assertion without a source system: an identifier with no provenance cannot be reconciled."
+ ] .
+
+iro:LEIShape a sh:NodeShape ;
+ sh:targetClass iro:LEI ;
+ sh:property [
+ sh:path iro:identifierValue ;
+ sh:pattern "^[A-Z0-9]{18}[0-9]{2}$" ;
+ sh:message "LEI must be 20 characters: 18 alphanumerics plus 2 decimal check digits (ISO 17442)." ;
+ ] ;
+ sh:property [
+ sh:path iro:checksumValid ;
+ sh:hasValue true ;
+ sh:message "LEI check digits fail ISO 7064 MOD 97-10: this value cannot be a real LEI." ;
+ ] .
+
+iro:UndertakingShape a sh:NodeShape ;
+ sh:targetClass iro:InsuranceUndertaking ;
+ sh:property [
+ sh:path iro:legalName ;
+ sh:minCount 1 ;
+ sh:message "Undertaking without a legal name." ;
+ ] ;
+ sh:property [
+ sh:path iro:homeCountry ;
+ sh:minCount 1 ; sh:maxCount 1 ;
+ sh:message "Undertaking must have exactly one home country." ;
+ ] ;
+ sh:property [
+ sh:path [ sh:inversePath iro:registrationOf ] ;
+ sh:minCount 1 ;
+ sh:severity sh:Warning ;
+ sh:message "Undertaking with no home registration attached: either a register export gap or a join failure." ;
+ ] .
+
+iro:RegistrationShape a sh:NodeShape ;
+ sh:targetClass iro:Registration ;
+ sh:property [
+ sh:path iro:registrationOf ;
+ sh:minCount 1 ; sh:maxCount 1 ;
+ sh:message "Registration must be of exactly one undertaking." ;
+ ] ;
+ sh:property [
+ sh:path iro:registeredBy ;
+ sh:minCount 1 ;
+ sh:message "Registration must name the authorising NCA." ;
+ ] .
+
+iro:OperationShape a sh:NodeShape ;
+ sh:targetClass iro:CrossBorderOperation ;
+ sh:property [
+ sh:path iro:operationOf ;
+ sh:minCount 1 ; sh:maxCount 1 ;
+ sh:message "Cross-border operation must be of exactly one undertaking." ;
+ ] ;
+ sh:property [
+ sh:path iro:hostCountry ;
+ sh:minCount 1 ; sh:maxCount 1 ;
+ sh:message "Cross-border operation must have exactly one host country." ;
+ ] ;
+ sh:property [
+ sh:path iro:operationMode ;
+ sh:minCount 1 ; sh:maxCount 1 ;
+ sh:message "Cross-border operation must carry exactly one operation mode from the SKOS registry." ;
+ ] .
diff --git a/case-studies/insurance-register-ontology/operation-modes.ttl b/case-studies/insurance-register-ontology/operation-modes.ttl
new file mode 100644
index 00000000..a9713127
--- /dev/null
+++ b/case-studies/insurance-register-ontology/operation-modes.ttl
@@ -0,0 +1,86 @@
+@prefix iro: <https://gov.tesseract.academy/def/insurance#> .
+@prefix irosch: <https://gov.tesseract.academy/def/insurance/scheme#> .
+@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
+@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+@prefix dcterms: <http://purl.org/dc/terms/> .
+
+#################################################################
+# Operation modes: the five ways an undertaking appears in the
+# EIOPA register's cross-border fabric. Values are the register's
+# own vocabulary ("Cross border status" column), given definitions
+# grounded in Directive 2009/138/EC (Solvency II).
+#################################################################
+
+irosch:operationModes a skos:ConceptScheme ;
+ skos:prefLabel "IRO operation modes"@en ;
+ dcterms:source "EIOPA Register of Insurance Undertakings, 'Cross border status' field; Directive 2009/138/EC Title I Chapter VIII (freedom of establishment and freedom to provide services)"@en .
+
+irosch:Domestic a skos:Concept ;
+ skos:inScheme irosch:operationModes ;
+ skos:prefLabel "domestic undertaking"@en ;
+ skos:notation "Domestic undertaking" ;
+ skos:definition "The undertaking's home-state authorization row: authorised by its home NCA and operating in its home market."@en .
+
+irosch:EEAFreedomOfServices a skos:Concept ;
+ skos:inScheme irosch:operationModes ;
+ skos:prefLabel "EEA freedom of services"@en ;
+ skos:notation "EEA FPS" ;
+ skos:definition "Operation in a host EEA country under freedom to provide services (passporting without establishment), Directive 2009/138/EC Articles 147-149."@en .
+
+irosch:EEABranch a skos:Concept ;
+ skos:inScheme irosch:operationModes ;
+ skos:prefLabel "EEA branch"@en ;
+ skos:notation "EEA branch" ;
+ skos:definition "Operation in a host EEA country through an established branch (freedom of establishment), Directive 2009/138/EC Articles 145-146."@en .
+
+irosch:ThirdCountryBranch a skos:Concept ;
+ skos:inScheme irosch:operationModes ;
+ skos:prefLabel "third-country branch"@en ;
+ skos:notation "3rd country branch" ;
+ skos:definition "A branch of an undertaking whose head office is outside the EEA, authorised under Directive 2009/138/EC Article 162."@en .
+
+irosch:FPSForEEABranch a skos:Concept ;
+ skos:inScheme irosch:operationModes ;
+ skos:prefLabel "freedom of services exercised by an EEA branch"@en ;
+ skos:notation "FPS for EEA Branches" ;
+ skos:definition "Freedom-of-services operation notified for an EEA branch rather than for the head-office undertaking: the register's own encoding of second-order passporting."@en .
+
+#################################################################
+# Identifier schemes present in this register fabric.
+#################################################################
+
+irosch:identifierSchemes a skos:ConceptScheme ;
+ skos:prefLabel "IRO identifier schemes"@en .
+
+irosch:LEI a skos:Concept ;
+ skos:inScheme irosch:identifierSchemes ;
+ skos:prefLabel "LEI"@en ;
+ skos:altLabel "Legal Entity Identifier"@en ;
+ skos:definition "20-character legal entity identifier defined by ISO 17442; 2 final check digits under ISO 7064 MOD 97-10. Entity-scoped and globally unique. EIOPA's 2014 Guidelines on the use of the Legal Entity Identifier (EIOPA-BoS-14-026) ask NCAs to ensure all undertakings under Solvency II hold one."@en ;
+ iro:identifierScope irosch:EntityScoped ;
+ iro:syntaxPattern "^[A-Z0-9]{18}[0-9]{2}$" .
+
+irosch:NationalIdentificationCode a skos:Concept ;
+ skos:inScheme irosch:identifierSchemes ;
+ skos:prefLabel "national identification code"@en ;
+ skos:definition "The identification code the home NCA assigns to the undertaking, carried by the EIOPA register. Unique only within the issuing NCA's namespace; formats differ per country. NCA-scoped, not global, the scope declaration is the data quality rule."@en ;
+ iro:identifierScope irosch:AuthorityScoped .
+
+irosch:EntityScoped a skos:Concept ;
+ skos:prefLabel "entity-scoped"@en ;
+ skos:definition "Identifies a legal entity, globally."@en .
+irosch:AuthorityScoped a skos:Concept ;
+ skos:prefLabel "authority-scoped"@en ;
+ skos:definition "Unique only within one issuing authority's namespace."@en .
+
+#################################################################
+# Source systems.
+#################################################################
+
+irosch:EIOPA-DATINS a skos:Concept ;
+ skos:prefLabel "EIOPA Register of Insurance Undertakings"@en ;
+ skos:definition "EIOPA's public register of insurance and reinsurance undertakings (register.eiopa.europa.eu), bulk CSV export."@en .
+
+irosch:GLEIF-API a skos:Concept ;
+ skos:prefLabel "GLEIF LEI records API"@en ;
+ skos:definition "api.gleif.org v1 lei-records, harvested per LEI value found in the EIOPA register."@en .
diff --git a/case-studies/insurance-register-ontology/run-demo.sh b/case-studies/insurance-register-ontology/run-demo.sh
new file mode 100755
index 00000000..ceda3313
--- /dev/null
+++ b/case-studies/insurance-register-ontology/run-demo.sh
@@ -0,0 +1,202 @@
+#!/usr/bin/env bash
+# Insurance Register Ontology (IRO) case study.
+#
+# Part 1 (always runs, self-contained): loads the vendored IRO core ontology,
+# the SKOS operation-mode and identifier-scheme registries, and a SYNTHETIC
+# example subgraph (no EIOPA or GLEIF data is redistributed here); runs the
+# registry and provenance queries, executes all six layer-3 rules as plain
+# SPARQL against engineered defects with known counts, and validates the
+# layer-1/2 shapes.
+#
+# Part 2 (runs when the full graph is present): loads the 276,683-triple EEA
+# register graph built by github.com/fabio-rovai/insurance-register-ontology
+# and executes the six layer-3 governance rules as plain SPARQL, printing each
+# count next to the number the IRO reference pipeline (set-based Python)
+# published for it.
+#
+# IRO_GRAPH=/path/to/iro_graph.ttl ./run-demo.sh
+#
+# Usage: ./run-demo.sh
+# Produces a markdown report on stdout.
+
+set -euo pipefail
+
+DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+ROOT="$(cd "$DIR/../.." && pwd)"
+IRO_GRAPH="${IRO_GRAPH:-$HOME/projects/insurance-register-ontology/data/build/iro_graph.ttl}"
+
+cargo build --release --manifest-path "$ROOT/Cargo.toml" --bin open-ontologies --quiet
+BIN="$(cargo metadata --manifest-path "$ROOT/Cargo.toml" --format-version 1 | python3 -c 'import sys,json; print(json.load(sys.stdin)["target_directory"])')/release/open-ontologies"
+
+filter_results() {
+ python3 -c "
+import json, sys
+for line in sys.stdin:
+ line = line.strip()
+ if not line:
+ continue
+ try:
+ r = json.loads(line)
+ except ValueError:
+ continue
+ if r.get('command') in ('query', 'stats', 'shacl'):
+ print(json.dumps(r['result'], indent=2)[:1600])
+"
+}
+
+cat <<'EOF_HEADER'
+# IRO on Open Ontologies: the six layer-3 rules as plain SPARQL
+
+Ontology under test: the Insurance Register Ontology
+(github.com/fabio-rovai/insurance-register-ontology), vendored at its
+14 Aug 2026 state. Part 1 runs on a clearly labelled SYNTHETIC subgraph;
+no EIOPA register data is redistributed by this case study.
+
+## Part 1: self-contained: core + registries + synthetic subgraph
+
+EOF_HEADER
+
+echo '### Load and stats'
+echo
+echo '```json'
+"$BIN" batch - <<EOF 2>&1 | filter_results
+load $DIR/iro-core.ttl
+load $DIR/operation-modes.ttl
+load $DIR/iro-example-synthetic.ttl
+stats
+EOF
+echo '```'
+
+run_part1() {
+ local label="$1"
+ local query="$2"
+ echo
+ echo "### $label"
+ echo
+ echo '```json'
+ "$BIN" batch - <<EOF 2>&1 | filter_results
+load $DIR/iro-core.ttl
+load $DIR/operation-modes.ttl
+load $DIR/iro-example-synthetic.ttl
+query "$query"
+EOF
+ echo '```'
+}
+
+# Scope as data: the registry declares the LEI entity-scoped and the NCA
+# code authority-scoped. A branch legitimately carrying its head office's
+# LEI under a host NCA's code is modelled, not special-cased.
+run_part1 "Identifier schemes by declared scope (SKOS registry)" \
+'PREFIX iro: <https://gov.tesseract.academy/def/insurance#> PREFIX irosch: <https://gov.tesseract.academy/def/insurance/scheme#> PREFIX skos: <http://www.w3.org/2004/02/skos/core#> SELECT ?scope (GROUP_CONCAT(?label; separator=\", \") AS ?schemes) WHERE { ?scheme skos:inScheme irosch:identifierSchemes ; iro:identifierScope ?scope ; skos:prefLabel ?label } GROUP BY ?scope'
+
+# The five operation modes, grounded in Directive 2009/138/EC, readable as
+# data with the register's own notation next to each concept.
+run_part1 "Operation modes (SKOS registry, notations from the register vocabulary)" \
+'PREFIX irosch: <https://gov.tesseract.academy/def/insurance/scheme#> PREFIX skos: <http://www.w3.org/2004/02/skos/core#> SELECT ?label ?notation WHERE { ?mode skos:inScheme irosch:operationModes ; skos:prefLabel ?label ; skos:notation ?notation } ORDER BY ?label'
+
+# All six layer-3 rules over the synthetic subgraph. The subgraph is
+# engineered so the expected counts are 1 / 2 / 1 / 1 / 1 / 1.
+echo
+echo '### The six layer-3 rules over the synthetic subgraph (expected 1 / 2 / 1 / 1 / 1 / 1)'
+echo
+echo '```json'
+"$BIN" batch - <<EOF 2>&1 | filter_results
+load $DIR/iro-core.ttl
+load $DIR/operation-modes.ttl
+load $DIR/iro-example-synthetic.ttl
+query "PREFIX iro: <https://gov.tesseract.academy/def/insurance#> SELECT (COUNT(DISTINCT ?this) AS ?r1_active_no_lei) WHERE { ?this a iro:InsuranceUndertaking . ?reg iro:registrationOf ?this . FILTER NOT EXISTS { ?reg iro:registrationEnd ?end . } FILTER NOT EXISTS { ?this iro:identifiedBy ?id . ?id a iro:LEI . } }"
+query "PREFIX iro: <https://gov.tesseract.academy/def/insurance#> SELECT (COUNT(DISTINCT ?this) AS ?r2_impossible_leis) WHERE { ?this a iro:LEI ; iro:identifierValue ?value ; iro:checksumValid false . }"
+query "PREFIX iro: <https://gov.tesseract.academy/def/insurance#> SELECT (COUNT(DISTINCT ?this) AS ?r3_lapsed_lei) WHERE { ?this a iro:InsuranceUndertaking . ?reg iro:registrationOf ?this . FILTER NOT EXISTS { ?reg iro:registrationEnd ?end . } ?this iro:identifiedBy ?id . ?id a iro:LEI ; iro:identifierValue ?value ; iro:gleifRegistrationStatus \"LAPSED\" . }"
+query "PREFIX iro: <https://gov.tesseract.academy/def/insurance#> SELECT (COUNT(DISTINCT ?this) AS ?r4_entity_inactive) WHERE { ?this a iro:InsuranceUndertaking . ?reg iro:registrationOf ?this . FILTER NOT EXISTS { ?reg iro:registrationEnd ?end . } ?this iro:identifiedBy ?id . ?id a iro:LEI ; iro:identifierValue ?value ; iro:gleifEntityStatus \"INACTIVE\" . }"
+query "PREFIX iro: <https://gov.tesseract.academy/def/insurance#> SELECT (COUNT(DISTINCT ?this) AS ?r5_shared_leis) WHERE { ?this a iro:LEI ; iro:identifies ?u1, ?u2 . FILTER (STR(?u1) < STR(?u2)) ?this iro:identifierValue ?value . }"
+query "PREFIX iro: <https://gov.tesseract.academy/def/insurance#> SELECT (COUNT(DISTINCT ?this) AS ?r6_zombie_passports) WHERE { ?this a iro:CrossBorderOperation ; iro:operationOf ?u . FILTER NOT EXISTS { ?this iro:operationEnd ?oe . } ?reg iro:registrationOf ?u ; iro:registrationEnd ?re . }"
+EOF
+echo '```'
+
+# Provenance: identifier assertions per source system, disagreement as a
+# query, not an audit project.
+run_part1 "Identifier assertions per source system" \
+'PREFIX iro: <https://gov.tesseract.academy/def/insurance#> PREFIX skos: <http://www.w3.org/2004/02/skos/core#> SELECT ?sourceLabel (COUNT(?id) AS ?assertions) WHERE { ?id a iro:Identifier ; iro:sourceSystem ?source . ?source skos:prefLabel ?sourceLabel } GROUP BY ?sourceLabel ORDER BY DESC(?assertions)'
+
+echo
+echo '### Layer-1/2 SHACL over the synthetic subgraph'
+echo
+echo 'Exercises `sh:pattern` (the 19-character truncated LEI), `sh:hasValue`'
+echo '(the checksum policy), `sh:minCount` (the provenance-free identifier),'
+echo 'and the `sh:inversePath` registration shape with `sh:severity` grading.'
+echo
+echo '```json'
+"$BIN" batch - <<EOF 2>&1 | python3 -c "
+import json, sys
+for line in sys.stdin:
+ line = line.strip()
+ if not line:
+ continue
+ try:
+ r = json.loads(line)
+ except ValueError:
+ continue
+ if r.get('command') == 'shacl':
+ res = r['result']
+ by = {}
+ for v in res.get('violations', []):
+ key = (v['severity'], v['constraint'], v['message'][:70])
+ by[key] = by.get(key, 0) + 1
+ print(json.dumps({'conforms': res.get('conforms'),
+ 'total': res.get('violation_count'),
+ 'by_message': [{'severity': k[0], 'constraint': k[1], 'message': k[2], 'count': c}
+ for k, c in sorted(by.items())]},
+ indent=2))
+"
+load $DIR/iro-core.ttl
+load $DIR/operation-modes.ttl
+load $DIR/iro-example-synthetic.ttl
+shacl $DIR/iro-shapes.ttl
+EOF
+echo '```'
+
+if [ ! -f "$IRO_GRAPH" ]; then
+ cat <<'EOF_NOGRAPH'
+
+## Part 2: full EEA register graph: SKIPPED
+
+`iro_graph.ttl` not found. Clone github.com/fabio-rovai/insurance-register-ontology,
+run its pipeline (fetch_eiopa.py, harvest_gleif.py, build_graph.py), and point
+IRO_GRAPH at data/build/iro_graph.ttl to replicate the layer-3 rules at
+276,683 triples. The EIOPA export is fetched by you, from EIOPA; it is not
+distributed with this repository.
+EOF_NOGRAPH
+ exit 0
+fi
+
+cat <<EOF_P2
+
+## Part 2: full EEA register graph ($IRO_GRAPH)
+
+The six layer-3 rules from \`iro-rules.ttl\`, executed as the plain SPARQL
+inside their \`sh:select\` bodies. Reference counts are the ones the IRO
+pipeline (set-based Python over the source CSVs) published in its governance
+report for the 14 Aug 2026 build: R1 = 643, R2 = 4, R3 = 118, R4 = 42,
+R5 = 227 register keys (20 at graph level, after entity resolution),
+R6 = 283 (291 at graph level; the LEI join attributes 8 more open operations
+to their ended home registration than the CSV key join can see). A rebuilt
+graph from fresher EIOPA/GLEIF snapshots will differ.
+
+\`\`\`json
+EOF_P2
+
+START=$(date +%s)
+"$BIN" batch - <<EOF 2>&1 | filter_results
+load $IRO_GRAPH
+query "PREFIX iro: <https://gov.tesseract.academy/def/insurance#> SELECT (COUNT(DISTINCT ?this) AS ?r1_active_no_lei) WHERE { ?this a iro:InsuranceUndertaking . ?reg iro:registrationOf ?this . FILTER NOT EXISTS { ?reg iro:registrationEnd ?end . } FILTER NOT EXISTS { ?this iro:identifiedBy ?id . ?id a iro:LEI . } }"
+query "PREFIX iro: <https://gov.tesseract.academy/def/insurance#> SELECT (COUNT(DISTINCT ?this) AS ?r2_impossible_leis) WHERE { ?this a iro:LEI ; iro:identifierValue ?value ; iro:checksumValid false . }"
+query "PREFIX iro: <https://gov.tesseract.academy/def/insurance#> SELECT (COUNT(DISTINCT ?this) AS ?r3_lapsed_lei) WHERE { ?this a iro:InsuranceUndertaking . ?reg iro:registrationOf ?this . FILTER NOT EXISTS { ?reg iro:registrationEnd ?end . } ?this iro:identifiedBy ?id . ?id a iro:LEI ; iro:identifierValue ?value ; iro:gleifRegistrationStatus \"LAPSED\" . }"
+query "PREFIX iro: <https://gov.tesseract.academy/def/insurance#> SELECT (COUNT(DISTINCT ?this) AS ?r4_entity_inactive) WHERE { ?this a iro:InsuranceUndertaking . ?reg iro:registrationOf ?this . FILTER NOT EXISTS { ?reg iro:registrationEnd ?end . } ?this iro:identifiedBy ?id . ?id a iro:LEI ; iro:identifierValue ?value ; iro:gleifEntityStatus \"INACTIVE\" . }"
+query "PREFIX iro: <https://gov.tesseract.academy/def/insurance#> SELECT (COUNT(DISTINCT ?this) AS ?r5_shared_leis) WHERE { ?this a iro:LEI ; iro:identifies ?u1, ?u2 . FILTER (STR(?u1) < STR(?u2)) ?this iro:identifierValue ?value . }"
+query "PREFIX iro: <https://gov.tesseract.academy/def/insurance#> SELECT (COUNT(DISTINCT ?this) AS ?r6_zombie_passports) WHERE { ?this a iro:CrossBorderOperation ; iro:operationOf ?u . FILTER NOT EXISTS { ?this iro:operationEnd ?oe . } ?reg iro:registrationOf ?u ; iro:registrationEnd ?re . }"
+query "PREFIX iro: <https://gov.tesseract.academy/def/insurance#> PREFIX irosch: <https://gov.tesseract.academy/def/insurance/scheme#> SELECT ?home (COUNT(?op) AS ?open_fps) WHERE { ?op a iro:CrossBorderOperation ; iro:operationMode irosch:EEAFreedomOfServices ; iro:operationOf ?u . FILTER NOT EXISTS { ?op iro:operationEnd ?e . } ?u iro:homeCountry ?home . } GROUP BY ?home ORDER BY DESC(?open_fps) LIMIT 6"
+EOF
+END=$(date +%s)
+echo '```'
+echo
+echo "Wall clock for load + all six rules + the passporting query, single process: $((END - START))s."
diff --git a/src/shacl.rs b/src/shacl.rs
index c1d92cdd..5829fd07 100644
--- a/src/shacl.rs
+++ b/src/shacl.rs
@@ -10,7 +10,8 @@ use std::sync::Arc;
///
/// Shapes are parsed from inline Turtle into a temporary Oxigraph store.
/// Constraints are translated into SPARQL queries run against the main graph.
-/// Supports `sh:minCount`, `sh:maxCount`, and `sh:datatype` constraints.
+/// Supports `sh:minCount`, `sh:maxCount`, `sh:datatype`, `sh:pattern`, and
+/// `sh:hasValue` constraints.
pub struct ShaclValidator;
impl ShaclValidator {
@@ -57,13 +58,15 @@ impl ShaclValidator {
&format!(
r#"
PREFIX sh: <http://www.w3.org/ns/shacl#>
- SELECT ?prop ?path ?invPath ?minCount ?maxCount ?datatype ?message ?severity WHERE {{
+ SELECT ?prop ?path ?invPath ?minCount ?maxCount ?datatype ?pattern ?hasValue ?message ?severity WHERE {{
{} sh:property ?prop .
?prop sh:path ?path .
OPTIONAL {{ ?path sh:inversePath ?invPath }}
OPTIONAL {{ ?prop sh:minCount ?minCount }}
OPTIONAL {{ ?prop sh:maxCount ?maxCount }}
OPTIONAL {{ ?prop sh:datatype ?datatype }}
+ OPTIONAL {{ ?prop sh:pattern ?pattern }}
+ OPTIONAL {{ ?prop sh:hasValue ?hasValue }}
OPTIONAL {{ ?prop sh:message ?message }}
OPTIONAL {{ ?prop sh:severity ?severity }}
}}
@@ -212,6 +215,69 @@ impl ShaclValidator {
}
}
}
+
+ // sh:pattern (regex over the string form of each value node,
+ // per SHACL; `sh:flags` is not supported and simply absent
+ // from real-world shapes we have seen so far).
+ if let Some(pattern_raw) = prop.get("pattern") {
+ let pattern = strip_quotes(pattern_raw);
+ let escaped = pattern.replace('\\', "\\\\").replace('"', "\\\"");
+ let query = format!(
+ r#"SELECT ?focus ?val WHERE {{
+ ?focus a <{target_class}> .
+ ?focus {path_expr} ?val .
+ FILTER(!REGEX(STR(?val), "{escaped}"))
+ }}"#
+ );
+ let results = graph_sparql_select(graph, &query)?;
+ for row in &results {
+ if let Some(focus) = row.get("focus") {
+ let msg = if message.is_empty() {
+ format!("Value does not match pattern {}", pattern)
+ } else {
+ message.clone()
+ };
+ violations.push(serde_json::json!({
+ "severity": severity,
+ "focus_node": strip_angle_brackets(focus),
+ "path": path,
+ "constraint": "pattern",
+ "message": msg,
+ }));
+ }
+ }
+ }
+
+ // sh:hasValue: every focus node must carry the exact term at
+ // least once on the path. The term arrives from the shapes
+ // store in N-Triples form (`<iri>` or `"lit"^^<dt>`), which is
+ // valid SPARQL as-is.
+ if let Some(has_value_term) = prop.get("hasValue") {
+ let term = has_value_term.trim();
+ let query = format!(
+ r#"SELECT ?focus WHERE {{
+ ?focus a <{target_class}> .
+ FILTER NOT EXISTS {{ ?focus {path_expr} {term} }}
+ }}"#
+ );
+ let results = graph_sparql_select(graph, &query)?;
+ for row in &results {
+ if let Some(focus) = row.get("focus") {
+ let msg = if message.is_empty() {
+ format!("Required value {} is not present", term)
+ } else {
+ message.clone()
+ };
+ violations.push(serde_json::json!({
+ "severity": severity,
+ "focus_node": strip_angle_brackets(focus),
+ "path": path,
+ "constraint": "hasValue",
+ "message": msg,
+ }));
+ }
+ }
+ }
}
}
diff --git a/tests/shacl_test.rs b/tests/shacl_test.rs
index 2984bc91..c04ab7d4 100644
--- a/tests/shacl_test.rs
+++ b/tests/shacl_test.rs
@@ -151,6 +151,70 @@ fn test_shacl_inverse_path_mincount() {
assert!(!violations.iter().any(|v| v["focus_node"].as_str().unwrap().contains("reg1")));
}
+#[test]
+fn test_shacl_pattern_violation() {
+ // LEI-style syntax rule: 18 alphanumerics + 2 decimal check digits.
+ // id1 conforms; id2 is 19 characters (a truncation) and must fire.
+ let store = Arc::new(GraphStore::new());
+ let ttl = r#"
+ @prefix ex: <http://example.org/> .
+ ex:id1 a ex:LEI ; ex:value "969500AAAAAAAAAAAA75" .
+ ex:id2 a ex:LEI ; ex:value "969500BBBBBBBBBBB12" .
+ "#;
+ store.load_turtle(ttl, None).unwrap();
+ let shapes = r#"
+ @prefix sh: <http://www.w3.org/ns/shacl#> .
+ @prefix ex: <http://example.org/> .
+ ex:LEIShape a sh:NodeShape ;
+ sh:targetClass ex:LEI ;
+ sh:property [
+ sh:path ex:value ;
+ sh:pattern "^[A-Z0-9]{18}[0-9]{2}$" ;
+ sh:message "LEI must be 20 characters (ISO 17442)" ;
+ ] .
+ "#;
+ let result = ShaclValidator::validate(&store, shapes).unwrap();
+ let parsed: serde_json::Value = serde_json::from_str(&result).unwrap();
+ assert_eq!(parsed["conforms"], false);
+ let violations = parsed["violations"].as_array().unwrap();
+ assert!(violations.iter().any(|v| v["focus_node"].as_str().unwrap().contains("id2")));
+ assert!(!violations.iter().any(|v| v["focus_node"].as_str().unwrap().contains("id1")));
+ assert!(violations.iter().any(|v| v["constraint"] == "pattern"));
+}
+
+#[test]
+fn test_shacl_has_value_violation() {
+ // Checksum policy: every LEI node must record ex:checksumValid true.
+ // id1 records true; id2 records false; id3 records nothing.
+ let store = Arc::new(GraphStore::new());
+ let ttl = r#"
+ @prefix ex: <http://example.org/> .
+ ex:id1 a ex:LEI ; ex:checksumValid true .
+ ex:id2 a ex:LEI ; ex:checksumValid false .
+ ex:id3 a ex:LEI .
+ "#;
+ store.load_turtle(ttl, None).unwrap();
+ let shapes = r#"
+ @prefix sh: <http://www.w3.org/ns/shacl#> .
+ @prefix ex: <http://example.org/> .
+ ex:LEIChecksumShape a sh:NodeShape ;
+ sh:targetClass ex:LEI ;
+ sh:property [
+ sh:path ex:checksumValid ;
+ sh:hasValue true ;
+ sh:message "LEI check digits fail or are unrecorded" ;
+ ] .
+ "#;
+ let result = ShaclValidator::validate(&store, shapes).unwrap();
+ let parsed: serde_json::Value = serde_json::from_str(&result).unwrap();
+ assert_eq!(parsed["conforms"], false);
+ let violations = parsed["violations"].as_array().unwrap();
+ assert!(violations.iter().any(|v| v["focus_node"].as_str().unwrap().contains("id2")));
+ assert!(violations.iter().any(|v| v["focus_node"].as_str().unwrap().contains("id3")));
+ assert!(!violations.iter().any(|v| v["focus_node"].as_str().unwrap().contains("id1")));
+ assert!(violations.iter().any(|v| v["constraint"] == "hasValue"));
+}
+
#[test]
fn test_shacl_unsupported_path_skipped_not_fatal() {
// A sequence path is not executable; it must be reported as skipped