2016-04-14 18 views
0

Wordnet'i thesarus olarak kullanmayı denedim, bu yüzden bir kelime listemiz var ve her kelimesi için eş anlamlılarını topladım. BuWordnet'teki sözcüklerin eşanlamlarını bulma

from nltk.corpus import wordnet as wn 
for i,j in enumerate(wn.synsets('dog')): 
    print (j.lemma_names) 

Bu kod aşağıdaki çıktıyı

<bound method Synset.lemma_names of Synset('dog.n.01')> 
<bound method Synset.lemma_names of Synset('frump.n.01')> 
<bound method Synset.lemma_names of Synset('dog.n.03')> 
<bound method Synset.lemma_names of Synset('cad.n.01')> 
<bound method Synset.lemma_names of Synset('frank.n.02')> 
<bound method Synset.lemma_names of Synset('pawl.n.01')> 
<bound method Synset.lemma_names of Synset('andiron.n.01')> 
<bound method Synset.lemma_names of Synset('chase.v.01')> 

verir Ama sadece eş bir listede toplamak istediğiniz çalıştı, bu nedenle çıktı bu

[ 'kocakarı' gibi olacak 'cad', 'frank', 'pawl', 'andiron', 'chase']

+0

Baskı (j.lemma_names) 'yazdırmayı (j.lemma_names())' son satırını değiştirirseniz ne olur? – davedwards

cevap

0

Çıktınızın gösterdiği gibi, lemma_names bir özellik değil, bir yöntemdir. Eğer beklendiği gibi Oral kodu çalışır:

from nltk.corpus import wordnet as wn 
result = [st.lemma_names()[0] for st in wn.synsets('dog')] 
print(result) 

çıktısı:

[u'dog', u'frump', u'dog', u'cad', u'frank', u'pawl', u'andiron', u'chase'] 

listedeki öğeler Unicode dizesi olduğunu unutmayın. Bu nedenle, çıktıda önde gelen u görüyorsunuz.