-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmartTokenizer.java
More file actions
32 lines (26 loc) · 994 Bytes
/
Copy pathSmartTokenizer.java
File metadata and controls
32 lines (26 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.blindgyi.tts;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class SmartTokenizer {
// Burmese syllable and token matching pattern
private static final Pattern MYANMAR_TOKEN_PATTERN = Pattern.compile(
"([က-အ](?:်[က-အ])?(?:[ျြွှ])*(?:[ါ-ေံးုိုီ]*)(?:်)?|[၊။]|\\s+|[^\\s\u1000-\u109F])"
);
public static List<String> tokenize(String text) {
List<String> tokens = new ArrayList<>();
if (text == null || text.isEmpty()) {
return tokens;
}
String cleaned = TextNormalizer.normalize(text);
Matcher matcher = MYANMAR_TOKEN_PATTERN.matcher(cleaned);
while (matcher.find()) {
String token = matcher.group();
if (token != null && !token.trim().isEmpty()) {
tokens.add(token);
}
}
return tokens;
}
}