Repository navigation
fix: retokenize a Document after its text changes - #583
Merged
aksg87 merged 4 commits intoNov 4, 2026
Merged
Conversation
|
Your branch is 1 commits behind git fetch origin main
git merge origin/main
git pushNote: Enable "Allow edits by maintainers" to allow automatic updates. |
Collaborator
|
Thanks @mittalpk. I merged main, cleared the AnnotatedDocument cache when text is set to None, and parameterized the tests. |
Merged
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.
Description
Document.tokenized_textcached its first tokenization, buttextis a plain public field, so assigning new text kept the old tokens. Extraction then prompted with the old text and aligned against it, producingMATCH_EXACTintervals that point at the wrong span of the returned text.The getter now compares the cached tokenization's
textwith the currenttextand tokenizes again when they differ. The same check is applied toAnnotatedDocument. A tokenization set explicitly for the current text is still kept.Fixes #580
Bug fix
How Has This Been Tested?
Added three tests to
tests/data_lib_test.py: aDocumentand anAnnotatedDocumentre-tokenize after their text changes, and a custom tokenization for unchanged text is kept. The first two fail without the fix. The issue's offline reproduction now extractsBobwith a correct interval.Checklist:
Code of conduct.
Contributing
page, and I either signed the Google
Individual CLA
or am covered by my company's
Corporate CLA.
issue(s) and we have agreed upon the general approach.
issue(s) that documentation elsewhere needs updating.
Google's Python Style Guide
and ran
pylintover the affected code.