2018年7月14日土曜日

開発環境

入門 自然言語処理 (Steven Bird (著)、Ewan Klein (著)、Edward Loper (著)、萩原 正人 (翻訳)、中山 敬広 (翻訳)、水野 貴明 (翻訳)、オライリージャパン)の2章(テキストコーパスと語彙資源へのアクセス)、2.8(演習問題)5.を取り組んでみる。

コード(Emacs)

Python 3

#!/usr/bin/env python3
from nltk.corpus import wordnet as wn

print('5.')

nouns = ['python', 'language', 'creature', 'dog', 'cat']
for noun in nouns:
    print(noun)
    for synset in wn.synsets(noun):
        print(f'\t{synset}: {synset.lemma_names()}')
        methods = [
            synset.member_meronyms,
            synset.part_meronyms,
            synset.substance_meronyms,
            synset.member_holonyms,
            synset.substance_holonyms
        ]
        for method in methods:
            print(f'\t\t{method.__name__}: {method()}')

入出力結果(Terminal, Jupyter(IPython))

$ ./sample5.py
5.
python
 Synset('python.n.01'): ['python']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: [Synset('pythoninae.n.01')]
  substance_holonyms: []
 Synset('python.n.02'): ['python']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('python.n.03'): ['Python']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
language
 Synset('language.n.01'): ['language', 'linguistic_communication']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('speech.n.02'): ['speech', 'speech_communication', 'spoken_communication', 'spoken_language', 'language', 'voice_communication', 'oral_communication']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('lyric.n.01'): ['lyric', 'words', 'language']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('linguistic_process.n.02'): ['linguistic_process', 'language']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('language.n.05'): ['language', 'speech']
  member_meronyms: []
  part_meronyms: [Synset('lexis.n.01'), Synset('vocabulary.n.02')]
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('terminology.n.01'): ['terminology', 'nomenclature', 'language']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
creature
 Synset('animal.n.01'): ['animal', 'animate_being', 'beast', 'brute', 'creature', 'fauna']
  member_meronyms: []
  part_meronyms: [Synset('face.n.07'), Synset('head.n.01')]
  substance_meronyms: [Synset('animal_tissue.n.01')]
  member_holonyms: [Synset('animalia.n.01')]
  substance_holonyms: []
 Synset('creature.n.02'): ['creature', 'wight']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('creature.n.03'): ['creature', 'tool', 'puppet']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
dog
 Synset('dog.n.01'): ['dog', 'domestic_dog', 'Canis_familiaris']
  member_meronyms: []
  part_meronyms: [Synset('flag.n.07')]
  substance_meronyms: []
  member_holonyms: [Synset('canis.n.01'), Synset('pack.n.06')]
  substance_holonyms: []
 Synset('frump.n.01'): ['frump', 'dog']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('dog.n.03'): ['dog']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('cad.n.01'): ['cad', 'bounder', 'blackguard', 'dog', 'hound', 'heel']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('frank.n.02'): ['frank', 'frankfurter', 'hotdog', 'hot_dog', 'dog', 'wiener', 'wienerwurst', 'weenie']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('pawl.n.01'): ['pawl', 'detent', 'click', 'dog']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('andiron.n.01'): ['andiron', 'firedog', 'dog', 'dog-iron']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('chase.v.01'): ['chase', 'chase_after', 'trail', 'tail', 'tag', 'give_chase', 'dog', 'go_after', 'track']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
cat
 Synset('cat.n.01'): ['cat', 'true_cat']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('guy.n.01'): ['guy', 'cat', 'hombre', 'bozo']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('cat.n.03'): ['cat']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('kat.n.01'): ['kat', 'khat', 'qat', 'quat', 'cat', 'Arabian_tea', 'African_tea']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('cat-o'-nine-tails.n.01'): ["cat-o'-nine-tails", 'cat']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('caterpillar.n.02'): ['Caterpillar', 'cat']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('big_cat.n.01'): ['big_cat', 'cat']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: [Synset('felidae.n.01')]
  substance_holonyms: []
 Synset('computerized_tomography.n.01'): ['computerized_tomography', 'computed_tomography', 'CT', 'computerized_axial_tomography', 'computed_axial_tomography', 'CAT']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('cat.v.01'): ['cat']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
 Synset('vomit.v.01'): ['vomit', 'vomit_up', 'purge', 'cast', 'sick', 'cat', 'be_sick', 'disgorge', 'regorge', 'retch', 'puke', 'barf', 'spew', 'spue', 'chuck', 'upchuck', 'honk', 'regurgitate', 'throw_up']
  member_meronyms: []
  part_meronyms: []
  substance_meronyms: []
  member_holonyms: []
  substance_holonyms: []
$

0 コメント:

コメントを投稿

Comments on Google+: