Bac*_*kue 5 python nltk wordnet
有什么方法可以使用 nltk wordnet 来检测给定的单词是否是名词?我也想单独提取特定单词的含义。怎么做?
要检测一个词是否是名词,试试这个。
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'
Run Code Online (Sandbox Code Playgroud)
为了解决第二部分 - 一个词可能有多种含义,您需要清楚地定义您的意思 - 单词之间存在各种关系,例如上位词、同名词、下位词、同义词等。
还要找到与给定单词的含义最接近的含义,您可能需要找到一个单词与其每个同义词集之间的相似性,并选择具有最高值的那个。有关更多信息,请参阅 Wordnet 中的 LCH 相似性和 JCN 相似性模块
| 归档时间: |
|
| 查看次数: |
2346 次 |
| 最近记录: |