Ted*_*rou 5 python synonym nltk wordnet
我想知道是否有一种简单的方法可以获取 wordnet 中名词的同义词。看来形容词的同义词很容易找到。
for ss in wn.synsets('beautiful'):
print(ss)
for sim in ss.similar_tos():
print(' {}'.format(sim))
Run Code Online (Sandbox Code Playgroud)
我从另一个 SO 问题中找到了上面的代码,它对于形容词效果很好。但当我说“汽油”或“火”时,结果就很糟糕了。理想情况下,我会得到一个与该网站非常相似的单词列表。
我尝试过的其他方法取得了良好的效果,但速度非常慢,如下:
def syn(word, lch_threshold=2.26):
for net1 in wn.all_synsets():
try:
lch = net1.lch_similarity(wn.synset(word))
except:
continue
# The value to compare the LCH to was found empirically.
# (The value is very application dependent. Experiment!)
if lch >= lch_threshold:
yield (net1, lch)
for x in syn('gasoline.n.1'):
print x
Run Code Online (Sandbox Code Playgroud)
这也是从另一个 SO 问题中找到的。有没有更简单的方法来获取上面提供的链接中的名词同义词?