2013-07-15 116 views

回答

4

要检测一个单词是否是名词,请尝试此操作。

from nltk.corpus import wordnet as wn 
from nltk.corpus.reader import NOUN 

#this gives a synsets list of empty length, since there is no noun corresponding to 'propose' 
synsets = wn.synsets('propose', NOUN) 

if synsets.length == 0 : 
    print ' We found a pure NOUN' 

#this will give you a non empty synset list since 'iron' can be a NOUN too. 
synsets = wn.synsets('iron',NOUN) 

if synsets.length > 0 : 
    print 'Iron is also a noun other than verb' 

为了解决第二部分 - 一个字可以有多种含义,你要定义你的意思是清楚的 - 有句话如hypernymy,holonymy,上下义,同义词等之间的各种关系

同时找到与给定单词最接近的含义,您可能需要找出单词与每个单词的同义词之间的相似度,然后选取具有最高值的单词。请参阅Wordnet中的LCH相似性和JCN相似性模块,以获取关于此的更多信息。

+0

我将尝试使用此..谢谢! – Backue

+0

您的意思是:打印'我们发现了一个纯粹的非名字' – Vladtn

+0

是的..正确..请不要错过键:) –