from __future__ import annotations
import pathlib
import sys
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent))
from decode import BlockedDafsa
def main(argv: list[str]) -> int:
asset_dir = pathlib.Path(argv[1] if len(argv) >= 2 else ".")
if not (asset_dir / "block_index.json").exists():
sys.stderr.write(
f"no block_index.json in {asset_dir}; "
"pass the asset directory as the first argument\n"
)
return 2
bd = BlockedDafsa(asset_dir)
_, root_count, _, root_edges = bd._state(0)
total = 0
for label, target in sorted(root_edges):
_, count, _, _ = bd._state(target)
print(f"{label} {count}")
total += count
n_sequences = bd.manifest["n_sequences"]
print(f"# total {total}; manifest n_sequences {n_sequences}; root count {root_count}")
if total != n_sequences or root_count != n_sequences:
print("# MISMATCH: per-length counts do not sum to n_sequences")
return 1
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))