Java製の形態素解析ライブラリ lucene-gosen 使ってみた

どうもRamencozoです(´ω`)ノ

もしかしたらなんかで使うかもしんないので下記のページを参考(写経)にgosenベースの形態素解析ライブラリ lucene-gosen 使ってみました(´ω`)

Java製形態素解析ライブラリ「lucene-gosen」を試してみる

下記リンクからGosenのJarをダウンロードしてクラスパスにつっこめばすぐ動くようです(´ω`)
こちらではとりあえず lucene-gosen-4.3.0.jar(本体) と lucene-gosen-4.3.0-ipadic.jar(辞書) の2つをダウンロードしてeclipseのプロジェクトに投げ入れました(ノ´ω`)ノ

Downloads - lucene-gosen

ソースコード完全写経ですがとりあえず(っ´ω`)っ

HelloMorphologicalAnalysis.java

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import net.java.sen.SenFactory;
import net.java.sen.StringTagger;
import net.java.sen.dictionary.Token;


public class HelloMorphologicalAnalysis {
 public static void main(String[] args) {
  try {
   StringTagger tagger = SenFactory.getStringTagger(null);
   List<Token> tokens = new ArrayList<Token>();
   tagger.analyze("こんにちは、ラーメンです", tokens);
   
   for (Token t : tokens) {
    System.out.println("----------------");
    System.out.println("Surface: " + t.getSurface());
    System.out.println("Cost: " + t.getCost());
    System.out.println("Length: " + t.getLength());
    System.out.println("Start: " + t.getStart());
    System.out.println("BasicForm: " + t.getMorpheme().getBasicForm());
    System.out.println("ConjugationalForm: " + t.getMorpheme().getConjugationalForm());
    System.out.println("ConjugationalType: " + t.getMorpheme().getConjugationalType());
    System.out.println("Part of Speech: " + t.getMorpheme().getPartOfSpeech());
    System.out.println("Pronuciations: " + t.getMorpheme().getPronunciations());
    System.out.println("Readings: " + t.getMorpheme().getReadings());
   }
  } catch (IOException e) {
   e.printStackTrace();
  }
 }
}

実行結果がこちら(´ω`)っ

----------------
Surface: こんにちは
Cost: 3270
Length: 5
Start: 0
BasicForm: *
ConjugationalForm: *
ConjugationalType: *
Part of Speech: 感動詞
Pronuciations: [コンニチワ]
Readings: [コンニチハ]
----------------
Surface: 、
Cost: 4056
Length: 1
Start: 5
BasicForm: *
ConjugationalForm: *
ConjugationalType: *
Part of Speech: 記号-読点
Pronuciations: [、]
Readings: [、]
----------------
Surface: ラーメン
Cost: 7698
Length: 4
Start: 6
BasicForm: *
ConjugationalForm: *
ConjugationalType: *
Part of Speech: 名詞-一般
Pronuciations: [ラーメン]
Readings: [ラーメン]
----------------
Surface: です
Cost: 9780
Length: 2
Start: 10
BasicForm: *
ConjugationalForm: 基本形
ConjugationalType: 特殊・デス
Part of Speech: 助動詞
Pronuciations: [デス]
Readings: [デス]

解析されてますねー(´ω`)んでこっからどう扱ったものかなと考えちうです