1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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

Last updated at Posted at 2020-05-18

Index

kuromoji とは

Javaで開発したオープンソース日本語形態素解析エンジンです。

kuromoji | Atilika
https://www.atilika.com/ja/kuromoji/

項目 説明
提供者 アティリカ Atilika
提供形式 Java ライブラリ

Maven

<!-- https://mvnrepository.com/artifact/org.nlp4j/nlp4j-kuromoji -->
<dependency>
    <groupId>org.nlp4j</groupId>
    <artifactId>nlp4j-kuromoji</artifactId>
    <version>1.3.4.0</version>
</dependency>

コード

package example;

import nlp4j.Document;
import nlp4j.Keyword;
import nlp4j.impl.DefaultDocument;
import nlp4j.krmj.annotator.KuromojiAnnotator;

public class HelloKuromojiNLP1 {

	public static void main(String[] args) throws Exception {
		// 自然文のテキスト
		String text = "今日はいい天気です。";

		Document doc = new DefaultDocument();
		// 属性「text」としてセットする
		doc.putAttribute("text", text);

		// kuromoji アノテーター
		KuromojiAnnotator annotator = new KuromojiAnnotator();
		// 処理対象の属性を指定
		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=。]

Index

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?