mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
fix(cli): count a contraction as one word in line_unread (#6346)
WORD_RUNS split at apostrophes, so "can't" counted as two words and a line with contractions got a longer hold floor than its real word count. Refs #6338
This commit is contained in:
@@ -81,6 +81,12 @@ describe("readingWords", () => {
|
||||
expect(readingWords("✓ — →")).toBe(0);
|
||||
expect(readingWords("今天天气很好")).toBeGreaterThan(1);
|
||||
});
|
||||
|
||||
it("counts a contraction as one word", () => {
|
||||
expect(readingWords("a tooth can't get in")).toBe(5);
|
||||
expect(readingWords("a tooth can’t get in")).toBe(5);
|
||||
expect(readingWords("it's 'quoted'")).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("lineFloorSec", () => {
|
||||
|
||||
@@ -29,7 +29,7 @@ const CRAFT_THRESHOLDS = {
|
||||
|
||||
const T = CRAFT_THRESHOLDS;
|
||||
const ZERO_BBOX: CheckBbox = { x: 0, y: 0, width: 0, height: 0 };
|
||||
const WORD_RUNS = /[\p{L}\p{M}\p{N}%$]+/gu;
|
||||
const WORD_RUNS = /[\p{L}\p{M}\p{N}%$]+(?:['’][\p{L}\p{M}\p{N}]+)*/gu;
|
||||
// Chinese and Japanese have no spaces; a dictionary segmenter counts their words like an English line's.
|
||||
const WORD_SEGMENTER = new Intl.Segmenter("ja", { granularity: "word" });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user