Class BlockSpecTextCodec

java.lang.Object
edu.cmu.tetrad.search.blocks.BlockSpecTextCodec

public final class BlockSpecTextCodec extends Object
Text codec for BlockSpec: - Supports LHS names with optional rank: L1, L1(2) - Validates duplicate block names (ERROR) - Warns if #index refers to a named variable (prefer name) - Preserves user-supplied names and ranks; does not reorder blocks - Sorts members within each block (stable) and removes within-line duplicates
  • Method Details

    • parse

      public static BlockSpecTextCodec.ParseResult parse(String text, DataSet ds)
      Parses an input textual representation of block specifications into a structured format.

      The input text is processed line-by-line to construct a block specification and validate the provided structure. Lines in the text that are either malformed, contain duplicates, or reference unknown variables are recorded as issues.

      Parameters:
      text - the input text defining the block specification
      ds - the dataset providing variable names and their corresponding indices
      Returns:
      a ParseResult record consisting of a constructed BlockSpec object and a list of encountered issues
    • format

      public static String format(BlockSpec spec)
      Formats the given BlockSpec object into a textual representation.

      Generates a string description of the block specification, including the names of variables and latent nodes, and their ranks. The format includes line-by-line grouping of variables associated with blocks, using the structure of the given BlockSpec object.

      Parameters:
      spec - the BlockSpec object to be formatted
      Returns:
      a string representing the formatted textual description of the block specification