feat(api): expose strategy auto-selection on the public API#19
Open
jerefrer wants to merge 1 commit into
Open
Conversation
Strategy auto-selection previously lived only in `cli_main`; the `patch_pdf` / `extract_pdf_text` / `build_tounicode_dict` API could not auto-select, so programmatic callers had to re-implement the scoring. Add a `strategy=` argument backed by a new `resolve_strategy` helper: - `strategy=None` (default): unchanged — the default gid tier. No new key is added to stats, so existing callers are unaffected. - `strategy="<name>"`: pin one bundled tree (e.g. "gid-pua-free"), no scoring. - `strategy="auto"`: score every bundled tree and keep the best. - `strategy=["gid", "gid-pua-free"]`: score over an explicit ordered subset — important for consumers that can't afford to auto-try the 139M gshape tree. When a strategy is given, the winning name is reported as stats["strategy"]. `font_lookup_dir` and `strategy` are mutually exclusive. Closes OpenPecha#18. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Jun 29, 2026
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.
Closes #18.
Strategy auto-selection currently lives only in
cli_main, so thepatch_pdf/extract_pdf_text/build_tounicode_dictAPI can't auto-select — programmatic callers have to re-implement the scoring. (We do exactly that in the in-browser Easy Tibetan Copy worker.)API
A new
strategy=argument, backed by aresolve_strategyhelper intounicode_core:The subset form is the one that matters for us: a browser consumer can't afford to auto-try the 139 MB
gshapetree, so "auto over these strategies" is what we need.Design choices (open to your preference)
strategy=Nonekeeps the historical behaviour (default gid tier) and adds no new key tostats, so existing callers are unaffected. I did not flip the API default to"auto"the way the CLI does — that felt like the maintainer's call given the docstring's "the public API is tier 1 (gid)" stance. Easy to change if you'd prefer auto-by-default.stats["strategy"].font_lookup_dirandstrategyare mutually exclusive (raisesValueError).resolve_strategyreuses the existing_select_auto_strategy/_default_strategy_specs; single-name strategies skip scoring; unknown names and uninstalled trees raise clear errors.Tests
tests/test_api_strategy.pycovers: default-unchanged (nostrategykey), pinned named tree, subset auto-select pickinggid-pua-freeon the #16 page,"auto",build_tounicode_dict(strategy=...), and the two error cases. Full suite: 81 passed, 10 skipped locally.Stacks cleanly on top of #17 (independent file).