确定单词是否为名词 [英] Determining whether a word is a noun or not

查看:131
本文介绍了确定单词是否为名词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个输入的单词,我想确定它是否是一个名词(如果有歧义,例如cook可以是名词或动词,则必须将该单词标识为名词).

Given an input word, I want to determine whether it is a noun or not (in case of ambiguity, for instance cook can be a noun or a verb, the word must be identified as a noun).

实际上,我使用Stanford Parser中的POS标记器(我给它一个单词作为输入,并且我仅从结果中提取POS标记).结果相当不错,但需要很长时间.

Actually I use the POS tagger from the Stanford Parser (i give it a single word as input, and i extract only the POS tag from the result). The results are quite good but it takes a very long time.

有没有一种方法(在python中,请:)比我实际执行的任务更快?

Is there a way (in python, please :) to perform this task quicker than what I do actually?

推荐答案

如果您只是想检查一个单词是否可以用作名词,最快的方法可能是建立一组所有名词,然后只需检查单词是否属于该集合即可.

If you simply want to check whether or not a single word can be used as a noun, the quickest way might be to build a set of all nouns and then just check the word for membership of that set.

要获取所有名词的列表,可以使用 WordNet 语料库(可以是例如通过NLTK访问):

For a list of all nouns you could use the WordNet corpus (which can be accessed through NLTK for example):

>>> from nltk.corpus import wordnet as wn
>>> nouns = {x.name().split('.', 1)[0] for x in wn.all_synsets('n')}
>>> "cook" in nouns
True
>>> "and" in nouns
False

这篇关于确定单词是否为名词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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