feat(spellcheck): spelling marks on the handwriting (#53 part 2) #59

Merged
jfro merged 23 commits from feat/53-ink-marks into main 2026-10-29 00:34:30 +00:00
Owner

Part of #53 (part 2: spelling marks on the handwriting). Based on main (#58 is merged).

Per reports/53-ink-build-plan.md:

  • Fixtures: two rmscene sample pages (MIT, notice kept) in test/support/fixtures/files/rmscene/.
  • Word boxes (Remarkable.Lines.WordBoxes): a page's strokes grouped into lines and words (i-dots and crossbars join their word, strikethroughs and heading underlines are rules that never weld words, the widest gaps are word breaks). Armstrong's audit F6/F7 fixed in 60db9e8.
  • Confidence gate + marks (Spellcheck.InkMarks): the transcription's Words.tokens lined up with the boxes in order; falls back (no marks, with a reason) on no ink, typed text, a drawing, a word count the ink can't make, unclear gaps (margin < 1.5) or uneven word widths. Hits on struck/illegible/unsure words and list markers are never marked. Logs each page's outcome with rm_hash, transcription id, numbers and ms.
  • Page view: an SVG over the page image, in the render's viewBox and scale, with a wavy line under each hit word (red spelling, blue grammar) and the message on hover. The panel says "Also marked on the page", or why it couldn't line up. Not on a backup's page or the "Now" compare page.
  • Ink check (Spellcheck.InkCheck): runs the gate on current handwritten transcriptions and prints each page's outcome and gap margin, the pass rate, the reasons and the margins' spread (read-only, no checker). From a checkout: mix spellcheck.ink_check [--user EMAIL] [--limit 50]; from a release: RmAnalyzer.Release.ink_check/1 (see Open).
  • Docs: docs/spellcheck.md, "On the handwriting".

Nothing is written to the tablet. No new deps.

Checked: mix precommit, 1002 tests pass (8bcce00). In Chromium on the mock app (scripts/screenshots) against a real LanguageTool, at 1280 and 390x844: on "Team meetings" p. 1 with "serch" and "notse" in the transcription, exactly those two words get marks (gate margin 2.01, 3 ms). On p. 3, whose drawn box around two lines isn't words, it falls back ("gaps aren't clear enough", margin 1.27) and marks only the text.

desktop p1
phone p1
desktop p3 fallback

Open:

  • OCR prompt v2 keeps the page's line breaks (d76ad72): one transcription line per handwritten line, so each ink line pins its own words. Markdown still renders it as one paragraph, and search, highlights and snippets read it the same way (wrapped phrases, ket-/tle and self-/aware line-end hyphens). Existing pages gain marks only after they're re-transcribed: v2 marks older AI transcriptions outdated, and re-running them stays the user's call. Migration 20261028190000 moves the transcription trigram index onto the rejoined-text expression (runs on app start).

  • Line margin is 1.3 (1a1b03c) so tightly spaced lines on real pages can be sure; word fit stays 0.6 (0.7 put words on the wrong box).

  • Gate margin 1.5 stays (Armstrong's audit at bde600b: no findings). rmscene's cursive multi-line sample scores 1.34 and gets no marks; that's now a test in ink_marks_test.exs. Retune on real notebooks (plan step 6).

  • Real-notebook pass rate needs Jeremy's data. It's read-only (SELECTs and blob reads only) and runs beside the app. On a running release (the Docker image built from this branch):

    # build the image from this branch
    docker build -t rm-analyzer:ink-marks .
    # in the running container (Docker / Compose)
    docker exec CONTAINER /app/bin/rm_analyzer eval 'RmAnalyzer.Release.ink_check(limit: 200)'
    # or on k3s
    kubectl exec -n NAMESPACE deploy/rm-analyzer -- /app/bin/rm_analyzer eval 'RmAnalyzer.Release.ink_check(limit: 200)'
    # one user only
    ... eval 'RmAnalyzer.Release.ink_check(user: "me@jeremyknope.com", limit: 200)'
    

    If the deployed app is still on main, the function isn't in it yet: run a one-off container of this branch's image against the same database and blob volume instead, e.g. docker run --rm --network host -e DATABASE_URL=... -e ENCRYPTION_KEY=... -e SECRET_KEY_BASE=... -e OIDC_ISSUER=... -e OIDC_CLIENT_ID=... -e OIDC_CLIENT_SECRET=... -v BLOBS:/data/remarkable/blobs:ro rm-analyzer:ink-marks /app/bin/rm_analyzer eval 'RmAnalyzer.Release.ink_check(limit: 200)' (runtime.exs wants the same env as the app).

    Tried that way on the mock notebooks (scripts/screenshots database, blobs mounted read-only): 24 pages, 11 line up (46%), 12 ambiguous_gaps, 1 uneven_widths; margins min 1.02, median 1.50, max 8.30. The mock pages are synthetic, so this says nothing yet about real handwriting.

Real handwriting (c116515)

Jeremy's real page fell back with count_mismatch. Slant, descender loops and t-bars make neighbouring words' boxes overlap in x, so words merge and there are too few gaps, or the gaps that are left fall inside words. When the plain box split runs short or isn't clear, WordBoxes now splits again: it shears out the measured slant, lets only words' own strokes make segments (dots and crossbars join the one they sit over), and as a second try measures strokes across the middle of the line only. The same gate applies (margin 1.5, word widths). A re-split with no gap left inside words is never used.

  • count_mismatch is now too_many_lines / too_few_gaps (panel + log, which also gives gaps and split). ink_check prints the split per page.
  • Synthetic slanted pages: 0/6 → 6/6 line up (plus 7 WordBoxes cases) (fixtures in test/support/fixtures/handwriting_fixtures.ex), every word on its own ink.
  • Mock screenshot pages: 11 → 15 of 24. The 4 new ones were checked visually, and every word sits on its own ink. rmscene Color_and_tool now lines up deslanted (1.86) with the same 7 boxes.
Part of #53 (part 2: spelling marks on the handwriting). Based on `main` (#58 is merged). Per `reports/53-ink-build-plan.md`: - **Fixtures**: two rmscene sample pages (MIT, notice kept) in `test/support/fixtures/files/rmscene/`. - **Word boxes** (`Remarkable.Lines.WordBoxes`): a page's strokes grouped into lines and words (i-dots and crossbars join their word, strikethroughs and heading underlines are rules that never weld words, the widest gaps are word breaks). Armstrong's audit F6/F7 fixed in 60db9e8. - **Confidence gate + marks** (`Spellcheck.InkMarks`): the transcription's `Words.tokens` lined up with the boxes in order; falls back (no marks, with a reason) on no ink, typed text, a drawing, a word count the ink can't make, unclear gaps (margin < 1.5) or uneven word widths. Hits on struck/illegible/unsure words and list markers are never marked. Logs each page's outcome with rm_hash, transcription id, numbers and ms. - **Page view**: an SVG over the page image, in the render's viewBox and scale, with a wavy line under each hit word (red spelling, blue grammar) and the message on hover. The panel says "Also marked on the page", or why it couldn't line up. Not on a backup's page or the "Now" compare page. - **Ink check** (`Spellcheck.InkCheck`): runs the gate on current handwritten transcriptions and prints each page's outcome and gap margin, the pass rate, the reasons and the margins' spread (read-only, no checker). From a checkout: `mix spellcheck.ink_check [--user EMAIL] [--limit 50]`; from a release: `RmAnalyzer.Release.ink_check/1` (see Open). - **Docs**: `docs/spellcheck.md`, "On the handwriting". Nothing is written to the tablet. No new deps. **Checked**: `mix precommit`, 1002 tests pass (8bcce00). In Chromium on the mock app (`scripts/screenshots`) against a real LanguageTool, at 1280 and 390x844: on "Team meetings" p. 1 with "serch" and "notse" in the transcription, exactly those two words get marks (gate margin 2.01, 3 ms). On p. 3, whose drawn box around two lines isn't words, it falls back ("gaps aren't clear enough", margin 1.27) and marks only the text. ![desktop p1](https://git.knope.dev/attachments/4f0ab8aa-e4b2-41af-bfba-f88d12e2520b) ![phone p1](https://git.knope.dev/attachments/11a8364a-ef14-4253-9011-d802b9f3d099) ![desktop p3 fallback](https://git.knope.dev/attachments/51573196-8cc7-4d06-aa64-a7e178daa886) **Open**: - **OCR prompt v2 keeps the page's line breaks** (d76ad72): one transcription line per handwritten line, so each ink line pins its own words. Markdown still renders it as one paragraph, and search, highlights and snippets read it the same way (wrapped phrases, `ket-`/`tle` and `self-`/`aware` line-end hyphens). **Existing pages gain marks only after they're re-transcribed**: v2 marks older AI transcriptions outdated, and re-running them stays the user's call. Migration `20261028190000` moves the transcription trigram index onto the rejoined-text expression (runs on app start). - Line margin is 1.3 (1a1b03c) so tightly spaced lines on real pages can be sure; word fit stays 0.6 (0.7 put words on the wrong box). - Gate margin 1.5 stays (Armstrong's audit at bde600b: no findings). rmscene's cursive multi-line sample scores 1.34 and gets no marks; that's now a test in `ink_marks_test.exs`. Retune on real notebooks (plan step 6). - Real-notebook pass rate needs Jeremy's data. It's read-only (SELECTs and blob reads only) and runs beside the app. On a running release (the Docker image built from this branch): ```sh # build the image from this branch docker build -t rm-analyzer:ink-marks . # in the running container (Docker / Compose) docker exec CONTAINER /app/bin/rm_analyzer eval 'RmAnalyzer.Release.ink_check(limit: 200)' # or on k3s kubectl exec -n NAMESPACE deploy/rm-analyzer -- /app/bin/rm_analyzer eval 'RmAnalyzer.Release.ink_check(limit: 200)' # one user only ... eval 'RmAnalyzer.Release.ink_check(user: "me@jeremyknope.com", limit: 200)' ``` If the deployed app is still on main, the function isn't in it yet: run a one-off container of this branch's image against the same database and blob volume instead, e.g. `docker run --rm --network host -e DATABASE_URL=... -e ENCRYPTION_KEY=... -e SECRET_KEY_BASE=... -e OIDC_ISSUER=... -e OIDC_CLIENT_ID=... -e OIDC_CLIENT_SECRET=... -v BLOBS:/data/remarkable/blobs:ro rm-analyzer:ink-marks /app/bin/rm_analyzer eval 'RmAnalyzer.Release.ink_check(limit: 200)'` (runtime.exs wants the same env as the app). Tried that way on the mock notebooks (`scripts/screenshots` database, blobs mounted read-only): 24 pages, 11 line up (46%), 12 `ambiguous_gaps`, 1 `uneven_widths`; margins min 1.02, median 1.50, max 8.30. The mock pages are synthetic, so this says nothing yet about real handwriting. ### Real handwriting (c116515) Jeremy's real page fell back with `count_mismatch`. Slant, descender loops and t-bars make neighbouring words' boxes overlap in x, so words merge and there are too few gaps, or the gaps that are left fall inside words. When the plain box split runs short or isn't clear, `WordBoxes` now splits again: it shears out the measured slant, lets only words' own strokes make segments (dots and crossbars join the one they sit over), and as a second try measures strokes across the middle of the line only. The same gate applies (margin 1.5, word widths). A re-split with no gap left inside words is never used. - `count_mismatch` is now `too_many_lines` / `too_few_gaps` (panel + log, which also gives gaps and split). `ink_check` prints the split per page. - Synthetic slanted pages: 0/6 → 6/6 line up (plus 7 WordBoxes cases) (fixtures in `test/support/fixtures/handwriting_fixtures.ex`), every word on its own ink. - Mock screenshot pages: 11 → 15 of 24. The 4 new ones were checked visually, and every word sits on its own ink. rmscene `Color_and_tool` now lines up deslanted (1.86) with the same 7 boxes.
Color_and_tool_v3.14.4.rm and With_SceneInfo_Block.rm from rmscene's
tests/data at d7d86ca (MIT, (c) 2023 Rick Lupton), with its LICENSE.
WordBoxes finds ink lines by y overlap (dots and crossbars join the line
they sit on, rules like strikethroughs never join words), merges strokes
that overlap in x, and cuts the page's widest gaps into the word count
wanted. Boxes on rmscene's samples match Armstrong's prototype.
A small flat stroke across two or more segments (below their top part,
so a T's crossbar over the e still joins) is a rule, whatever its width.
Drawn lines attach to the nearest line, without the i-dot reach that took
a heading's underline for the next line's. Armstrong's F6 and F7.
Spellcheck.InkMarks.locate/3 cuts the page's ink into as many word boxes
as the transcription has words and zips them in order; it falls back
(drawing, typed text, count mismatch, ambiguous gaps, uneven widths)
rather than guess. marks/4 puts a mark under each word a hit covers,
skipping struck, illegible, unsure words and list markers; squiggle/1
draws it. Logs the outcome with the page's numbers and duration.
A shown check's hits are drawn under their words on the handwriting too,
as an SVG in the render's own box and scale over the page image, with
each hit's message on hover. When the ink doesn't line up, the panel says
so (the reason in its title) and the marks stay on the text. Not on a
backup's page or the compare page.
feat(spellcheck): mix spellcheck.ink_check, to see how pages' ink lines up
All checks were successful
CI / test (pull_request) Successful in 1m27s
0868f7f6fb
Runs the ink marks' gate on current handwritten transcriptions and prints
each page's outcome, the pass rate and the reasons, without a checker or
writing anything, for tuning on real notebooks.
jfro added this to the v1.6.0 milestone 2026-10-27 03:23:18 +00:00
feat(spellcheck): ink check from a release, with gap margins
All checks were successful
CI / test (pull_request) Successful in 1m37s
8bcce0078f
RmAnalyzer.Release.ink_check/1 runs the same read-only check as
mix spellcheck.ink_check (now RmAnalyzer.Spellcheck.InkCheck), so it
works on a deployed app: bin/rm_analyzer eval
'RmAnalyzer.Release.ink_check(limit: 200)'. Both print each page's gap
margin and the margins' spread. InkMarks.diagnose/2 gives the gate's
outcome and numbers without logging.

Moves the cursive rmscene sample's fallback (margin 1.34) into
ink_marks_test.exs, from Armstrong's gate audit, and notes in InkMarks'
moduledoc that @gate_margin gets retuned on real notebooks.
jfro changed target branch from feat/53-spellcheck to main 2026-10-27 13:12:22 +00:00
jfro force-pushed feat/53-ink-marks from 8bcce0078f
All checks were successful
CI / test (pull_request) Successful in 1m37s
to f6cc6f035a
All checks were successful
CI / test (pull_request) Successful in 1m27s
2026-10-27 13:12:22 +00:00
Compare
fix(spellcheck): ink marks on slanted, run-together handwriting
All checks were successful
CI / test (pull_request) Successful in 1m36s
c116515504
On real handwriting the ink marks fell back with :count_mismatch: a slant,
descender loops and t-bars make neighbouring words' boxes overlap in x, so
whole words merge and there are too few gaps, or the gaps left are inside
words.

When the plain box split runs short or isn't clear, WordBoxes now splits
each line again: the page's slant (median angle of its downstrokes) is
sheared out, only words' own strokes make segments (dots, commas and
crossbars join the one they sit over), and a second try measures strokes
only across the middle of the line. The clearest re-split is used if it
passes the same gate (margin 1.5, word widths); one with no gap left
inside words is never used.

:count_mismatch is split into :too_many_lines and :too_few_gaps, in the
panel and the log (with gaps and the split used). InkCheck prints the
split. Synthetic slanted pages as fixtures; Color_and_tool now lines up
deslanted (1.86) with the same seven boxes. Mock pages: 11 -> 15 of 24.

Part of #53
A page that falls back can be found from its log line without going
through its blob hash.
On dense, slanted handwriting every split by gaps falls back: descenders
reach into the next line, so ink lines weld, and the gaps between
letters are as wide as the ones between words. Lines.InkAlign (split
:align) finds lines from the ink's profile down the page, shears the
slant out, measures gaps as horizontal runs across the line's middle,
and lines the words up over the lines by their letter widths with a
dynamic program. Only words it's sure of get a box: three runs at
different width weights agree, the breaks are clear, the line fits its
letters, and the width fits; a page passes when 75% are. Boxes drawn
round words are left out.

Mock pages: 15 to 24 of 24 line up, every box checked by eye on its own
word. A dense real page (34 lines, 183 words) went from too_few_gaps to
153 words marked.
A stroke joins the line whose core it overlaps (its strokes' median top
to median bottom), not the line's growing box, and dots and dashes attach
by core too (Armstrong's prototype). Re-splits take each stroke from the
line it was put on, measure the core band from the line's core, and level
each line by its own baseline tilt first.

Adds Armstrong's synthetic cursive audit test: 36 of 36 pages line up
(12 before), all 24 close/tight-line pages find their 4 lines (0 before).
With no gap left inside words, nothing backs the cuts but the words'
widths: hold them to 2/3x to 1.5x the median per letter, else fall back
ambiguous_gaps, and don't re-split (a gap inside a word next to two words
that touch fools every split by gaps). The log line says how many gaps
were cut. Adds Armstrong's all-gaps-cut audit test.
docs(spellcheck): ink lines by core, levelled bands, every-gap-cut widths
All checks were successful
CI / test (pull_request) Successful in 1m46s
88b9e6da25
fix(spellcheck): a word missing or extra in the transcription leaves its line unmarked
All checks were successful
CI / test (pull_request) Successful in 1m31s
399b4beced
Lined up by letters (:align), a transcription one word short of the ink
(an OCR slip, a hand edit) or one word over put the words round it on
their neighbours' ink (F12, F13).

- A line break in the transcription ends an ink line too, so a missing
  or extra word can't shift words between lines.
- A line's words are sure together or not at all: every word's breaks
  clear, the line's narrowest cut 1.5x the widest gap it leaves inside
  words, and every word's width within 0.6 (log) of its letters'.
- With those per-line checks, a page passes at 25% sure (was 75%).

Adds Nye's missing-word audit and an extra-word audit.
fix(spellcheck): a word missing on a line where two touch leaves the page unmarked
All checks were successful
CI / test (pull_request) Successful in 2m38s
0a93f9be0a
A split by gaps counted the page's words, not each line's, so a word
missing from the transcription and two inked words touching cut the
same number of gaps, boxing the words between on their neighbours'
ink (F14). Every line break in the transcription must now end an ink
line too, and a word joined across a gap left inside it must be no
wider than 1.6x the median per letter (and one more), or the split
doesn't pass. :align holds joined words to 1.4x the same way.

Adds Armstrong's gap-split and word-off-by-two audit tests.
fix(spellcheck): a word off in a flat paragraph can't shift onto the next line's ink
All checks were successful
CI / test (pull_request) Successful in 2m41s
20b9fdee6d
The OCR joins a paragraph's wrapped lines, so most ink lines have no
transcription break to pin their words. A missing or extra word then
spills across a line: the line that takes it fails its checks, and its
neighbour can look sure on shifted words of the same length (F16).

A line next to one that isn't sure is now only sure when a transcription
line end sits between them. Adds Armstrong's flat-paragraph audit (SYN_JOIN)
and the F16 cases as a regression test.
feat(spellcheck): switch off lining ink up by letters, per user or SPELLCHECK_INK_ALIGN
All checks were successful
CI / test (pull_request) Successful in 2m43s
4b70a222f4
The :align split is the last resort for dense handwriting. A user can now
turn it off on the OCR settings page, and SPELLCHECK_INK_ALIGN=true|false
sets it for every user (shown on the page instead of the switch). Off, a
page no split by gaps passes falls back with no marks, and the ink log
line says 'align off'. InkCheck still always tries it.
fix(spellcheck): a line break a word early can't pin the next line on shifted words
All checks were successful
CI / test (pull_request) Successful in 2m52s
62c5700879
A line next to an unsure line was sure whenever a transcription line
break sat between them. When every break falls a word early and a word
is dropped right after one, the counts cancel and the next line is pinned
on shifted words, its first word boxed on another word's ink (F17).

Now the unsure neighbour must not fit its count of words one earlier or
later better (by 1.0 in the alignment score) for its break to pin.
fix(spellcheck): say so when a page lines up but none of its hits is on a sure word
All checks were successful
CI / test (pull_request) Successful in 2m47s
5152bb2fdf
Closes F15 on #59: with the ink lined up but every hit on a line that
isn't sure, the panel showed no note at all. It now says the words aren't
on a line that lines up surely. With lining up by letters switched off, the
fallback note's tooltip also says so.
word_fit stays 0.6: loosening it to 0.7 let two extra words on a line's
first words land boxes on the wrong word (F18, off-by-two set).
feat(ocr): keep the page's line breaks in transcriptions (prompt v2)
All checks were successful
CI / test (pull_request) Successful in 2m25s
d76ad7246d
Joined paragraphs leave most ink lines with no line break to hold their
words in place, so a word off on one line unpins its neighbours and the
ink marks fall back. One transcription line per handwritten line still
renders as one Markdown paragraph. Version 2 marks earlier AI
transcriptions outdated; re-running them stays the user's call.

Search reads those lines as Markdown does, so line-broken pages search
as well as joined ones: a quoted phrase matches with any whitespace
between its words (a regex the trigram index still serves), its
highlight crosses the break, and snippets join a paragraph's lines with
a space, keeping " · " for blank lines, headings, list items and quotes.

The opened page marks a wrapped phrase too: SearchHighlight (and the PDF
page's marks) match each term as its escaped words joined by \s+, the
same pattern Search.phrase_regex builds. A word hyphenated at a line end
("ket-" then "tle") is searched, marked and shown whole: a hyphen
ending a line between lowercase letters is dropped, in plain_text and in
the database, where the trigram index moves onto that same expression.
A compound broken at its own hyphen ("self-" then "aware") is still
found by "self-aware": the term's hyphen is optional in the database,
and a search for it keeps the hyphen in the snippet and marks it on
the page.

Refs #53
jfro merged commit ad7d28ee08 into main 2026-10-29 00:34:30 +00:00
jfro deleted branch feat/53-ink-marks 2026-10-29 00:34:30 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jfro/rm-analyzer!59
No description provided.