Skip to main content

Module extract

Module extract 

Source
Expand description

Subschema extraction (paper Algorithm 5, ExtractSubschema). Ported from ~/dev/omnist/omnist/ops/extract.py.

Given a schema and a set of permissible labels keep (the paper’s X'), produces the minimal subschema that recognizes only documents built from those labels.

Algorithm:

  1. For every record in the env, delete any field whose label is not in keep.
  2. If a deleted field had min >= 1 (mandatory), that record is invalidated – the paper’s “state removed”: there is no way to build a document at that record’s shape without a label that’s no longer available.
  3. Propagate. A record with a mandatory field whose type is an invalidated record is itself invalidated, and so on transitively – a least-fixpoint closure, same shape as super::prune’s satisfiability fixpoint.
  4. If the root ends up invalidated, there is no valid subschema for this keep set at all: extract returns a SchemaError naming the first offending label and record.
  5. Otherwise, invalidated records (and fields typed to them, along with any fields already dropped in step 1) are gone; the result is run through super::prune::prune and super::minimize::normalize (Algorithm 5’s own final MakeUseful + Minimize step).

Design decision: mandatory deletion is an error, not silently-optional – matching the Python reference. Silently loosening a deleted mandatory field to optional would mean the result no longer reflects Algorithm 5’s semantics, and would more often hide a mistake in the caller’s keep set than express an intentional relaxation.

Functions§

extract
The minimal subschema of s that only recognizes documents built from labels in keep. Returns a SchemaError if deleting the other labels would invalidate the root record (see the module doc comment).