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:
- For every record in the env, delete any field whose label is not in
keep. - 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. - 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. - If the root ends up invalidated, there is no valid subschema for this
keepset at all:extractreturns aSchemaErrornaming the first offending label and record. - 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::pruneandsuper::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
sthat only recognizes documents built from labels inkeep. Returns aSchemaErrorif deleting the other labels would invalidate the root record (see the module doc comment).