vibe.review.parsing.rules.loader

Load rules from YAML files.

Rule YAML format:

rule_id: layout_header_detection
name: "Detect Page Headers"
layer: layout
priority: 100
match:
  predicates:
    # Inline Python expressions
    - "node.bbox.y0 / ctx.page_height < 0.12"
    - "len(node.text) < 100"
    # Or reference external functions
    - predicate_function: "is_repeated_header"
actions:
  - action: tag
    tag: page_header
provenance_note: "Detected as page header"

Predicate expressions are Python expressions with access to: - node: The node being evaluated - ctx: Additional context (page dimensions, helper functions) - re: The re module for regex operations

load_rules_from_yaml

load_rules_from_yaml(yaml_path: Path) -> list[Rule]

Load rules from a YAML file.

Parameters:
  • yaml_path (Path) –

    Path to YAML file.

Returns:

load_rules_from_directory

load_rules_from_directory(directory: Path) -> list[Rule]

Load all rules from YAML files in a directory.

Parameters:
  • directory (Path) –

    Directory containing YAML files.

Returns:
  • list[Rule]

    List of all Rule objects.

rules_to_yaml

rules_to_yaml(rules: list[Rule]) -> str

Convert rules to YAML string.

Parameters:
  • rules (list[Rule]) –

    List of Rule objects.

Returns:
  • str

    YAML string representation.