Python-text-processing-python-wordnet-interface
提供:Dev Guides
Python-WordNetインターフェイス
WordNetは英語の辞書で、従来のシソーラスNLTKには英語のWordNetが含まれています。 単語の意味、使用例、定義を取得するためのリファレンスとして使用できます。 同様の単語の集まりは、補題と呼ばれます。 WordNetの単語は整理され、ノードと単語のテキストを表すノードとエッジ、単語間の関係を表すエッジがあります。 以下に、WordNetモジュールの使用方法を示します。
すべての補題
from nltk.corpus import wordnet as wn
res=wn.synset('locomotive.n.01').lemma_names()
print res
上記のプログラムを実行すると、次の出力が得られます-
[u'locomotive', u'engine', u'locomotive_engine', u'railway_locomotive']
単語の定義
単語の辞書定義は、定義関数を使用して取得できます。 通常の辞書にある単語の意味を説明しています。
from nltk.corpus import wordnet as wn
resdef = wn.synset('ocean.n.01').definition()
print resdef
上記のプログラムを実行すると、次の出力が得られます-
a large body of water constituting a principal part of the hydrosphere
使用例
- exmaples()*関数を使用して、単語の使用例を示す例文を取得できます。
from nltk.corpus import wordnet as wn
res_exm = wn.synset('good.n.01').examples()
print res_exm
上記のプログラムを実行すると、次の出力が得られます-
['for your own good', "what's the good of worrying?"]
言葉の反対
反意語関数を使用して、反対の単語をすべて取得します。
from nltk.corpus import wordnet as wn
# get all the antonyms
res_a = wn.lemma('horizontal.a.01.horizontal').antonyms()
print res_a
上記のプログラムを実行すると、次の出力が得られます-
[Lemma('inclined.a.02.inclined'), Lemma('vertical.a.01.vertical')]