mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 11:26:02 +00:00
fix(check): a number with a separator counts as one word in line reading time (#8084)
"1,080" and "3.5%" were split at the separator and counted as two words, so a two-word line such as "1,080억 달러" was timed as three and its shortest allowed hold went from 0.4 s to 1.05 s. Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
a1ee40094d
commit
7a63b10d76
@@ -111,6 +111,16 @@ describe("readingWords", () => {
|
||||
expect(readingWords("a tooth can’t get in")).toBe(5);
|
||||
expect(readingWords("it's 'quoted'")).toBe(2);
|
||||
});
|
||||
|
||||
it("counts a number with a thousands separator or a decimal point as one word", () => {
|
||||
expect(readingWords("1,080")).toBe(1);
|
||||
expect(readingWords("3.5%")).toBe(1);
|
||||
expect(readingWords("$1,200.50 saved")).toBe(2);
|
||||
expect(readingWords("1,080억 달러")).toBe(2);
|
||||
expect(readingWords("one, two. 3 left")).toBe(4);
|
||||
expect(readingWords("12/40")).toBe(2);
|
||||
expect(readingWords("売上1,080億")).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe("lineFloorSec", () => {
|
||||
|
||||
@@ -29,7 +29,10 @@ 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}%$]+(?:['’][\p{L}\p{M}\p{N}]+)*/gu;
|
||||
const WORD_CHARS = "[\\p{L}\\p{M}\\p{N}%$]+";
|
||||
const CONTRACTION_TAIL = "['’][\\p{L}\\p{M}\\p{N}]+";
|
||||
const DIGIT_SEPARATOR_TAIL = `(?<=\\p{N})[.,](?=\\p{N})${WORD_CHARS}`;
|
||||
const WORD_RUNS = new RegExp(`${WORD_CHARS}(?:${CONTRACTION_TAIL}|${DIGIT_SEPARATOR_TAIL})*`, "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" });
|
||||
const UNSPACED_SCRIPT =
|
||||
|
||||
Reference in New Issue
Block a user