Class SchemaAlgebra

java.lang.Object
dev.omnist.algebra.SchemaAlgebra

public final class SchemaAlgebra extends Object
Normative Schema Algebra operations (§6 of 06-schema-algebra.md).
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Checks if every Document accepted by Schema A is also accepted by Schema B (§6.6).
    static List<List<String>>
    Group record names of schema into structural equivalence classes using partition refinement (§6.8).
    static boolean
    Checks if two Schemas accept the exact same set of Documents (§6.7).
    static Schema
    extract(Schema schema, Set<String> keep)
    extract(S, keep) - returns the minimal subschema that recognizes only Documents built from keep labels (§6.9).
    static Schema
    infer(List<Document> samples)
    Infers a schema from a list of sample documents (§6.10), rooted at "Root" with any-fallback disabled.
    static Schema
    infer(List<Document> samples, String rootName, boolean allowAny)
    Infers a schema from a list of sample documents (§6.10).
    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 to any because its samples mixed incompatible scalar kinds.
    static boolean
    isEmpty(Schema schema)
    Checks if a Schema accepts zero finite documents (§6.4).
    lint(Schema schema)
    lint(S) - diagnoses structural schema issues that compile fine but mean parts of the schema can never do anything (§6.11).
    static Schema
    normalize(Schema schema)
    normalize(S) - canonical minimal schema equivalent to S (§6.8).
    static Schema
    prune(Schema schema)
    Prunes a Schema into an equivalent schema with unreachable records and impossible fields removed (§6.5).
    static Set<String>
    Computes the set of record names in schema S that admit at least one finite document (§6.4).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • satisfiableSet

      public static Set<String> satisfiableSet(Schema schema)
      Computes the set of record names in schema S that admit at least one finite document (§6.4). Implements a least fixpoint computation.
    • isEmpty

      public static boolean isEmpty(Schema schema)
      Checks if a Schema accepts zero finite documents (§6.4). Returns true if the root record name is not in the satisfiable set.
    • prune

      public static Schema prune(Schema schema)
      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

      public static boolean compatibleWith(Schema a, Schema b)
      Checks if every Document accepted by Schema A is also accepted by Schema B (§6.6). Implements coinductive memoized subschema comparison.
    • equivalent

      public static boolean equivalent(Schema a, Schema b)
      Checks if two Schemas accept the exact same set of Documents (§6.7). Evaluates compatibleWith(A, B) && compatibleWith(B, A).
    • equivalenceClasses

      public static List<List<String>> equivalenceClasses(Schema schema)
      Group record names of schema into structural equivalence classes using partition refinement (§6.8). Operates directly on S.records().
    • normalize

      public static Schema normalize(Schema schema)
      normalize(S) - canonical minimal schema equivalent to S (§6.8).
    • extract

      public static Schema extract(Schema schema, Set<String> keep)
      extract(S, keep) - returns the minimal subschema that recognizes only Documents built from keep labels (§6.9).
    • lint

      public static List<LintFinding> lint(Schema schema)
      lint(S) - diagnoses structural schema issues that compile fine but mean parts of the schema can never do anything (§6.11).
    • infer

      public static Schema infer(List<Document> samples)
      Infers a schema from a list of sample documents (§6.10), rooted at "Root" with any-fallback disabled. Equivalent to infer(samples, "Root", false).
      Parameters:
      samples - the documents to infer from; must not be empty
      Returns:
      the inferred schema
      Throws:
      IllegalArgumentException - if samples is empty, or if a field's sample values mix incompatible scalar kinds and allowAny is disabled
    • infer

      public static Schema infer(List<Document> samples, String rootName, boolean allowAny)
      Infers a schema from a list of sample documents (§6.10). Equivalent to inferWithReport(samples, rootName, allowAny).schema(); discards the AnyFallback report that would explain each any-typed field's cause.
      Parameters:
      samples - the documents to infer from; must not be empty
      rootName - the name to give the inferred root record
      allowAny - if true, a field with sample values of more than one scalar kind is inferred as any instead of throwing
      Returns:
      the inferred schema
      Throws:
      IllegalArgumentException - if samples is empty, or if a field mixes incompatible scalar kinds and allowAny is false
    • 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 to any because its samples mixed incompatible scalar kinds.

      Per §6.10, inference performs no normalization and does not use any by default — any is only ever produced when allowAny is true and a genuine kind conflict was found.

      Parameters:
      samples - the documents to infer from; must not be empty
      rootName - the name to give the inferred root record
      allowAny - if true, a field with sample values of more than one scalar kind is inferred as any instead of throwing
      Returns:
      the inferred schema together with its AnyFallback report
      Throws:
      IllegalArgumentException - if samples is empty, or if a field mixes incompatible scalar kinds and allowAny is false