英文の中から名詞のみを抽出することを検討している。 日本語と違い、英語はスペースで分かち書きしているので、「の、は、が」とかを分析する形態要素解析は簡単なようだ。 したがって、自然言語処理(NLP Natural Language Processing)の技術のうち、品詞判断を実現するツールを探してみた。
この手のツールは、POS Tagging(Part-of-Speech Tagging: 品詞タグ付け)と呼ぶそうだ。 いろいろと探してみた結果、Eric Bill氏が1993年に開発した "Bill Tagger"が有名で、かなりのツールはこのエンジンを利用している。
http://en.wikipedia.org/wiki/Brill_taggerBill氏は、今マイクロソフト社に勤務しているとのこと。彼のオリジナルツールは、"Error-driven"であり、"tranformation-based"なんだそうで、辞書ベースと文脈解析で最初の解析を終えたあと、利用者が解析を修正することで辞書を成長させていくものらしい。
今回の目的は、自然言語処理の勉強でなく、名詞のみが判断されれば良いし、また出来ればjavascriptのツールが欲しかったので、pos-jsを試してみた。
https://github.com/fortnightlabs/pos-jshttp://code.google.com/p/jspos/
pos-jsのインストール
作業ディレクトリに、ライブラリをインストールしてみる。
pos-js (js pos:javascript parts-of-speech tagger)も、Eric Bill氏のエンジンを利用している。
[baker@www tagger-js]$ npm install pos
npm http GET https://registry.npmjs.org/pos
npm http 200 https://registry.npmjs.org/pos
npm http GET https://registry.npmjs.org/pos/-/pos-0.1.1.tgz
npm http 200 https://registry.npmjs.org/pos/-/pos-0.1.1.tgz
pos@0.1.1 ./node_modules/pos
サンプルプログラムの実行
まずは、サイトのサンプルプログラムを試してみた。
作業ディレクトリで作成したサンプルコード sample.jsvar pos = require('pos');
// 分かち書き解析モジュールで単語分解する
// クラス Lexer()を用意し、lexメソッドで単語分解を実行し、wordsに配列として保管。
var words = new pos.Lexer().lex("This is some sample text. This text can contain multiple sentences.");
// クラス Tagger()を用意し、tagづけ(品詞判断)を行う。アウトプットは[単語、タグ]の配列の配列。
var taggedWords = new pos.Tagger().tag(words);
for(i in taggedWords){
var taggedWord = taggedWords[i];
var word = taggedWord[0]; // 単語を抽出
var tag = taggedWord[1]; // タグを抽出
console.log(word + " /" + tag);
}
実行結果です。
$ node sample.js This /DT # 前置詞 is /VBZ # 動詞, 現在形 some /DT # 前置詞 sample /NN # 名詞 text /NN # 名詞 . /. # ピリオド This /DT # 前置詞 text /NN # 名詞 can /MD # 助詞 contain /VB # 動詞 multiple /JJ # 形容詞 sentences /NNS # 名詞、複数形 . /. # ピリオド
タグの一覧を引用しておきます。NNPは(たぶん名詞)てな意味ですね。
--- ----------------------- -------------
TAG sense sample
--- ----------------------- -------------
CC Coord Conjuncn and,but,or
CD Cardinal number one,two
DT Determiner the,some
EX Existential there there
FW Foreign Word mon dieu
IN Preposition of,in,by
JJ Adjective big
JJR Adj., comparative bigger
JJS Adj., superlative biggest
LS List item marker 1,One
MD Modal can,should
NN Noun, sing. or mass dog
NNP Proper noun, sing. Edinburgh
NNPS Proper noun, plural Smiths
NNS Noun, plural dogs
POS Possessive ending Õs
PDT Predeterminer all, both
PP$ Possessive pronoun my,oneÕs
PRP Personal pronoun I,you,she
RB Adverb quickly
RBR Adverb, comparative faster
RBS Adverb, superlative fastest
RP Particle up,off
SYM Symbol +,%,&
TO ÒtoÓ to
UH Interjection oh, oops
URL url http://www.google.com/
VB verb, base form eat
VBD verb, past tense ate
VBG verb, gerund eating
VBN verb, past part eaten
VBP Verb, present eat
VBZ Verb, present eats
WDT Wh-determiner which,that
WP Wh pronoun who,what
WP$ Possessive-Wh whose
WRB Wh-adverb how,where
, Comma ,
. Sent-final punct . ! ?
: Mid-sent punct. : ; Ñ
$ Dollar sign $
# Pound sign #
" quote "
( Left paren (
) Right paren )
0 件のコメント:
コメントを投稿