Expose keywords/links/pageId/orientation/recognitionStatus to OCR plugins - #146
Merged
Conversation
…gins Extends PageTextProcessorContext (registerPageTextProcessor's hook, see ocr-plugins.md) with per-page fields an external companion plugin has had no way to see until now: starred keywords, internal links, PAGEID, orientation, and recognition status. Previously the hook only exposed a flat OCR-text string and rasterized image bytes, which was enough to reproduce the OCR-text-pattern half of #123 but not #122's genuine keyword-star/link handling - see the discussion on #145. sn.keywords/sn.links are grouped per page using the same first-4-characters-of-the-Record-key convention supernote-typescript's _parseLinks documents (more reliable than IKeyword.KEYWORDPAGE, which can be '0'/invalid). Verified against a real device-created fixture (supernote-typescript/tests/input/nomad-3.26.40-link-tag-3p.note). Titles were considered too (same "device-native structured signal" category as keywords/links) but dropped from this pass: ITitle has no decoded text, only a bounding box + bitmap, so getting title text needs correlating that box against page.recognitionElements' word boxes - real new logic, not just wiring through an existing field. Bumps the supernote-typescript submodule pointer to a branch (not yet merged) that exports RecognitionStatuses from its index, needed to type the new recognitionStatus field as that enum rather than a bare string - see supernote-typescript#38.
Now that #38 (export RecognitionStatuses) merged to main, point at that rather than the feature branch it landed via.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the field additions discussed in #145 (a follow-up from #144's prototype, which found the
registerPageTextProcessorhook couldn't reproduce PR #122/#123's native keyword-star/link handling from outside the plugin).Extends
PageTextProcessorContextwith:keywords: string[]- this page's starred keywords, raw OCR'd text, deduplicatedlinks: ILink[]- this page's own internal links, same-file anchors already resolvedpageId: string- this page's ownPAGEIDorientation: string- this page's orientation as recorded in the.notefilerecognitionStatus: RecognitionStatuses- whether recognition ran/completed on this page, distinguishing that fromtextbeing merely emptykeywords/linksare grouped per page using the same "first 4 characters of thesn.keywords/sn.linksRecord key = 1-indexed page" conventionsupernote-typescript's_parseLinksalready documents (more reliable thanIKeyword.KEYWORDPAGE, which can be'0'/invalid).Titles were considered and dropped from this pass -
ITitlehas no decoded text (onlyTITLERECT+ a bitmap), so producing title text would need correlating that rectangle againstpage.recognitionElements' word-level boxes, which is new logic, not just wiring through an existing field. Left for a follow-up once that's designed.Stacked on supernote-typescript#38, which exports
RecognitionStatusesfrom that library's index (needed sorecognitionStatuscan be typed as the real enum rather than a bare string) - this PR's submodule pointer currently points at that branch, notmain. Rebase the pointer once #38 merges.Test plan
npm run build(both submodule and plugin) - cleannpx tsc --noEmit- cleannpx eslint src/main.ts- 0 errorsnpx vitest run- 95 passedcollectPageKeywords/collectPageLinksagainst a real device-created fixture (supernote-typescript/tests/input/nomad-3.26.40-link-tag-3p.note) - keywords landed on the correct page (3), links resolved to the correct target pages (2),pageId/orientation/recognitionStatusall populated as expectedctx.keywords/ctx.links/ctx.pageId/ctx.orientation/ctx.recognitionStatusagainst a real note with starred keywords and internal links