0
0

More than 1 year has passed since last update.

NLP4J - Java で形態素解析(Mecabを利用)

Last updated at Posted at 2021-07-18

NLP4J Index

MeCab (和布蕪)とは

MeCabは 京都大学情報学研究科−日本電信電話株式会社コミュニケーション科学基礎研究所 共同研究ユニットプロジェクトを通じて開発されたオープンソース 形態素解析エンジンです。

MeCab: Yet Another Part-of-Speech and Morphological Analyzer
https://taku910.github.io/mecab/
MeCab - Wikipedia
https://ja.wikipedia.org/wiki/MeCab

項目 説明
提供者 工藤拓
提供形式 Cプログラム / ライブラリ

実行前提条件

Mecab がインストールされていて、コマンドラインから呼び出し可能になっていること。

>mecab
今日はいい天気です。
今日    名詞,副詞可能,*,*,*,*,今日,キョウ,キョー
は      助詞,係助詞,*,*,*,*,は,ハ,ワ
いい    形容詞,自立,*,*,形容詞・イイ,基本形,いい,イイ,イイ
天気    名詞,一般,*,*,*,*,天気,テンキ,テンキ
です    助動詞,*,*,*,特殊・デス,基本形,です,デス,デス
。      記号,句点,*,*,*,*,。,。,。
EOS
^Z

>

Maven

最新のバージョンは以下リンクから確認してください

<dependency>
	<groupId>org.nlp4j</groupId>
	<artifactId>nlp4j-core</artifactId>
	<version>[1.3.1.0,)</version>
</dependency>
<dependency>
	<groupId>org.nlp4j</groupId>
	<artifactId>nlp4j-mecab</artifactId>
	<version>[0.1.0.0,)</version>
</dependency>

コード

package nlp4j.mecab.examples;

import nlp4j.Document;
import nlp4j.Keyword;
import nlp4j.impl.DefaultDocument;
import nlp4j.mecab.MecabAnnotator;

public class MecabAnnotatorExample0 {
	public static void main(String[] args) throws Exception {
		// 自然文のテキスト
		String text = "私は学校に行きました。";
		Document doc = new DefaultDocument();
		{
			doc.putAttribute("text", text);
		}
		MecabAnnotator annotator = new MecabAnnotator();
		{
			annotator.setProperty("target", "text");
		}
		annotator.annotate(doc); // throws Exception
		for (Keyword kwd : doc.getKeywords()) {
			System.err.println(kwd);
		}
	}
}

#結果

私 [facet=名詞, str=私]
は [facet=助詞, str=は]
学校 [facet=名詞, str=学校]
に [facet=助詞, str=に]
行く [facet=動詞, str=行き]
ます [facet=助動詞, str=まし]
た [facet=助動詞, str=た]
。 [facet=記号, str=。]

以上です.

NLP4J Index

0
0
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
0
0