英语形态学软件

时间:2015-08-16 16:09:53

标签: nlp

在我的应用程序中,我需要使用一个软件能够:a)将单词转换为基本形式; b)查找它们是否为“名词”,“动词”等。

我找到了能够完成这项工作的软件列表。

http://aclweb.org/aclwiki/index.php?title=Morphology_software_for_English

有没有人对这些经历有任何经验?你推荐哪一个?

1 个答案:

答案 0 :(得分:-1)

您可以使用NLTK(Python)来执行这些任务。

  

查看它们是否是“名词”,“动词”......

此任务称为Part-of-speech tagging。您可以使用nltk.pos_tag功能。 (见Peen Treebank tagset

  

将单词转换为基本形式

此任务称为lemmatization。您可以使用nltk.stem.wordnet.WordNetLemmatizer.lemmatize功能。

示例

import nltk
from nltk.stem.wordnet import WordNetLemmatizer
from nltk.corpus import wordnet as wn

penn_to_wn = lambda penn_tag: {'NN':wn.NOUN,'JJ':wn.ADJ,'VB':wn.VERB,'RB':wn.ADV}.get(penn_tag[:2], wn.NOUN)

sentence = "The rabbits are eating in the garden."
tokens = nltk.word_tokenize(sentence)
pos_tags = nltk.pos_tag(tokens)
wl = WordNetLemmatizer()
lemmas = [wl.lemmatize(token, pos=penn_to_wn(tag)) for token, tag in pos_tags]

然后,如果您打印结果:

>>> tokens
['The', 'rabbits', 'are', 'eating', 'in', 'the', 'garden', '.']

>>> pos_tags
[('The', 'DT'),
 ('rabbits', 'NNS'),
 ('are', 'VBP'),
 ('eating', 'VBG'),
 ('in', 'IN'),
 ('the', 'DT'),
 ('garden', 'NN'),
 ('.', '.')]

>>> lemmas
['The', u'rabbit', u'be', u'eat', 'in', 'the', 'garden', '.']