如何使用python nltk检查单词是形容词还是动词? [英] How to check a word if it is adjective or verb using python nltk?

查看:127
本文介绍了如何使用python nltk检查单词是形容词还是动词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些单词列表,例如惊人的、有趣的、爱的、很棒的、不错的.我想检查单词是形容词还是动词,例如love"是动词而 nice 是形容词...如何使用 python 或 nltk 进行操作,有帮助吗?

i have list of words like amazing, interesting, love, great, nice. And i want to check if word is adjective or verb , like "love" is verb and nice is adjective... How to do it using python, or nltk, any help ?

推荐答案

在没有任何上下文的情况下猜测一个词是什么的唯一方法是使用 WordNet,但它不会是 100% 可靠的,因为例如爱"在一个句子中可以有不同的作用.

The only way to guess what a word is without having any context is to use WordNet, but it won't be 100% reliable since for example "love" can have different roles in a sentence.

from nltk.corpus import wordnet as wn
words = ['amazing', 'interesting', 'love', 'great', 'nice']

for w in words:
    tmp = wn.synsets(w)[0].pos()
    print w, ":", tmp

将输出:

amazing : v
interesting : v
love : n
great : n
nice : n

这篇关于如何使用python nltk检查单词是形容词还是动词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆