9
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

kuromoji.js(日本語形態素解析)の使い方

Last updated at Posted at 2018-04-14

kuromoji.js(日本語形態素解析)の使い方

kuromoji.jsをシンプルに使う為のサンプル

デモは以下で可能。
Furigana Extension(chrome拡張)
https://chrome.google.com/webstore/detail/furigana-extension/kenooeijfmebjimghhoijpdbednpnpbl

kuromojiオブジェクトの作成

// kuromojiオブジェクト
let kuromojiObj;

// kuromojiオブジェクトの作成
kuromoji.builder({
	dicPath : 'dict/'
}).build(function(error, _tokenizer) {
	if (error != null) {
		console.log(error);
	}
	kuromojiObj = _tokenizer;
});

// kuromojiオブジェクトの取得
let getKuromojiObj = function() {
	return kuromojiObj;
};

形態素解析

// 形態素解析
function analyze(str) {
	// kuromojiオブジェクトの取得
	let tokenizer = getKuromojiObj();
	// 形態素解析実行
	tokenize = tokenizer.tokenize(str);
	for (let j = 0; j < tokenize.length; j++) {
		alert(tokenize[j].surface_form);
	}
}
9
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?