StoryEdit 開発日誌

ウェブアプリ StoryEditを作ってましたが延期。普通のブログ。

日本語版WordNetから、英語 --> 日本語の翻訳を探す。

お盆休み!、ということで興味の赴くまま、また別のウェブアプリをつくってます。
英単語勉強アプリ。Coffee Script + nodejs で作成中です。

このメイン機能で、英単語いれたら、その意味をだしてくれる必要があるんですが、そのときに、翻訳が必要。翻訳APIとか、フリーの英和辞書とか探したけど、なかなかいいのがなくて、みつけたのがこちら。

日本語 WordNet: http://nlpwww.nict.go.jp/wn-ja/

詳しくは、本家ウェブサイトの解説を参照してほしいが、学術用(?)に作られた単語間の関連性をもったデータベースらしく。そんなNLPなデータなんだから、単語の意味くらい入ってるだろと思って調べていった結果の途中報告。(内部情報が見つけられなかったため、対訳探すのに苦労した)

1. wnjpn.dbをダウンロード、接続。

# .schema

sqlite> .schema
CREATE TABLE ancestor (synset1 text,
                          synset2 text,
                          hops int);
CREATE TABLE link_def (link text,
                          lang text,
                          def text);
CREATE TABLE pos_def (pos text,
                          lang text,
                          def text);
CREATE TABLE sense (synset text,
                          wordid integer,
                          lang text,
                          rank text,
                          lexid integer,
                          freq integer,
                          src text);
CREATE TABLE synlink (synset1 text,
                          synset2 text,
                          link text,
                          src text);
CREATE TABLE synset (synset text,
                          pos text,
                          name text,
                          src text);
CREATE TABLE synset_def (synset text,
                          lang text,
                          def text,
                          sid text);
CREATE TABLE synset_ex (synset text,
                          lang text,
                          def text,
                          sid text);
CREATE TABLE variant (varid integer primary key,
                          wordid integer,
                          lang text,
                          lemma text,
                          vartype text);
CREATE TABLE word (wordid integer primary key,
                          lang text,
                          lemma text,
                          pron text,
                          pos text);
CREATE TABLE xlink (synset text,
                        resource text,
                        xref  text,
                        misc text,
                        confidence text);

なるほど。まったくわからん。

どうやらwordというテーブルに、単語が入っている模様。

sqlite> select * from word where lemma="dog";
85237|eng|dog||n
152987|eng|dog||v

やっぱり意味は入ってないのね。そこで、wordidというのを含んでいるschemaをさがすと、senseというのがそれっぽい。とりあえず、wordid=85237でsenseを検索。

sqlite> select * from sense where wordid=85237;
02084071-n|85237|eng|0|1|42|eng-30
10114209-n|85237|eng|0|2|0|eng-30
10023039-n|85237|eng|0|3|0|eng-30
09886220-n|85237|eng|0|4|0|eng-30
07676602-n|85237|eng|0|5|0|eng-30
03901548-n|85237|eng|0|6|0|eng-30
02710044-n|85237|eng|0|7|0|eng-30

これで、synsetというのがとれる。ここから、単語の意味をもっているであろうと思われる、synset_defなぞをたたいてみる。(defってそれっぽく聞こえるから)

sqlite> select * from synset_def where synset="02084071-n";
02084071-n|eng|a member of the genus Canis (probably descended from the common wolf) that has been domesticated by man since prehistoric times; occurs in many breeds; "the dog barked all night"|0
02084071-n|img|animals/mammals/dog_06_drawn_with_strai_02|0
02084071-n|img|animals/mammals/dog_05_drawn_with_strai_02|1
02084071-n|img|animals/mammals/dog_on_leash_gerald_g._01|2
02084071-n|eng|a member of the genus Canis (probably descended from the common wolf) that has been domesticated by man since prehistoric times|0
02084071-n|jpn|有史以前から人間に家畜化されて来た(おそらく普通のオオカミを先祖とする)イヌ属の動物|0
02084071-n|eng|occurs in many breeds|1
02084071-n|jpn|多数の品種がある|1


日本語にしぼったほうがよさそうだな。というわけで、lang=jpnで再検索。

sqlite> select * from synset_def where synset="02084071-n" and lang="jpn";
02084071-n|jpn|有史以前から人間に家畜化されて来た(おそらく普通のオオカミを先祖とする)イヌ属の動物|0
02084071-n|jpn|多数の品種がある|1


う。。。そうかぁ。。。「イヌ」ってでてきて欲しかったけど、けっこうな訳がでてきてしまいましたね。。。



しかし!!ここであきらめない!!
他にsynsetを使っているテーブルをとりあえずみてみる。

sqlite> select * from sense where synset="02084071-n" and lang="jpn";
02084071-n|176027|jpn||||hand
02084071-n|180438|jpn||||hand
02084071-n|185856|jpn||||hand
02084071-n|196135|jpn||||hand
02084071-n|207353|jpn||||hand
02084071-n|212666|jpn||||hand

うむぅ。。。わけがわからん。。。この番号は、、、wordidか。。。あれ、"dog"のwordidと違うぞ。

ん?

まさか?

sqlite> select * from word where wordid=175027;
175027|jpn|下し金||n

おぉぉぉぉぉ!!! 

なんか日本語の単語がでてきたぁ!!!もしやこれは、いけるか?

sqlite> select * from word where wordid=180438;
180438|jpn|ドッグ||n
sqlite> select * from word where wordid=185856;
185856|jpn|犬||n

よっしゃーーーーーーー!!!ψ(`∇´)ψ

まぁしかし、何番目のwordidをとれば、一番適切なのかはどうやってわかるんですかねぇ?


追記:
http://ejje.weblio.jp/content/dog

ここのWordnetをみれば、たしかに同じ定義がとってこれている。