小编李恒通*_*李恒通的帖子

为什么 wordnet 中的 NLTK wn.all_synsets() 函数不返回同义词集列表?

我为这个问题编写代码:

没有下义词的名词同义词集的百分比是多少?您可以使用 wn.all_synsets('n') 获取所有名词同义词集。

这是我的代码:

import nltk
from nltk.corpus import wordnet as wn

all_noun = wn.all_synsets('n')
print(all_noun)
print(wn.all_synsets('n'))
all_num = len(set(all_noun))
noun_have_hypon = [word for word in wn.all_synsets('n') if len(word.hyponyms()) >= 1]
noun_have_num = len(noun_have_hypon)
print('There are %d nouns, and %d nouns without hyponyms, the percentage is %f' %
  (all_num, noun_have_num, (all_num-noun_have_num)/all_num*100))
Run Code Online (Sandbox Code Playgroud)

当我运行这段代码时,输​​出是

<generator object all_synsets at 0x10927b1b0>

<generator object all_synsets at 0x10e6f0bd0>

有名词 82115 个,无下位词名词 16693 个,百分比为 79.671193

但如果改变

noun_have_hypon = [word for word in wn.all_synsets('n') if len(word.hyponyms()) >= …

python nlp generator nltk wordnet

3
推荐指数
1
解决办法
2628
查看次数

标签 统计

generator ×1

nlp ×1

nltk ×1

python ×1

wordnet ×1