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.

fix(demo): reproducible per-file findings, accurate wording, no unreconciled counts

FABIOTESS6985d35c83e9
diff --git a/demo/dcat_conformance.py b/demo/dcat_conformance.py
index dec1f691..ec5695ab 100644
--- a/demo/dcat_conformance.py
+++ b/demo/dcat_conformance.py
@@ -415,6 +415,65 @@ def measure(
}
+def _rel_key(path: Path) -> str:
+ """'<Class>/good/<file>.json', unique across the corpus.
+
+ Bare filenames are NOT unique: "minimal_example.json", "null_example.json"
+ and "typical_example.json" each recur under many different classes'
+ good/ directories, so keying per-file results by path.name alone would
+ silently collide and overwrite entries.
+ """
+ return "/".join(path.parts[-3:])
+
+
+def per_file_triples(
+ files: list[Path], context: dict | None, base: str = BASE, retype: dict[str, str] | None = None
+) -> dict[str, int]:
+ """Triples produced by each file on its own, keyed by '<Class>/good/<file>'.
+
+ Distinct from measure()['triples'] (the same per-file counts summed) and
+ from len(merge_corpus(...)) (all files' triples merged into one
+ rdflib.Graph, where exact-duplicate triples across files collapse: two
+ files that both mint the same manufactured relative IRI and type it the
+ same way contribute only one triple to the merged graph, not two). This
+ is what a reader checking one specific example file in isolation would
+ reproduce by hand.
+ """
+ out: dict[str, int] = {}
+ for path in files:
+ g, err = expand_file(path, context, base, retype)
+ out[_rel_key(path)] = 0 if err else len(g)
+ return out
+
+
+def per_file_shacl_violations(
+ files: list[Path], shapes_path: Path, context: dict | None,
+ base: str = BASE, retype: dict[str, str] | None = None,
+) -> dict[str, dict]:
+ """SHACL violations for each file's own triples, validated on its own.
+
+ Each good example is a self-contained record: no file's triples name a
+ subject that another file also describes. Validating one file's expanded
+ graph alone therefore reproduces what a reader would see running only
+ that file through pySHACL, not an artefact of merging the whole corpus
+ into one graph first.
+ """
+ out: dict[str, dict] = {}
+ for path in files:
+ g, err = expand_file(path, context, base, retype)
+ key = _rel_key(path)
+ if err:
+ out[key] = {"violations": None, "focusNodes": 0, "conforms": None, "error": err}
+ continue
+ result = run_shacl(shapes_path, g)
+ out[key] = {
+ "violations": result["violations"],
+ "focusNodes": result["focusNodes"],
+ "conforms": result["conforms"],
+ }
+ return out
+
+
def merge_corpus(
files: list[Path], context: dict | None, base: str = BASE, retype: dict[str, str] | None = None
) -> Graph:
@@ -579,6 +638,23 @@ def main() -> int:
"focusNodesDelta": shacl_org_fixed["focusNodes"] - shacl_real_typed["focusNodes"],
}
+ # --- Per-file breakdown ---
+ # demo/precomputed/findings.json quotes per-file triple and violation
+ # figures for specific example files (Catalog, Dataset, Distribution,
+ # Concept, Identifier). Those are computed here, not eyeballed from the
+ # aggregate numbers above, and pinned by
+ # demo/tests/test_dcat_conformance.py so a reader running this script
+ # reproduces exactly what findings.json quotes.
+ per_file_published = per_file_triples(good_files, None)
+ per_file_observed_violations = per_file_shacl_violations(good_files, SHAPES_PATH, observed)
+ per_file_real_typed_violations = per_file_shacl_violations(good_files, SHAPES_PATH, real_context, retype=retype_map)
+
+ per_file = {
+ "asPublishedTriples": per_file_published,
+ "withObservedBindingViolations": {k: v["violations"] for k, v in per_file_observed_violations.items()},
+ "withRealContextTypedViolations": {k: v["violations"] for k, v in per_file_real_typed_violations.items()},
+ }
+
result = {
"measured": "2026-08-25, this repository, no network, no model call",
"commit": COMMIT_SHA,
@@ -591,6 +667,7 @@ def main() -> int:
"recoveredFilesOrgPrefixTypoImpactDiagnosticOnly": org_prefix_impact,
"lenientTermCount": len(lenient_terms),
"lenientTerms": sorted(lenient_terms),
+ "perFile": per_file,
"examples": {
"asPublished": as_published,
"withDeclaredBinding": with_declared,
diff --git a/demo/dcat_conformance_measurements.json b/demo/dcat_conformance_measurements.json
index 143b9149..b345fabb 100644
--- a/demo/dcat_conformance_measurements.json
+++ b/demo/dcat_conformance_measurements.json
@@ -549,6 +549,359 @@
"unitMeasure"
],
"measured": "2026-08-25, this repository, no network, no model call",
+ "perFile": {
+ "asPublishedTriples": {
+ "AccessRestriction/good/minimal_example.json": 0,
+ "AccessRestriction/good/null_example.json": 0,
+ "AccessRestriction/good/typical_example.json": 1,
+ "Activity/good/complete_example.json": 1,
+ "Activity/good/minimal_example.json": 0,
+ "Activity/good/null_example.json": 0,
+ "Activity/good/typical_example.json": 1,
+ "Address/good/complete_example.json": 1,
+ "Address/good/minimal_example.json": 1,
+ "Address/good/null_example.json": 0,
+ "Address/good/typical_example.json": 1,
+ "Agent/good/complete_example.json": 1,
+ "Agent/good/minimal_example.json": 0,
+ "Agent/good/null_example.json": 0,
+ "Agent/good/simple_category_example.json": 1,
+ "Agent/good/typical_example.json": 1,
+ "Attribution/good/complete_example.json": 1,
+ "Attribution/good/minimal_example.json": 0,
+ "Attribution/good/typical_example.json": 1,
+ "CUIRestriction/good/complete_example.json": 1,
+ "CUIRestriction/good/minimal_example.json": 1,
+ "CUIRestriction/good/null_example.json": 0,
+ "CUIRestriction/good/typical_example.json": 1,
+ "Catalog/good/complete_example.json": 1,
+ "Catalog/good/minimal_example.json": 1,
+ "Catalog/good/typical_example.json": 1,
+ "CatalogRecord/good/complete_example.json": 1,
+ "CatalogRecord/good/minimal_example.json": 0,
+ "CatalogRecord/good/typical_example.json": 1,
+ "Checksum/good/complete_example.json": 1,
+ "Checksum/good/minimal_example.json": 1,
+ "Checksum/good/null_example.json": 0,
+ "Checksum/good/typical_example.json": 1,
+ "Concept/good/complete_example.json": 1,
+ "Concept/good/minimal_object.json": 1,
+ "Concept/good/null_example.json": 0,
+ "Concept/good/typical_example.json": 1,
+ "ConceptScheme/good/complete_example.json": 1,
+ "ConceptScheme/good/minimal_example.json": 1,
+ "ConceptScheme/good/null_example.json": 0,
+ "ConceptScheme/good/typical_example.json": 1,
+ "DataService/good/complete_example.json": 1,
+ "DataService/good/minimal_example.json": 0,
+ "DataService/good/null_example.json": 0,
+ "DataService/good/typical_example.json": 1,
+ "Dataset/good/complete_example.json": 1,
+ "Dataset/good/comprehensive-dataset.json": 1,
+ "Dataset/good/good-accrual-periodicity.json": 1,
+ "Dataset/good/minimal_example.json": 0,
+ "Dataset/good/null_example.json": 0,
+ "Dataset/good/theme_full_example.json": 1,
+ "Dataset/good/theme_simple_example.json": 1,
+ "Dataset/good/typical_example.json": 1,
+ "DatasetSeries/good/complete_example.json": 1,
+ "DatasetSeries/good/good-accrual-periodicity.json": 1,
+ "DatasetSeries/good/minimal_example.json": 0,
+ "DatasetSeries/good/null_example.json": 0,
+ "DatasetSeries/good/typical_example.json": 1,
+ "Distribution/good/complete_example.json": 1,
+ "Distribution/good/minimal_example.json": 0,
+ "Distribution/good/null_example.json": 0,
+ "Distribution/good/typical_example.json": 1,
+ "Document/good/complete_example.json": 1,
+ "Document/good/minimal_example.json": 0,
+ "Document/good/null_example.json": 0,
+ "Document/good/typical_example.json": 1,
+ "Identifier/good/complete_example.json": 1,
+ "Identifier/good/minimal_object_example.json": 0,
+ "Identifier/good/minimal_string_example.json": 0,
+ "Identifier/good/null_example.json": 0,
+ "Identifier/good/typical_example.json": 1,
+ "Kind/good/complete_example.json": 1,
+ "Kind/good/minimal_example.json": 0,
+ "Kind/good/null_example.json": 0,
+ "Kind/good/typical_example.json": 1,
+ "Location/good/bbox_geojson.json": 1,
+ "Location/good/bbox_wkt.json": 1,
+ "Location/good/centroid_geojson.json": 1,
+ "Location/good/complete_example.json": 1,
+ "Location/good/geometry_geojson.json": 1,
+ "Location/good/identifier_iri_reference.json": 1,
+ "Location/good/minimal_example.json": 1,
+ "Location/good/null_example.json": 0,
+ "Location/good/typical_example.json": 1,
+ "Metric/good/complete_example.json": 1,
+ "Metric/good/minimal_example.json": 1,
+ "Metric/good/null_example.json": 0,
+ "Metric/good/typical_example.json": 1,
+ "Organization/good/complete_example.json": 1,
+ "Organization/good/minimal_example.json": 1,
+ "Organization/good/null_example.json": 0,
+ "Organization/good/typical_example.json": 1,
+ "PeriodOfTime/good/complete_example.json": 1,
+ "PeriodOfTime/good/minimal_example_end_date_only.json": 1,
+ "PeriodOfTime/good/minimal_example_start_date_only.json": 1,
+ "PeriodOfTime/good/null_example.json": 0,
+ "PeriodOfTime/good/typical_example.json": 1,
+ "PeriodOfTime/good/year_month_example.json": 1,
+ "PeriodOfTime/good/year_only_example.json": 1,
+ "QualityMeasurement/good/complete_example.json": 1,
+ "QualityMeasurement/good/minimal_example.json": 0,
+ "QualityMeasurement/good/null_example.json": 0,
+ "QualityMeasurement/good/typical_example.json": 1,
+ "Relationship/good/complete_example.json": 1,
+ "Relationship/good/minimal_example.json": 1,
+ "Relationship/good/null_example.json": 0,
+ "Relationship/good/typical_example.json": 1,
+ "Standard/good/complete_example.json": 1,
+ "Standard/good/minimal_example.json": 0,
+ "Standard/good/null_example.json": 0,
+ "Standard/good/typical_example.json": 1,
+ "UseRestriction/good/complete_example.json": 1,
+ "UseRestriction/good/minimal_example.json": 0,
+ "UseRestriction/good/null_example.json": 0,
+ "UseRestriction/good/typical_example.json": 1
+ },
+ "withObservedBindingViolations": {
+ "AccessRestriction/good/minimal_example.json": 0,
+ "AccessRestriction/good/null_example.json": 0,
+ "AccessRestriction/good/typical_example.json": 1,
+ "Activity/good/complete_example.json": 0,
+ "Activity/good/minimal_example.json": 0,
+ "Activity/good/null_example.json": 0,
+ "Activity/good/typical_example.json": 1,
+ "Address/good/complete_example.json": 0,
+ "Address/good/minimal_example.json": 0,
+ "Address/good/null_example.json": 0,
+ "Address/good/typical_example.json": 0,
+ "Agent/good/complete_example.json": 1,
+ "Agent/good/minimal_example.json": 0,
+ "Agent/good/null_example.json": 0,
+ "Agent/good/simple_category_example.json": 1,
+ "Agent/good/typical_example.json": 1,
+ "Attribution/good/complete_example.json": 1,
+ "Attribution/good/minimal_example.json": 0,
+ "Attribution/good/typical_example.json": 2,
+ "CUIRestriction/good/complete_example.json": 0,
+ "CUIRestriction/good/minimal_example.json": 0,
+ "CUIRestriction/good/null_example.json": 0,
+ "CUIRestriction/good/typical_example.json": 0,
+ "Catalog/good/complete_example.json": 19,
+ "Catalog/good/minimal_example.json": 2,
+ "Catalog/good/typical_example.json": 2,
+ "CatalogRecord/good/complete_example.json": 5,
+ "CatalogRecord/good/minimal_example.json": 0,
+ "CatalogRecord/good/typical_example.json": 3,
+ "Checksum/good/complete_example.json": 1,
+ "Checksum/good/minimal_example.json": 1,
+ "Checksum/good/null_example.json": 0,
+ "Checksum/good/typical_example.json": 1,
+ "Concept/good/complete_example.json": 0,
+ "Concept/good/minimal_object.json": 1,
+ "Concept/good/null_example.json": 0,
+ "Concept/good/typical_example.json": 0,
+ "ConceptScheme/good/complete_example.json": 3,
+ "ConceptScheme/good/minimal_example.json": 0,
+ "ConceptScheme/good/null_example.json": 0,
+ "ConceptScheme/good/typical_example.json": 1,
+ "DataService/good/complete_example.json": 14,
+ "DataService/good/minimal_example.json": 0,
+ "DataService/good/null_example.json": 0,
+ "DataService/good/typical_example.json": 3,
+ "Dataset/good/complete_example.json": 35,
+ "Dataset/good/comprehensive-dataset.json": 33,
+ "Dataset/good/good-accrual-periodicity.json": 4,
+ "Dataset/good/minimal_example.json": 0,
+ "Dataset/good/null_example.json": 0,
+ "Dataset/good/theme_full_example.json": 2,
+ "Dataset/good/theme_simple_example.json": 4,
+ "Dataset/good/typical_example.json": 13,
+ "DatasetSeries/good/complete_example.json": 17,
+ "DatasetSeries/good/good-accrual-periodicity.json": 1,
+ "DatasetSeries/good/minimal_example.json": 0,
+ "DatasetSeries/good/null_example.json": 0,
+ "DatasetSeries/good/typical_example.json": 18,
+ "Distribution/good/complete_example.json": 14,
+ "Distribution/good/minimal_example.json": 0,
+ "Distribution/good/null_example.json": 0,
+ "Distribution/good/typical_example.json": 6,
+ "Document/good/complete_example.json": 6,
+ "Document/good/minimal_example.json": 0,
+ "Document/good/null_example.json": 0,
+ "Document/good/typical_example.json": 3,
+ "Identifier/good/complete_example.json": 2,
+ "Identifier/good/minimal_object_example.json": 0,
+ "Identifier/good/minimal_string_example.json": 0,
+ "Identifier/good/null_example.json": 0,
+ "Identifier/good/typical_example.json": 0,
+ "Kind/good/complete_example.json": 1,
+ "Kind/good/minimal_example.json": 0,
+ "Kind/good/null_example.json": 0,
+ "Kind/good/typical_example.json": 1,
+ "Location/good/bbox_geojson.json": 2,
+ "Location/good/bbox_wkt.json": 1,
+ "Location/good/centroid_geojson.json": 2,
+ "Location/good/complete_example.json": 7,
+ "Location/good/geometry_geojson.json": 2,
+ "Location/good/identifier_iri_reference.json": 1,
+ "Location/good/minimal_example.json": 0,
+ "Location/good/null_example.json": 0,
+ "Location/good/typical_example.json": 1,
+ "Metric/good/complete_example.json": 2,
+ "Metric/good/minimal_example.json": 2,
+ "Metric/good/null_example.json": 0,
+ "Metric/good/typical_example.json": 2,
+ "Organization/good/complete_example.json": 1,
+ "Organization/good/minimal_example.json": 1,
+ "Organization/good/null_example.json": 0,
+ "Organization/good/typical_example.json": 1,
+ "PeriodOfTime/good/complete_example.json": 2,
+ "PeriodOfTime/good/minimal_example_end_date_only.json": 1,
+ "PeriodOfTime/good/minimal_example_start_date_only.json": 1,
+ "PeriodOfTime/good/null_example.json": 0,
+ "PeriodOfTime/good/typical_example.json": 2,
+ "PeriodOfTime/good/year_month_example.json": 2,
+ "PeriodOfTime/good/year_only_example.json": 1,
+ "QualityMeasurement/good/complete_example.json": 3,
+ "QualityMeasurement/good/minimal_example.json": 0,
+ "QualityMeasurement/good/null_example.json": 0,
+ "QualityMeasurement/good/typical_example.json": 2,
+ "Relationship/good/complete_example.json": 2,
+ "Relationship/good/minimal_example.json": 2,
+ "Relationship/good/null_example.json": 0,
+ "Relationship/good/typical_example.json": 2,
+ "Standard/good/complete_example.json": 2,
+ "Standard/good/minimal_example.json": 0,
+ "Standard/good/null_example.json": 0,
+ "Standard/good/typical_example.json": 2,
+ "UseRestriction/good/complete_example.json": 0,
+ "UseRestriction/good/minimal_example.json": 0,
+ "UseRestriction/good/null_example.json": 0,
+ "UseRestriction/good/typical_example.json": 1
+ },
+ "withRealContextTypedViolations": {
+ "AccessRestriction/good/minimal_example.json": 0,
+ "AccessRestriction/good/null_example.json": 0,
+ "AccessRestriction/good/typical_example.json": 0,
+ "Activity/good/complete_example.json": 0,
+ "Activity/good/minimal_example.json": 0,
+ "Activity/good/null_example.json": 0,
+ "Activity/good/typical_example.json": 0,
+ "Address/good/complete_example.json": 0,
+ "Address/good/minimal_example.json": 0,
+ "Address/good/null_example.json": 0,
+ "Address/good/typical_example.json": 0,
+ "Agent/good/complete_example.json": 1,
+ "Agent/good/minimal_example.json": 0,
+ "Agent/good/null_example.json": 0,
+ "Agent/good/simple_category_example.json": 0,
+ "Agent/good/typical_example.json": 0,
+ "Attribution/good/complete_example.json": 0,
+ "Attribution/good/minimal_example.json": 0,
+ "Attribution/good/typical_example.json": 1,
+ "CUIRestriction/good/complete_example.json": 0,
+ "CUIRestriction/good/minimal_example.json": 0,
+ "CUIRestriction/good/null_example.json": 0,
+ "CUIRestriction/good/typical_example.json": 0,
+ "Catalog/good/complete_example.json": 0,
+ "Catalog/good/minimal_example.json": 0,
+ "Catalog/good/typical_example.json": 0,
+ "CatalogRecord/good/complete_example.json": 2,
+ "CatalogRecord/good/minimal_example.json": 0,
+ "CatalogRecord/good/typical_example.json": 2,
+ "Checksum/good/complete_example.json": 0,
+ "Checksum/good/minimal_example.json": 0,
+ "Checksum/good/null_example.json": 0,
+ "Checksum/good/typical_example.json": 0,
+ "Concept/good/complete_example.json": 0,
+ "Concept/good/minimal_object.json": 1,
+ "Concept/good/null_example.json": 0,
+ "Concept/good/typical_example.json": 0,
+ "ConceptScheme/good/complete_example.json": 3,
+ "ConceptScheme/good/minimal_example.json": 0,
+ "ConceptScheme/good/null_example.json": 0,
+ "ConceptScheme/good/typical_example.json": 1,
+ "DataService/good/complete_example.json": 8,
+ "DataService/good/minimal_example.json": 0,
+ "DataService/good/null_example.json": 0,
+ "DataService/good/typical_example.json": 3,
+ "Dataset/good/complete_example.json": 15,
+ "Dataset/good/comprehensive-dataset.json": 17,
+ "Dataset/good/good-accrual-periodicity.json": 2,
+ "Dataset/good/minimal_example.json": 0,
+ "Dataset/good/null_example.json": 0,
+ "Dataset/good/theme_full_example.json": 2,
+ "Dataset/good/theme_simple_example.json": 2,
+ "Dataset/good/typical_example.json": 8,
+ "DatasetSeries/good/complete_example.json": 15,
+ "DatasetSeries/good/good-accrual-periodicity.json": 0,
+ "DatasetSeries/good/minimal_example.json": 0,
+ "DatasetSeries/good/null_example.json": 0,
+ "DatasetSeries/good/typical_example.json": 17,
+ "Distribution/good/complete_example.json": 5,
+ "Distribution/good/minimal_example.json": 0,
+ "Distribution/good/null_example.json": 0,
+ "Distribution/good/typical_example.json": 2,
+ "Document/good/complete_example.json": 3,
+ "Document/good/minimal_example.json": 0,
+ "Document/good/null_example.json": 0,
+ "Document/good/typical_example.json": 2,
+ "Identifier/good/complete_example.json": 1,
+ "Identifier/good/minimal_object_example.json": 0,
+ "Identifier/good/minimal_string_example.json": 0,
+ "Identifier/good/null_example.json": 0,
+ "Identifier/good/typical_example.json": 0,
+ "Kind/good/complete_example.json": 0,
+ "Kind/good/minimal_example.json": 0,
+ "Kind/good/null_example.json": 0,
+ "Kind/good/typical_example.json": 0,
+ "Location/good/bbox_geojson.json": 2,
+ "Location/good/bbox_wkt.json": 1,
+ "Location/good/centroid_geojson.json": 2,
+ "Location/good/complete_example.json": 7,
+ "Location/good/geometry_geojson.json": 2,
+ "Location/good/identifier_iri_reference.json": 1,
+ "Location/good/minimal_example.json": 0,
+ "Location/good/null_example.json": 0,
+ "Location/good/typical_example.json": 1,
+ "Metric/good/complete_example.json": 0,
+ "Metric/good/minimal_example.json": 0,
+ "Metric/good/null_example.json": 0,
+ "Metric/good/typical_example.json": 0,
+ "Organization/good/complete_example.json": 0,
+ "Organization/good/minimal_example.json": 0,
+ "Organization/good/null_example.json": 0,
+ "Organization/good/typical_example.json": 0,
+ "PeriodOfTime/good/complete_example.json": 2,
+ "PeriodOfTime/good/minimal_example_end_date_only.json": 1,
+ "PeriodOfTime/good/minimal_example_start_date_only.json": 1,
+ "PeriodOfTime/good/null_example.json": 0,
+ "PeriodOfTime/good/typical_example.json": 2,
+ "PeriodOfTime/good/year_month_example.json": 2,
+ "PeriodOfTime/good/year_only_example.json": 1,
+ "QualityMeasurement/good/complete_example.json": 0,
+ "QualityMeasurement/good/minimal_example.json": 0,
+ "QualityMeasurement/good/null_example.json": 0,
+ "QualityMeasurement/good/typical_example.json": 1,
+ "Relationship/good/complete_example.json": 0,
+ "Relationship/good/minimal_example.json": 0,
+ "Relationship/good/null_example.json": 0,
+ "Relationship/good/typical_example.json": 0,
+ "Standard/good/complete_example.json": 4,
+ "Standard/good/minimal_example.json": 0,
+ "Standard/good/null_example.json": 0,
+ "Standard/good/typical_example.json": 2,
+ "UseRestriction/good/complete_example.json": 0,
+ "UseRestriction/good/minimal_example.json": 0,
+ "UseRestriction/good/null_example.json": 0,
+ "UseRestriction/good/typical_example.json": 0
+ }
+ },
"realContextBaseCommit": "04acd5c25579dd70a86a436b30a33e0784965cc4",
"realContextBindsConceptProperties": [
"altLabel",
diff --git a/demo/precomputed/findings.json b/demo/precomputed/findings.json
index 77301428..5e7b58c5 100644
--- a/demo/precomputed/findings.json
+++ b/demo/precomputed/findings.json
@@ -49,7 +49,7 @@
{
"document": "jsonschema/definitions/Dataset.json",
"predicate": "measuredAsPublished",
- "object": "115 files expand to 76 triples total, 1 distinct predicate (rdf:type), 0 dcat: triples, 38 files empty, 1 parse error (demo/dcat_conformance.py, no context)"
+ "object": "115 files expand to 76 triples total (summed per file, demo/dcat_conformance_measurements.json's examples.asPublished.triples; merged into one graph, exact-duplicate triples across files collapse to 73, corpusTriples.asPublished), 1 distinct predicate (rdf:type), 0 dcat: triples, 38 files empty, 1 file whose root is not a JSON object -- not a parse error, the JSON itself is valid: jsonschema/examples/Identifier/good/minimal_string_example.json's entire content is the JSON string \"dataset-12345\" (demo/dcat_conformance.py, no context)"
},
{
"document": "recovered-shapes.ttl",
diff --git a/demo/tests/test_dcat_conformance.py b/demo/tests/test_dcat_conformance.py
index 8f64059c..7d0878b7 100644
--- a/demo/tests/test_dcat_conformance.py
+++ b/demo/tests/test_dcat_conformance.py
@@ -28,6 +28,8 @@ from demo.dcat_conformance import (
load_shapes_namespaces,
measure,
merge_corpus,
+ per_file_shacl_violations,
+ per_file_triples,
run_shacl,
scan_bare_values,
title_to_rdf_class,
@@ -174,6 +176,54 @@ def test_shacl_violation_counts_disagree_across_methods():
assert len(counts) == 3
+def test_per_file_figures_quoted_in_findings_json_are_reproducible():
+ """demo/precomputed/findings.json quotes per-file triple and violation
+ counts for specific example files (findings 1, 3 and 5). Those numbers
+ must be exactly what per_file_triples() / per_file_shacl_violations()
+ compute, not hand-typed approximations: this test is the thing a
+ sceptical reader runs to check them.
+ """
+ classes = load_classes(DEFINITIONS)
+ namespaces = load_shapes_namespaces(SHAPES_PATH)
+ files = _good_files()
+ lenient_terms = scan_bare_values(files, classes)
+ observed = build_context(classes, namespaces, lenient_terms=lenient_terms)
+ real_context = load_real_context(REAL_CONTEXT_PATH)
+ retype_map = title_to_rdf_class(classes)
+
+ as_published = per_file_triples(files, None)
+ # Finding 1: Catalog and Dataset each expand to 1 triple as published
+ # (rdf:type of a manufactured IRI, no @context).
+ assert as_published["Catalog/good/complete_example.json"] == 1
+ assert as_published["Dataset/good/complete_example.json"] == 1
+
+ observed_violations = per_file_shacl_violations(files, SHAPES_PATH, observed)
+ real_typed_violations = per_file_shacl_violations(files, SHAPES_PATH, real_context, retype=retype_map)
+
+ # Finding 5: firesViolations, observed binding vs. real context typed.
+ assert observed_violations["Dataset/good/complete_example.json"]["violations"] == 35
+ assert real_typed_violations["Dataset/good/complete_example.json"]["violations"] == 15
+ assert observed_violations["Catalog/good/complete_example.json"]["violations"] == 19
+ assert real_typed_violations["Catalog/good/complete_example.json"]["violations"] == 0
+ assert observed_violations["Distribution/good/complete_example.json"]["violations"] == 14
+ assert real_typed_violations["Distribution/good/complete_example.json"]["violations"] == 5
+
+ # Finding 3: Concept/Identifier reachability under the real context.
+ assert real_typed_violations["Concept/good/complete_example.json"]["violations"] == 0
+ assert real_typed_violations["Concept/good/minimal_object.json"]["violations"] == 1
+ assert real_typed_violations["Identifier/good/complete_example.json"]["violations"] == 1
+
+
+def test_per_file_keys_are_unique_across_reused_filenames():
+ # "minimal_example.json", "null_example.json" and "typical_example.json"
+ # each recur under many classes' good/ directories. A per-file mapping
+ # keyed by bare filename would silently collide; keying by
+ # '<Class>/good/<file>' must not.
+ files = _good_files()
+ result = per_file_triples(files, None)
+ assert len(result) == len(files) == 115
+
+
def test_recovered_files_disagree_on_org_prefix():
# A defect internal to the two recovered files themselves, both deleted
# by the same pull request as part of the same profile release: they