生成名词的复数形式 [英] Generating the plural form of a noun

查看:139
本文介绍了生成名词的复数形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个单词,该单词可能是也可能不是单数形式的名词,您将如何生成其复数形式?

Given a word, which may or may not be a singular-form noun, how would you generate its plural form?

基于此 NLTK教程和此

Based on this NLTK tutorial and this informal list on pluralization rules, I wrote this simple function:

def plural(word):
    """
    Converts a word to its plural form.
    """
    if word in c.PLURALE_TANTUMS:
        # defective nouns, fish, deer, etc
        return word
    elif word in c.IRREGULAR_NOUNS:
        # foot->feet, person->people, etc
        return c.IRREGULAR_NOUNS[word]
    elif word.endswith('fe'):
        # wolf -> wolves
        return word[:-2] + 'ves'
    elif word.endswith('f'):
        # knife -> knives
        return word[:-1] + 'ves'
    elif word.endswith('o'):
        # potato -> potatoes
        return word + 'es'
    elif word.endswith('us'):
        # cactus -> cacti
        return word[:-2] + 'i'
    elif word.endswith('on'):
        # criterion -> criteria
        return word[:-2] + 'a'
    elif word.endswith('y'):
        # community -> communities
        return word[:-1] + 'ies'
    elif word[-1] in 'sx' or word[-2:] in ['sh', 'ch']:
        return word + 'es'
    elif word.endswith('an'):
        return word[:-2] + 'en'
    else:
        return word + 's'

但是我认为这是不完整的.有更好的方法吗?

But I think this is incomplete. Is there a better way to do this?

推荐答案

pattern-en软件包(适用于python 2.5+,但不适用于python 3)提供

The pattern-en package (for python 2.5+, but not python 3 yet) offers pluralization

>>> import pattern.en
>>> pattern.en.pluralize("dog")
'dogs'
>>> 

这篇关于生成名词的复数形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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