Skip to content

Book scan: ranked alternatives for edit-1 findings (mirror of #34, with QA fixes) - #41

Merged
Nathaniel-260 merged 3 commits into
mainfrom
mirror/pr34-alternatives
Nov 16, 2026
Merged

Nathaniel-260 merged 3 commits into
mainfrom
mirror/pr34-alternatives

Conversation

@Nathaniel-260

Copy link
Copy Markdown
Owner

Mirror of #34 (fork PR; CodeQL does not run on forks) plus QA fixes: alternatives anchored to the finding's own suggestion, tests for the MARGIN path and detector agreement, README notes on rerank cost. Merged with main (domain gate, extra lexicon, guard); conflicts resolved by keeping both sides.

🤖 Generated with Claude Code

mynim and others added 3 commits November 15, 2026 21:22
…ng words (off by default)

The edit-1 rule finds several common words one edit away from a rare word
and keeps only the best by word-level score; the same suggestion is then
made at every occurrence. `--alternatives N` lists, per occurrence, up to N
of the candidates that rule accepted, ranked by the bigram/trigram model of
the real-word check (realword.posterior) over the occurrence's neighbours,
counted in the --book-verify-ctx pass without the book's own rows. The
detector's first choice keeps first place unless the context prefers
another candidate by MARGIN (2.0 log10 odds). With no counts, no neighbour
or no candidate seen beside them, the detector's order is kept.
`--alt-rerank 1` makes the finding's suggestion follow that first place.

* core.edit1_scored / core.edit1_record: the edit-1 loop of evaluate_word,
  factored out unchanged (evaluate_word gives the same records).
* magiah/alternatives.py: candidates, needs, rank, reranked.
* book_scan: the alternatives' n-grams join the real-word counts of the
  same pass; findings get an `alternatives` field only when on.
* webui: merge_book_scan puts them in the finding's `extra`, which the
  drawer already shows as "הצעות חלופיות" (labels for the two new `by`
  values); Hebrew labels for the two settings; README (en/he).
* tests/test_alternatives.py.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	README.he.md
#	README.md
#	magiah/book_scan.py
#	magiah/cli.py
#	magiah/config.py
…s for MARGIN and detector agreement

- alternatives.anchor(): rank/rerank work relative to the suggestion the
  finding actually carries (by string), so a candidate-list mismatch can
  never be reported as a context rerank; no alternatives if it is absent.
  reranked() tolerates empty/missing candidates.
- alternatives.scores() factored out of rank() (same arithmetic).
- tests/test_alt_robust.py: fuzz over synthetic library and file books
  (detector suggestion == first candidate, invariants of plain and
  rerank scans); MARGIN with real n-gram counts on both sides, for the
  alternatives order and the --alt-rerank suggestion; mismatch tests.
- README: the 2.0 margin of --alt-rerank and its extra pair counting.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Nathaniel-260
Nathaniel-260 merged commit ea4190e into main Nov 16, 2026
13 checks passed
@Nathaniel-260
Nathaniel-260 deleted the mirror/pr34-alternatives branch November 16, 2026 21:32
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.

3 participants