JS組み込みの形態素解析

コードを見た方が早い。NodeJS v16や最新のChromeなら動作する、Firefoxはまだ実装されていない

const text = "吾輩は猫である。名をニャンという。";
const seg = new Intl.Segmenter("ja-JP", {granularity: "word"});
console.log([...seg.segment(text)].map(s=>s.segment))

実行結果

[
  '吾輩',   'は',
  '猫',     'で',
  'ある',   '。',
  '名',     'を',
  'ニャン', 'という',
  '。'
]

実装はどうなっているのだろう? 内部にMeCabなどの形態素解析器を持っているのだろうか?

辞書登録がないので本格的な利用はまだ難しそうだが、独自辞書の追加機能の提案がされているようだ

Custom Dictionaries · Issue #133 · tc39/proposal-intl-segmenter · GitHub