legislation

Provision retrieval and replay

Requires Python 3.11+ and SQLite with FTS5. All commands below run from the repository root. The catalogue can be searched before building any database.

python engine/legal.py search wayleaves
python engine/legal.py search 'ukpga/1989/29'
digest=$(python engine/legal.py bootstrap /tmp/legislation.sqlite)
python engine/legal.py terms /tmp/legislation.sqlite "$digest" 'necessary wayleave'
python engine/legal.py get /tmp/legislation.sqlite "$digest" schedule/4/paragraph/6
python engine/legal.py get /tmp/legislation.sqlite "$digest" schedule/4/paragraph/6/1 --xml
gzip -dc engine/electricity-1989-enacted.xml.gz > /tmp/act-1989.xml
python engine/benchmark.py /tmp/act-1989.xml 2026-11-28
python -m unittest discover -s engine

The source archive was fetched on 28 November 2026. Both the full archived XML and the exact paragraph excerpt contain public sector information licensed under the Open Government Licence v3.0. Source: Electricity Act 1989 as enacted, The National Archives / King’s Printer. For an independent online comparison, download that XML and check its SHA-256 against the receipt. Publisher changes require a new receipt and snapshot. The original record remains addressable.

Catalogue search recognises exact instrument IDs and titles, and offers keyword matches. Filters include --jurisdiction, --date (exact indexed metadata date) and --status. For captured XML, terms searches indexed provision words and returns up to 50 matches with context. The tool assigns each passage to its nearest enclosing publisher-identified unit. Exact lookups take the full source SHA-256 and a case-sensitive official structural path, including parts, chapters, sections, subsections, schedules and paragraphs where present. The empty path selects the root XML element. The source file SHA covers the full original file including material outside the root element. Byte fragments retain their original namespace context, so processors may need the enclosing document’s namespace declarations.

The database preserves original bytes and successive retrieval dates in a transaction. Re-importing identical bytes adds one observation per day. Source digest and provision identity are separate. New publisher bytes at the same URL receive a new digest. Ingestion rejects DTDs, duplicate structural identities, document identity mismatches and provision version mismatches. Retrieval verifies the fragment digest, returns the observed source identity and marks applicability unassessed. Legal commencement, territorial extent, amendments, exceptions and associated interpretation require separate evidence. A retrieval date or dated manifestation alone cannot establish applicability.

The benchmark reads a known official specimen and compares a full XML scan with one SQLite range read. Both paths return the exact checked-in paragraph bytes. The full scan verifies the source digest and searches the official structural attribute directly without building a database. The selective path verifies the result against the pre-built index. The receipt includes one-time build cost, SQLite storage, query CPU and peak allocations tracked by Python. It reports logical payload bytes. Page cache, SQLite native allocations, disk I/O, HTTP wire bytes during acquisition, development tokens, human time and energy were not measured. Replaying the archived specimen uses no network or AI. Benchmark timings are single observations and vary by host and cache state.

Dated and regnal sources

The engine accepts complete CLML document manifestations from their canonical publisher paths. The root identity, edition, each indexed provision URL and the publisher’s Atom self link must agree. An introduction, a metadata-only extract or a single section has a different self link and cannot be ingested as the whole Act. The historical UK Public General Act paths tested here include the regnal identifiers ukpga/Geo5/15-16/20 and ukpga/Eliz2/9-10/33. Calendar-year aliases may redirect to these official identities. Use the canonical URL when ingesting the resulting XML.

Independent dated receipts record the 1 January 2024 manifestations of the Electricity Act 1989, Law of Property Act 1925 and Land Compensation Act 1961. Each includes the complete source digest, selected provision digest, byte range, address count and retrieval date. For each receipt, download its document_url, run python engine/legal.py ingest STORE.sqlite DOWNLOADED.xml DOCUMENT_URL RETRIEVAL_DATE and pass the resulting digest and the recorded locator to python engine/legal.py get. The archived enacted Electricity Act remains a separate version. Every catalogue ID is also exercised by synthetic identity tests; that coverage describes recognised addresses rather than a capture of 47 complete instruments.