Converting plural to singular in a text file with Python

后端 未结 3 648
予麋鹿
予麋鹿 2021-01-04 23:01

I have txt files that look like this:

word, 23
Words, 2
test, 1
tests, 4

And I want them to look like this:

word, 23
word,          


        
3条回答
  •  逝去的感伤
    2021-01-04 23:22

    The Nodebox English Linguistics library contains scripts for converting plural form to single form and vice versa. Checkout tutorial: https://www.nodebox.net/code/index.php/Linguistics#pluralization

    To convert plural to single just import singular module and use singular() function. It handles proper conversions for words with different endings, irregular forms, etc.

    from en import singular
    print(singular('analyses'))   
    print(singular('planetoids'))
    print(singular('children'))
    >>> analysis
    >>> planetoid
    >>> child
    

提交回复
热议问题