Package dev.omnist.algebra
Class SchemaAlgebra
java.lang.Object
dev.omnist.algebra.SchemaAlgebra
Normative Schema Algebra operations (§6 of 06-schema-algebra.md).
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleancompatibleWith(Schema a, Schema b) Checks if every Document accepted by Schema A is also accepted by Schema B (§6.6).equivalenceClasses(Schema schema) Group record names of schema into structural equivalence classes using partition refinement (§6.8).static booleanequivalent(Schema a, Schema b) Checks if two Schemas accept the exact same set of Documents (§6.7).static Schemaextract(S, keep) - returns the minimal subschema that recognizes only Documents built from keep labels (§6.9).static SchemaInfers a schema from a list of sample documents (§6.10), rooted at"Root"withany-fallback disabled.static SchemaInfers a schema from a list of sample documents (§6.10).static InferResultinferWithReport(List<Document> samples, String rootName, boolean allowAny) Infers a schema from a list of sample documents (§6.10), returning both the schema and a report of every field that fell back toanybecause its samples mixed incompatible scalar kinds.static booleanChecks if a Schema accepts zero finite documents (§6.4).static List<LintFinding> lint(S) - diagnoses structural schema issues that compile fine but mean parts of the schema can never do anything (§6.11).static Schemanormalize(S) - canonical minimal schema equivalent to S (§6.8).static SchemaPrunes a Schema into an equivalent schema with unreachable records and impossible fields removed (§6.5).satisfiableSet(Schema schema) Computes the set of record names in schema S that admit at least one finite document (§6.4).
-
Method Details
-
satisfiableSet
Computes the set of record names in schema S that admit at least one finite document (§6.4). Implements a least fixpoint computation. -
isEmpty
Checks if a Schema accepts zero finite documents (§6.4). Returns true if the root record name is not in the satisfiable set. -
prune
Prunes a Schema into an equivalent schema with unreachable records and impossible fields removed (§6.5). Preserves language equivalence (S and prune(S) accept identical Documents). -
compatibleWith
Checks if every Document accepted by Schema A is also accepted by Schema B (§6.6). Implements coinductive memoized subschema comparison. -
equivalent
Checks if two Schemas accept the exact same set of Documents (§6.7). EvaluatescompatibleWith(A, B) && compatibleWith(B, A). -
equivalenceClasses
Group record names of schema into structural equivalence classes using partition refinement (§6.8). Operates directly on S.records(). -
normalize
normalize(S) - canonical minimal schema equivalent to S (§6.8). -
extract
extract(S, keep) - returns the minimal subschema that recognizes only Documents built from keep labels (§6.9). -
lint
lint(S) - diagnoses structural schema issues that compile fine but mean parts of the schema can never do anything (§6.11). -
infer
Infers a schema from a list of sample documents (§6.10), rooted at"Root"withany-fallback disabled. Equivalent toinfer(samples, "Root", false).- Parameters:
samples- the documents to infer from; must not be empty- Returns:
- the inferred schema
- Throws:
IllegalArgumentException- ifsamplesis empty, or if a field's sample values mix incompatible scalar kinds andallowAnyis disabled
-
infer
Infers a schema from a list of sample documents (§6.10). Equivalent toinferWithReport(samples, rootName, allowAny).schema(); discards theAnyFallbackreport that would explain eachany-typed field's cause.- Parameters:
samples- the documents to infer from; must not be emptyrootName- the name to give the inferred root recordallowAny- iftrue, a field with sample values of more than one scalar kind is inferred asanyinstead of throwing- Returns:
- the inferred schema
- Throws:
IllegalArgumentException- ifsamplesis empty, or if a field mixes incompatible scalar kinds andallowAnyisfalse
-
inferWithReport
public static InferResult inferWithReport(List<Document> samples, String rootName, boolean allowAny) Infers a schema from a list of sample documents (§6.10), returning both the schema and a report of every field that fell back toanybecause its samples mixed incompatible scalar kinds.Per §6.10, inference performs no normalization and does not use
anyby default —anyis only ever produced whenallowAnyistrueand a genuine kind conflict was found.- Parameters:
samples- the documents to infer from; must not be emptyrootName- the name to give the inferred root recordallowAny- iftrue, a field with sample values of more than one scalar kind is inferred asanyinstead of throwing- Returns:
- the inferred schema together with its
AnyFallbackreport - Throws:
IllegalArgumentException- ifsamplesis empty, or if a field mixes incompatible scalar kinds andallowAnyisfalse
-