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

More than 1 year has passed since last update.

NLP4J - Java で構文解析(Cabochaを利用)

Last updated at Posted at 2021-07-18

NLP4J Index

CaboCha/南瓜とは

CaboCha は, Support Vector Machines に基づく日本語係り受け解析器です。

CaoboCha: Yet Another Japanese Dependency Structure Analyzer
https://taku910.github.io/cabocha/

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

#実行前提条件

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

>cabocha
今日はいい天気です。
    今日は---D
        いい-D
    天気です。
EOS
^Z

>

#Maven Dependency

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

コード

package nlp4j.cabocha.examples;

import nlp4j.Document;
import nlp4j.Keyword;
import nlp4j.KeywordWithDependency;
import nlp4j.cabocha.CabochaAnnotator;
import nlp4j.impl.DefaultDocument;

public class CabochaAnnotatorExample0 {
	public static void main(String[] args) throws Exception {
		Document doc = new DefaultDocument();
		{
			doc.putAttribute("text", "私は大学に歩いて行きました。");
		}
		CabochaAnnotator ann = new CabochaAnnotator();
		{
			ann.setProperty("encoding", "MS932");
			ann.setProperty("target", "text");
		}
		ann.annotate(doc); // Annotation
		for (Keyword kwd : doc.getKeywords()) {
			if (kwd instanceof KeywordWithDependency) {
				System.err.println(((KeywordWithDependency) kwd).toStringAsXml());
			}
		}
	}
}

#結果

<?xml version="1.0" encoding="UTF-8"?>
<w begin="13" depth="0" end="14" facet="記号" id="9" lex="。" sequence="9" str="。" upos="SYM">
    <w begin="12" depth="1" end="13" facet="助動詞" id="8" lex="た" sequence="8" str="た" upos="AUX">
        <w begin="10" depth="2" end="12" facet="助動詞" id="7" lex="ます" sequence="7" str="まし" upos="AUX">
            <w begin="8" depth="3" end="10" facet="動詞" id="6" lex="行く" sequence="6" str="行き" upos="VERB">
                <w begin="7" depth="4" end="8" facet="助詞" id="5" lex="て" sequence="5" str="て" upos="ADP">
                    <w begin="5" depth="5" end="7" facet="動詞" id="4" lex="歩く" sequence="4" str="歩い" upos="VERB">
                        <w begin="1" depth="6" end="2" facet="助詞" id="1" lex="は" sequence="1" str="は" upos="ADP">
                            <w begin="0" depth="7" end="1" facet="名詞" id="0" lex="私" sequence="0" str="私" upos="NOUN"/>
                        </w>
                        <w begin="4" depth="6" end="5" facet="助詞" id="3" lex="に" sequence="3" str="に" upos="ADP">
                            <w begin="2" depth="7" end="4" facet="名詞" id="2" lex="大学" sequence="2" str="大学" upos="NOUN"/>
                        </w>
                    </w>
                </w>
            </w>
        </w>
    </w>
</w>

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?