かれ4

かれこれ4個目のブログ

Apache UIMAのサンプルを動かす

Apache UIMA面白いですね。

IBMの誇るクイズ王(ワトソン (コンピュータ) - Wikipedia)のソースコード(の一部)がASFに寄贈され、現在も開発が続いているプログラムです。

Mac OSX(10.9.4)でUIMAのサンプルを動かしてみます。

Macと言いつつほぼUnixとして使っているので、Linuxでも同様に動くはずです。

Javaの用意

まずはJavaが必要です。手元の環境ではJDKの1.8.0u5が入っていたので、この機会にJava SE Development Kit 8 - Downloadsからダウンロードして1.8.0u20を入れました。

Mac OSXの場合はJavaはインストールしても自動的に変わるわけではないので、
.profileなどに

export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home

を追加しておきます。

$ java -version
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
java version "1.8.0_20"
Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
$ javac -version
Picked up _JAVA_OPTIONS: -Dfile.encoding=UTF-8
javac 1.8.0_20

Javaのアップデートが完了したことが確認できました。

Apache UIMAのinstall

Apache UIMA - DownloadsからApache UIMAをダウンロードしてきます。
Apache UIMAには"UIMA AS Asynchronous Scaleout"と"UIMA Java framework & SDK"がありますが、今回はローカルだけで動かすので、"UIMA Java framework & SDK"だけをダウンロードしました。

解凍して、設置した場所(手元では/usr/local/apache-uima)をUIMA_HOMEとして.profile内でexportしておきます。

UIMAを動かしてみる

UIMAには最初から色々と便利なスクリプトが用意されています。

${UIMA_HOME}/bin/documentAnalyzer.sh

実行すると↓こんなWindowが開きました。
f:id:tottokug:20140831011404p:plain

Input Directory: ${UIMA_HOME}/apache-uima/examples/data/
Input File Format: text
Character Encoding: UTF-8
Output Directory:${UIMA_HOME}/examples/data/processed
Location of Analysis Engine XML Descriptor: ${UIMA_HOME}/examples/descriptors/analysis_engine/NamesAndPersonTitles_TAE.xml
XML Tag containing Text(option): 空欄
Language: en

と入力して、Interactiveを押すと、なんか入力出来そうなフォームが出てきました。
f:id:tottokug:20140831012317p:plain

ここに何か文章を入れるようなのですが、英語で何かを書こうなんて無理なお話です。
そこでピノキオの原作のテキストを数行お借りすることにしました。

How it happened that Mastro Cherry, carpenter, found a piece of wood
that wept and laughed like a child.


Centuries ago there lived--


"A king!" my little readers will say immediately.

No, children, you are mistaken. Once upon a time there was a piece of wood. It was not an expensive piece of wood. Far from it. Just a common block of firewood, one of those thick, solid logs that are put on the fire in winter to make cold rooms cozy and warm.


I do not know how this really happened, yet the fact remains that one fine day this piece of wood found itself in the shop of an old carpenter. His real name was Mastro Antonio, but everyone called him Mastro Cherry, for the tip of his nose was so round and red and shiny that it looked like a ripe cherry.


As soon as he saw that piece of wood, Mastro Cherry was filled with joy.
Rubbing his hands together happily, he mumbled half to himself:

"This has come in the nick of time. I shall use it to make the leg of a
table."

このテキストをフォームにペーストして”Analyze”を押すと結果が確認できました。

↓の画像のように、人の名前っぽいところが抜き出せている事が分かります。
f:id:tottokug:20140831014355p:plain

こんなにも簡単にテキストの分析が出来るとはという感じで、今後も期待のUIMAのサンプルをいじって遊んでみました。



参考:
UIMA 101: 前編 - UIMAことはじめ
これがちょっと古い情報だったので、今の2.6.0でも同じように出来るのか確かめました。