grammar-inference-engine/bex/rwrsq.py
tobjend 7c00c6713d Initial commit: BEX-based grammar inference engine
- CRX: direct CHARE inference (Algorithm 7, TODS 2010)
- iDRegEx: k-ORE inference (Algorithm 4, arXiv 2010)
- RWR₀: SORE repair (Algorithm 6, TODS 2010)
- rwr²: k-ORE extraction (Algorithm 3, arXiv 2010)
- SOA, k-OA, iKoa, 2T-INF, Baum-Welch
- Ansible role grammar adapter
- Generic YAML key-path converter
- 28 tests, all passing
2026-07-01 08:01:16 +02:00

31 lines
639 B
Python

"""rwr² — Translate k-OA to k-ORE (Algorithm 3, arXiv 1004.2372).
rwr²(G):
1: compute a marking H of G
2: return strip(rwr²₁(H))
"""
import re
from .marking import mark_koa
from .rwr0 import rwr0
def strip(expr):
"""Remove k-ORE markers: a_i → a."""
return re.sub(r'_\d+', '', expr)
def rwr_sq(G):
"""
|———— Algorithm 3: rwr² ————|
Require: k-OA G
Ensure: k-ORE r with L(G) ⊆ L(r)
1: H ← marking of G
2: return strip(rwr²₁(H))
"""
H = mark_koa(G)
result = rwr0(H)
if result is None or result == '':
return None
return strip(result)