Last active
November 8, 2018 00:56
-
-
Save tushuhei/5ac67442a8e5e4c78a2ad41805864fd9 to your computer and use it in GitHub Desktop.
Word segmentation with pure V8 engine.
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
let segment = (text) => { | |
let it = Intl.v8BreakIterator('ja'); | |
it.adoptText(text); | |
let result = []; | |
let curr, next; | |
while (true) { | |
curr = it.current(); | |
next = it.next(); | |
if (next == -1) break; | |
result.push(text.slice(curr, next)); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment