grammar-inference-engine/bex/__init__.py
tobjend 739000e8c6 feat: CRX refined — cluster-then-infer for tighter grammars
Standard CRX over-approximates when Hasse diagram is non-linear (24% of
RAGSAK packages). Cluster-then-infer groups sequences by (first, last,
length), infers per-cluster, picks largest cluster's grammar.

Results on RAGSAK:
  Avg max disjunction: 2.8 → 1.7 (39% tighter)
  Packages improved: 6/10

Tradeoff: cluster granularity (too coarse = over-approximation,
too fine = no generalization). Current: (first, last, length_bucket).

Exports crx_refined() and crx_with_confidence() from bex package.
20 new tests. All 199 tests pass.
2026-07-12 01:50:40 +02:00

31 lines
1.1 KiB
Python

"""
bex — Paper-faithful implementation of BEX inference algorithms.
Papers:
- Bex et al. 2010 (TODS): Inference of Concise Regular Expressions and DTDs
- Bex et al. 2010 (arXiv 1004.2372): Learning Deterministic Regular Expressions
Algorithms implemented:
TODS 2010: 2T-INF, REWRITE, RWR, RWR², RWR₀, CRX
arXiv 2010: iKoa, Disambiguate, rwr², iDRegEx
"""
from .soa import SOA
from .twotinf import build_soa
from .rwr0 import rwr0
from .crx import CRX
from .ikoa import ikoa
from .rwrsq import rwr_sq
from .idregex import idregex
from .kore import kOREInference, validate_k_ore
from .koa import KOA, build_complete_koa
from .expr import concat, disj, star, optional, alphabet, strip_k
from .marking import mark_koa
from .tokenizer import YAMLTokenizer
from .ensemble import infer_ensemble
from .template import generate_template
from .reduce import reduce_contexts, soa_distance, build_soa_with_support, minimize_contexts, reduce_and_infer
from .gbnf import to_gbnf, to_gbnf_with_rules
from .crx_refined import crx_refined, crx_with_confidence
__version__ = "0.2.0"