Fix acronym and abbreviation handling in speed reader#5
Open
Roconx wants to merge 4 commits intoTheRedJalapeno:masterfrom
Open
Fix acronym and abbreviation handling in speed reader#5Roconx wants to merge 4 commits intoTheRedJalapeno:masterfrom
Roconx wants to merge 4 commits intoTheRedJalapeno:masterfrom
Conversation
- Add protectAcronyms() to handle U.K., U.S.A., N.A.T.O. etc. - Add protectAbbreviations() for Mr., Dr., Prof., etc. - Intelligently detect if acronym is at end of sentence - Use Unicode placeholder to protect dots during parsing
- Add endsWithSentencePunctuation() helper - Update getChunksFromSentences() to use helper - Update pause detection in startReading() to exclude U.K., Mr., etc.
- Don't restore dots in splitIntoSentences() - Update endsWithSentencePunctuation() to detect real vs protected dots - Restore dots only when displaying text - Fixes: acronyms at end of sentence now correctly pause
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.
Fixes: #4
Problem
Words like "U.K.", "U.S.", "Mr.", "Dr." were being incorrectly handled:
Solution
Use a placeholder technique to temporarily protect dots that aren't real sentence endings during text processing.
Why not use regex lookbehind (like numbers)?
Numbers use (?<!\d) lookbehind because the pattern is simple and fixed-length. Acronyms have variable-length patterns (U.K. vs U.S.A. vs N.A.T.O.) which JavaScript regex lookbehind doesn't support.
Changes
New functions added:
Key logic:
Files modified: core.js
Supported abbreviations
Mr, Mrs, Ms, Dr, Prof, Sr, Jr, vs, etc, approx, Inc, Ltd, Co, Gen, Col, Lt, Sgt, Rev, Hon