mirror of
https://github.com/hansjone/netx.git
synced 2026-10-17 06:10:58 +08:00
Add TextFSM rule tables as dual input to biz-state parsers.
Collectors apply RULE_KEYS (or index stems) into fsm_tables before normalize; parsers prefer FSM or hand-parse. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
24a1a853af
commit
02b8a7073b
25 changed files with 714 additions and 69 deletions
31
netx_api/biz_state/parsers/common/pipeline.py
Normal file
31
netx_api/biz_state/parsers/common/pipeline.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
"""Shared FSM-vs-hand helpers for biz_state parsers."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Callable, Mapping, Sequence
|
||||
|
||||
MapRowsFn = Callable[[list[dict[str, Any]]], list[dict[str, Any]]]
|
||||
HandFn = Callable[..., list[dict[str, Any]]]
|
||||
|
||||
|
||||
def prefer_fsm(
|
||||
fsm_tables: Mapping[str, list[dict[str, Any]]] | None,
|
||||
keys: Sequence[str],
|
||||
map_rows: MapRowsFn,
|
||||
hand_fn: HandFn,
|
||||
*,
|
||||
raw_text: str,
|
||||
**kw: Any,
|
||||
) -> list[dict[str, Any]]:
|
||||
"""Use the first non-empty FSM table (mapped); otherwise hand-parse raw_text."""
|
||||
tables = fsm_tables or {}
|
||||
for key in keys or ():
|
||||
k = str(key or "").strip()
|
||||
if not k:
|
||||
continue
|
||||
rows = tables.get(k) or []
|
||||
if rows:
|
||||
mapped = map_rows(rows)
|
||||
if mapped:
|
||||
return mapped
|
||||
return hand_fn(raw_text=raw_text, **kw)
|
||||
Loading…
Add table
Add a link
Reference in a new issue