2017-10-03 14 views
-1

WordNetによる名詞、動詞、形容詞、副詞の平均多義性を計算しようとしています。 これは私が定義した関数である。私はそれを呼び出すとWordNetによる名詞、動詞、形容詞、副詞の平均多項式を計算する

def averagePolysemy(synsets): 
    allSynsets = list(wn.all_synsets(synsets)) 
    lemmas = [synset.lemma_names() for synset in allSynsets] 
    senseCount = 0 
    for lemma in lemmas: 
     senseCount = senseCount + len(wn.synsets(lemma, synsets)) 
    return senseCount/len(allSynsets) 

averagePolysemy(wn.NOUN) 

私はエラーを取得する:

Traceback (most recent call last): 

File "<ipython-input-214-345e72500ae3>", line 1, in <module> 
averagePolysemy(wn.NOUN) 

File "<ipython-input-213-616cc4af89d1>", line 6, in averagePolysemy 
senseCount = senseCount + len(wn.synsets(lemma, synsets)) 

File "/Users/anna/anaconda/lib/python3.6/site- 
packages/nltk/corpus/reader/wordnet.py", line 1483, in synsets 
lemma = lemma.lower() 

AttributeError: 'list' object has no attribute 'lower'e 'lower' 

私はこのエラーの原因となっている私の機能のどの部分かわかりません。

+0

完全なトレースバックを表示してください。 – BrenBarn

+0

おそらく 'synset.lemma_names'は' sysnet.lemma_names() 'でなければなりませんか? – BrenBarn

+0

私はそれを調整しましたが、同じエラーがまだ残っています – Anna

答えて

0

まず、ポリシームを定義します。

Polysemy: The coexistence of many possible meanings for a word or phrase.

(出典:https://www.google.com/search?q=polysemy

Wordnetから:

WordNet® is a large lexical database of English. Nouns, verbs, adjectives and adverbs are grouped into sets of cognitive synonyms (synsets), each expressing a distinct concept. Synsets are interlinked by means of conceptual-semantic and lexical relations.

そしてWordNetの中で、我々は精通している必要があり、いくつかの条件があります。

Synset: a distinct concept/meaning

Lemma: a root form of a word

Part-Of-Speech (POS): the linguistic category of a word

Word: a surface form of a word (surface words are not in WordNet)

が(注: @alexisはlemma vs synsetの回答が良いです:https://stackoverflow.com/a/42050466/610569;コードでもhttps://stackoverflow.com/a/23715743/610569https://stackoverflow.com/a/29478711/610569

を参照してください:

from nltk.corpus import wordnet as wn 
# Given a word "run" 
word = 'run' 
# We get multiple meaning (i.e. synsets) for 
# the word in wordnet. 
for synset in wn.synsets(word): 
    # Each synset comes with an ID. 
    offset = str(synset.offset()).zfill(8) 
    # Each meaning comes with their 
    # linguistic category (i.e. POS) 
    pos = synset.pos() 
    # Usually, offset + POS is the way 
    # to index a synset. 
    idx = offset + '-' + pos 
    # Each meaning also comes with their 
    # distinct definition. 
    definition = synset.definition() 
    # For each meaning, there are multiple 
    # root words (i.e. lemma) 
    lemmas = ','.join(synset.lemma_names()) 
    print ('\t'.join([idx, definition, lemmas])) 

[出]:

00189565-n a score in baseball made by a runner touching all four bases safely run,tally 
00791078-n the act of testing something test,trial,run 
07460104-n a race run on foot footrace,foot_race,run 
00309011-n a short trip run 
01926311-v move fast by using one's feet, with one foot off the ground at any given time run 
02075049-v flee; take to one's heels; cut and run scat,run,scarper,turn_tail,lam,run_away,hightail_it,bunk,head_for_the_hills,take_to_the_woods,escape,fly_the_coop,break_away 

バックの質問に行く、はどのように「名詞の平均多義性を計算します、動詞、形容詞と副詞WordNetによると "

WordNetで作業しているので、面白い言葉が使われていないため、補題だけが残っています。

まず、どのような補題が名詞、動詞、形容詞に含まれているかを定義する必要があります。

from nltk.corpus import wordnet as wn 
from collections import defaultdict 

words_by_pos = defaultdict(set) 

for synset in wn.all_synsets(): 
    pos = synset.pos() 
    for lemma in synset.lemmas(): 
     words_by_pos[pos].add(lemma) 

しかし、これはPOS対補題関係の単純化した図である。

# There are 5 POS. 
>>> words_by_pos.keys() 
dict_keys(['a', 's', 'r', 'n', 'v']) 

# Some words have multiple POS tags =(
>>> len(words_by_pos['n']) 
119034 
>>> len(words_by_pos['v']) 
11531 
>> len(words_by_pos['n'].intersection(words_by_pos['v'])) 
4062 

我々はそれを無視して上を移動できるかどうか見てみましょう:

# Lets look that the verb 'v' category 
num_meanings_per_verb = [] 

for word in words_by_pos['v']: 
    # No. of meaning for a word given a POS. 
    num_meaning = len(wn.synsets(word, pos='v')) 
    num_meanings_per_verb.append(num_meaning) 
print(sum(num_meanings_per_verb)/len(num_meanings_per_verb)) 

[出]:

2.1866273523545225 

番号は何を意味しますか?それは2つの意味の平均がWordNetの中のすべての動詞のうち

  • があることを意味する

    (それがすべてでは何を意味している場合)。

  • いくつかの単語は、他のPOSカテゴリおそらく

でより多くの意味を持っているという事実を無視して、そこに多分、それにはいくつかの意味であるが、我々はnum_meanings_per_verb内の値の数を見れば:

Counter({1: 101168, 
     2: 11136, 
     3: 3384, 
     4: 1398, 
     5: 747, 
     6: 393, 
     7: 265, 
     8: 139, 
     9: 122, 
     10: 85, 
     11: 74, 
     12: 39, 
     13: 29, 
     14: 10, 
     15: 19, 
     16: 10, 
     17: 6, 
     18: 2, 
     20: 5, 
     26: 1, 
     30: 1, 
     33: 1}) 
関連する問題