Skip to content

Commit 5bd395a

Browse files
Lee Seongjooclaude
andcommitted
subtitle: don't split a sentence at a token-internal period (np.where, file.txt)
The sentence splitter treated the "." in np.where / file.txt / self.x as a sentence end, so the crawl broke those tokens across lines. Generalize the decimal exception: a "." immediately followed by a letter or digit is inside a token, not a sentence boundary (real Korean periods are followed by space/ newline/end). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a97816f commit 5bd395a

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

‎Sources/Core/TextSplitter.swift‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,22 @@ enum TextSplitter {
1111

1212
/// Split a paragraph into sentences for the karaoke-style subtitle. Breaks on
1313
/// sentence terminators (. ! ? … and newlines); doesn't split a "." that sits
14-
/// between digits (e.g. an unspelled decimal). Used for display only — audio
15-
/// stays chunked by paragraph.
14+
/// inside a token (np.where, file.txt, self.x, a decimal like 0.5). Used for
15+
/// display only — audio stays chunked by paragraph.
1616
static func sentences(_ text: String) -> [String] {
1717
let chars = Array(text)
1818
var out: [String] = []
1919
var cur = ""
2020
for (i, ch) in chars.enumerated() {
2121
cur.append(ch)
22-
let isTerminator = ch == "." || ch == "!" || ch == "?" || ch == "…" || ch == "\n"
23-
let betweenDigits = ch == "." && i > 0 && i + 1 < chars.count
24-
&& chars[i - 1].isNumber && chars[i + 1].isNumber
25-
if isTerminator && !betweenDigits {
22+
// A "." immediately followed by a letter or digit is inside a token
23+
// (np.where, file.txt, 0.5), not a sentence end. Real Korean sentence
24+
// periods are followed by space / newline / end / closing punctuation.
25+
let dotInsideToken = ch == "." && i + 1 < chars.count
26+
&& (chars[i + 1].isLetter || chars[i + 1].isNumber)
27+
let isTerminator = (ch == "." || ch == "!" || ch == "?" || ch == "…" || ch == "\n")
28+
&& !dotInsideToken
29+
if isTerminator {
2630
let t = cur.trimmingCharacters(in: .whitespacesAndNewlines)
2731
if !t.isEmpty { out.append(t) }
2832
cur = ""

0 commit comments

Comments
 (0)