Skip to content

Add KBMAG serialization for WordGraph - #16

Closed
james-d-mitchell wants to merge 1 commit into
codex/word-graph-kbmag-basefrom
codex/word-graph-kbmag
Closed

james-d-mitchell wants to merge 1 commit into
codex/word-graph-kbmag-basefrom
codex/word-graph-kbmag

Conversation

@james-d-mitchell

Copy link
Copy Markdown
Owner

Add a KBMAG interchange format that preserves the complete WordGraph transition table, including labels, missing transitions, isolated nodes, and unused labels. For example, edges (s, a, t) and (s, b, t) with different labels survive a round trip unchanged.

The new APIs provide:

  • word_graph::to_kbmag_string(graph, format) and word_graph::write_kbmag(output, graph, format), with dense deterministic or sparse output.
  • make<WordGraph<Node>>(text) and make<WordGraph<Node>>(input) for strings and streams.
  • Documented encoding and parsing algorithms, bounds checks, and diagnostics that identify the invalid field or value and the input line and column.

The writer converts node and label indices to KBMAG's one-based numbering and includes numTransitions. The reader processes one row at a time without building a second complete transition table. Nonempty graphs use initial := [1]; empty graphs use initial := []; all graphs use accepting := [].

Import supports the documented numeric subset: simple state and alphabet records, DFA flags, dense deterministic or sparse tables, comments, line continuations, and sparse defaults. Unsupported automaton semantics are rejected, including nonempty accepting lists, other initial states, nondeterminism, and external transition files. Additional metadata is skipped without evaluating GAP code.

Validation:

  • Built test_word_graph_io, test_word_graph, and test_word_graph_view; all 118 test cases selected by [quick] passed.
  • make doc-test: all 43 documentation examples passed.
  • make doc, documentation order/line-break checks, and generated umbrella-header checks passed. The documentation build reports existing unrelated warnings.
  • Pre-push formatting, lint, spelling, and generated-file checks passed for the changed files.
  • 24 round trips through KBMAG's fsafilter, covering both formats, empty graphs, and zero out-degree, preserved graph equality.
  • The full test suite was not run.

This PR targets codex/word-graph-kbmag-base, a snapshot of upstream commit 52d350f21170ed14b7f9409132746fdadeb10524, because this fork's main is behind that commit. The comparison contains only the KBMAG implementation commit.

AI assistance: OpenAI Codex implemented the code, documentation, and tests, performed validation, and prepared this pull request. The commit includes Codex co-author credit.

Read and write dense deterministic and sparse KBMAG records through
streams or strings. Preserve transition labels, undefined transitions,
parallel targets, isolated nodes, and the alphabet size. Use initial
state 1 for nonempty graphs and an empty accepting list.

Document the encoding and parsing algorithms and the supported numeric
KBMAG subset. Report invalid values, fields, sources, and input locations.
Include round-trip, malformed-input, stream, and documentation tests.

Validated the quick WordGraphIO, WordGraph, and WordGraphView suites,
documentation examples and build, pre-push hooks, and 24 round trips
through KBMAG's fsafilter in dense and sparse formats.

AI assistance: OpenAI Codex implemented the code, documentation, tests,
and commit message.

Co-authored-by: Codex OpenAI <codex@openai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant