Skip to content

Graph-Native Infrastructure for Context and Accountable AI Systems

feat(standards): add machine-readable standards catalog (#2024) (#2066)

Parth Jadhav981a915177da
diff --git a/standards/catalog.yaml b/standards/catalog.yaml
new file mode 100644
index 00000000..815bf1fe
--- /dev/null
+++ b/standards/catalog.yaml
@@ -0,0 +1,77 @@
+---
+# Standards catalog: one machine-readable entry per standard Semantica leans on.
+#
+# This is an inventory, not a dependency list and not a mapping between
+# standards. Each entry records which standard the project consumes, the
+# version it consumes, the licence its reusable parts are available under, who
+# maintains it, how often it moves, where the source lives, and which module
+# in this repository does the consuming.
+#
+# Adding a standard: append an entry with every required field, then run
+# pytest -q tests/test_standards_catalog.py
+# The test fails when an entry is missing a field, so the catalog cannot rot
+# silently. Source-link reachability is checked when an entry is added
+# (SEMANTICA_TEST_STANDARDS_NETWORK=1 pytest -q tests/test_standards_catalog.py),
+# not by the default test run.
+#
+# Licence note: every standard listed here is a W3C Recommendation. All but
+# JSON-LD 1.1 use a version of the W3C Document License
+# (https://www.w3.org/copyright/); JSON-LD 1.1 uses the W3C Software and
+# Document License, 2015 version
+# (https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document).
+# The licence that applies to a particular copy is the one stated in that copy.
+
+catalog_version: 1
+
+standards:
+ - name: OWL 2
+ version: "2 (W3C Recommendation, 11 December 2012)"
+ license: W3C Document License
+ maintainer: W3C OWL Working Group
+ cadence: Stable since 2012; the OWL Working Group has closed, so no further revisions are planned.
+ source: https://www.w3.org/TR/owl2-overview/
+ consumed_by:
+ - semantica/ontology/owl_generator.py
+ - semantica/ontology/engine.py
+ - semantica/export/owl_exporter.py
+
+ - name: SHACL
+ version: "1.0 (W3C Recommendation, 20 July 2017)"
+ license: W3C Document License
+ maintainer: W3C RDF Data Shapes Working Group (RDF Data Shapes WG)
+ cadence: Stable since 2017; the working group has closed, so any revision arrives as a new Recommendation.
+ source: https://www.w3.org/TR/shacl/
+ consumed_by:
+ - semantica/ontology/ontology_generator.py
+ - semantica/ontology/ontology_validator.py
+ - semantica/ontology/engine.py
+
+ - name: RDF 1.1
+ version: "1.1 (W3C Recommendation, 25 February 2014)"
+ license: W3C Document License
+ maintainer: W3C RDF Working Group (RDF WG)
+ cadence: Stable since 2014; the RDF Working Group has closed, so no further revisions are planned.
+ source: https://www.w3.org/TR/rdf11-concepts/
+ consumed_by:
+ - semantica/export/rdf_exporter.py
+ - semantica/ingest/ontology_ingestor.py
+ - semantica/triplet_store/rdf4j_store.py
+
+ - name: JSON-LD 1.1
+ version: "1.1 (W3C Recommendation, 16 July 2020)"
+ license: W3C Software and Document License (2015)
+ maintainer: W3C JSON-LD Working Group (JSON-LD WG)
+ cadence: Stable since 2020; the JSON-LD Working Group has closed, so no further revisions are planned.
+ source: https://www.w3.org/TR/json-ld11/
+ consumed_by:
+ - semantica/export/json_exporter.py
+ - semantica/export/rdf_exporter.py
+
+ - name: PROV-O
+ version: "1.0 (W3C Recommendation, 30 April 2013)"
+ license: W3C Document License
+ maintainer: W3C Provenance Working Group (PROV WG)
+ cadence: Stable since 2013; the Provenance Working Group has closed, so no further revisions are planned.
+ source: https://www.w3.org/TR/prov-o/
+ consumed_by:
+ - semantica/provenance/manager.py
diff --git a/tests/test_standards_catalog.py b/tests/test_standards_catalog.py
new file mode 100644
index 00000000..9e39f2aa
--- /dev/null
+++ b/tests/test_standards_catalog.py
@@ -0,0 +1,165 @@
+"""The standards catalog must stay complete and machine-readable (#2024).
+
+``standards/catalog.yaml`` is the static inventory of the standards Semantica
+leans on. The rules it has to satisfy live here so an entry cannot quietly
+lose a field:
+
+- the file parses as YAML and holds a non-empty list of entries;
+- every entry carries name, version, license, maintainer, cadence, source and
+ consumed_by;
+- entry names are unique;
+- ``source`` is an http(s) URL;
+- every module named in ``consumed_by`` still exists in this repository.
+
+Source-link reachability needs the network, so it is opt-in and never part of
+the default run:
+
+ SEMANTICA_TEST_STANDARDS_NETWORK=1 pytest -q tests/test_standards_catalog.py
+"""
+
+import os
+from pathlib import Path
+
+import pytest
+import yaml
+
+ROOT = Path(__file__).resolve().parent.parent
+CATALOG = ROOT / "standards" / "catalog.yaml"
+
+#: Fields every entry must carry as a non-empty string.
+REQUIRED_TEXT_FIELDS = (
+ "name",
+ "version",
+ "license",
+ "maintainer",
+ "cadence",
+ "source",
+)
+#: Fields every entry must carry as a non-empty list of strings.
+REQUIRED_LIST_FIELDS = ("consumed_by",)
+
+
+def _load_catalog():
+ return yaml.safe_load(CATALOG.read_text(encoding="utf-8"))
+
+
+def _entry_problems(entry):
+ """Return the reasons ``entry`` is not a valid catalog entry.
+
+ The same function guards the real catalog and the meta-test below, so the
+ meta-test cannot pass while the real check has drifted into a no-op.
+ """
+ if not isinstance(entry, dict):
+ return [f"entry must be a mapping, got {type(entry).__name__}"]
+
+ problems = []
+ for field in REQUIRED_TEXT_FIELDS:
+ value = entry.get(field)
+ if not isinstance(value, str) or not value.strip():
+ problems.append(f"missing or empty field {field!r}")
+
+ source = entry.get("source")
+ if isinstance(source, str) and source.strip():
+ if not source.startswith(("http://", "https://")):
+ problems.append(f"source must be an http(s) URL, got {source!r}")
+
+ for field in REQUIRED_LIST_FIELDS:
+ value = entry.get(field)
+ if not isinstance(value, list) or not value:
+ problems.append(f"missing or empty field {field!r}")
+ elif not all(isinstance(item, str) and item.strip() for item in value):
+ problems.append(f"field {field!r} must list non-empty strings")
+
+ return problems
+
+
[email protected](scope="module")
+def catalog():
+ return _load_catalog()
+
+
[email protected](scope="module")
+def entries(catalog):
+ return catalog["standards"]
+
+
+def test_catalog_file_exists():
+ assert CATALOG.is_file(), f"{CATALOG} is missing"
+
+
+def test_catalog_parses_into_a_list_of_entries(catalog):
+ assert isinstance(catalog, dict), "the catalog must be a mapping"
+ standards = catalog.get("standards")
+ assert isinstance(standards, list), "'standards' must be a list"
+ assert standards, "the catalog must not be empty"
+
+
+def test_every_entry_carries_the_required_fields(entries):
+ for entry in entries:
+ problems = _entry_problems(entry)
+ assert not problems, (
+ f"catalog entry {entry.get('name', '<unnamed>')!r} is incomplete: "
+ + "; ".join(problems)
+ )
+
+
+def test_a_missing_field_is_reported(entries):
+ """A field that goes missing has to fail the check above, not pass it."""
+ complete = entries[0]
+ assert not _entry_problems(complete)
+
+ for field in REQUIRED_TEXT_FIELDS + REQUIRED_LIST_FIELDS:
+ broken = {k: v for k, v in complete.items() if k != field}
+ problems = _entry_problems(broken)
+ assert problems, f"dropping {field!r} went unreported"
+ assert any(field in problem for problem in problems), (
+ f"dropping {field!r} was reported as {problems!r}, which does not "
+ f"name the missing field"
+ )
+
+
+def test_entry_names_are_unique(entries):
+ names = [entry["name"] for entry in entries]
+ duplicates = {name for name in names if names.count(name) > 1}
+ assert not duplicates, f"duplicate catalog entries: {sorted(duplicates)}"
+
+
+def test_source_links_are_urls(entries):
+ for entry in entries:
+ assert entry["source"].startswith(("http://", "https://")), (
+ f"{entry['name']}: source must be an http(s) URL, "
+ f"got {entry['source']!r}"
+ )
+
+
+def test_consumed_by_modules_exist(entries):
+ for entry in entries:
+ for module in entry["consumed_by"]:
+ assert (ROOT / module).is_file(), (
+ f"{entry['name']}: consumed_by names {module}, which is not a "
+ f"file in this repository"
+ )
+
+
+ not os.environ.get("SEMANTICA_TEST_STANDARDS_NETWORK"),
+ reason="network check; set SEMANTICA_TEST_STANDARDS_NETWORK=1 to run it",
+)
+def test_source_links_are_reachable(entries):
+ import requests
+
+ for entry in entries:
+ response = requests.get(
+ entry["source"],
+ timeout=30,
+ allow_redirects=True,
+ stream=True,
+ headers={"User-Agent": "semantica-standards-catalog-check"},
+ )
+ try:
+ assert response.status_code == 200, (
+ f"{entry['name']}: {entry['source']} returned "
+ f"HTTP {response.status_code}"
+ )
+ finally:
+ response.close()