test add tokenizer

This commit is contained in:
polv committed 2026-08-28 00:54:20 +07:00
1 parent 7e8c38a80f
commit 9dfae88805
11 files changed
+233 -20

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
import { MeCab } from "kuromoji-ko";
export class Tokenizer {
static async init() {
return new Tokenizer(
await MeCab.create({
engine: "ko",
dictPath: "./node_modules/kuromoji-ko/dict",
}),
);
}
private constructor(public mecab: MeCab) {}
normalize(s: string) {
return this.mecab
.parse(s)
.filter((t) => t.pos.some((p) => /^[NVM]/.test(p)))
.map((t) => t.lemma)
.join(" ");
}
}