test add tokenizer
This commit is contained in:
1 parent
7e8c38a80f
commit
9dfae88805
11 files changed
+233
-20
No files matched your search
@@ -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(" ");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user