python - 生成名词的复数形式

标签 python nlp wordnet linguistics

给定一个单词,它可能是也可能不是单数形式的名词,你将如何生成它的复数形式?

基于此NLTK tutorial还有这个informal list关于复数规则,我写了这个简单的函数:

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'

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

最佳答案

pattern-en 包提供 pluralization

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

关于python - 生成名词的复数形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18902608/

相关文章:

python - django.db.utils.ProgrammingError : (1146, "Table ' med_portal.Custparent'不存在”)

algorithm - N-gram文本分类类别大小差异补偿

python - 对 "A lot"、 "A few"、 "some"等单词进行分类的简单方法

c++ - findtheinfo_ds() 中的 WordNet SynSet ptrlist 仅进入一级

python - 如何修改 python 中的库并使用它?

用于创建可处理数百万行的 XLSX 文档的 Python(或 C)库

python - 将推文分类为多个类别(无监督数据/推文)

java - 获取树结构中所有可能的路径

nlp - 如何获取单词的语义类型?

python - 用Python通过打印机打开till