向python模式singulariz添加术语的好方法

2024-09-27 04:22:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用python模式来获取英语名词的单数形式。在

    In [1]: from pattern.en import singularize
    In [2]: singularize('patterns')
    Out[2]: 'pattern'
    In [3]: singularize('gases')
    Out[3]: 'gase'

我在解决第二个问题

^{pr2}$

有没有更好的方法来做到这一点,例如添加到模式的规则中,或者使exceptionDict在某种程度上成为模式的内部元素?在


Tags: infromimport模式out形式patternsen
1条回答
网友
1楼 · 发布于 2024-09-27 04:22:05

正如评论中所提到的,你最好把单词词组化。 它是nltk stemming module的一部分。在

from nltk.stem import WordNetLemmatizer

wnl = WordNetLemmatizer()
test_words = ['gases', 'spectrum','cross','nuclei']
%timeit [wnl.lemmatize(wrd) for wrd in test_words]

10000 loops, best of 3: 60.5 µs per loop

与你的功能相比

^{pr2}$

nltk柠檬化性能更好。在

相关问题 更多 >

    热门问题