Is there a reliable way to 'pluralize' english words with Python?
Unfortunately, it won't always be accurate unless you go to great pains. This is due to there being multiple rules (and exceptions to those rules) for the English language.
there are some cookbook recipe in ASPN you can refer to.here.
they may not be wat you want, but at least will give you a head start
Python's regex module re allows you to establish english plural rules in a more condensed from. This one should take care of most common plurals, you may add more rules ...
# using module re to pluralize most common english words
# (rule_tuple used as function default, so establish it first)
# (pattern, search, replace) regex english plural rules tuple
rule_tuple = (
('[ml]ouse$', '([ml])ouse$', '\\1ice'),
('child$', 'child$', 'children'),
('booth$', 'booth$', 'booths'),
('foot$', 'foot$', 'feet'),
('ooth$', 'ooth$', 'eeth'),
('l[eo]af$', 'l([eo])af$', 'l\\1aves'),
('sis$', 'sis$', 'ses'),
('man$', 'man$', 'men'),
('ife$', 'ife$', 'ives'),
('eau$', 'eau$', 'eaux'),
('lf$', 'lf$', 'lves'),
('[sxz]$', '$', 'es'),
('[^aeioudgkprt]h$', '$', 'es'),
('(qu|[^aeiou])y$', 'y$', 'ies'),
('$', '$', 's')
for line in rules:
pattern, search, replace = line
yield lambda word: re.search(pattern, word) and re.sub(search, replace, word)
for rule in regex_rules():
result = rule(noun)
# testing ...
print plural("man") # men
print plural("woman") # women
print plural("lady") # ladies
print plural("wife") # wives
print plural("leaf") # leaves
# okay according to Webster ...
print plural("index") # indexes
print plural("fungus") # funguses
I have gone to "great pains" to create a module that accurately gives the plural of English words: inflect.py
>>> import inflect
>>> p = inflect.engine()
to use it just do:
pip install inflect
Edited 7 Years Ago
by pwdyson: n/a
For simple idea how to deal with singular plural after you have them by program or by literals see my snippet:Kbyte(s) eliminator
I am using Mplab x Ide with v3.61 on Xc8 compiler, PIC18F24K40. I used MCC generated UART code for send and receive data. For understanding I am clubling my code ...
kernel DB 10 DUP(1)
input DB 1, 2, 3, 4, 5, 6, 7
output DB 0, 0, 0, 0, 0, 0, 0
MAIN PROC ...
I can't slove this problem
my code print nothing
what's wrong with it ??
#define total 1000
int weight (char word[total])
int i; ...