"""Pluralize English nouns (stage 4)This program is part of "Dive Into Python", a free Python book forexperienced programmers. Visit http://diveintopython.org/ for thelatest version.Command line usage:$ python plural4.py nounnouns"""__author__="Mark Pilgrim (mark@diveintopython.org)"__version__="$Revision: 1.3 $"__date__="$Date: 2004/03/18 16:43:37 $"__copyright__="Copyright (c) 2004 Mark Pilgrim"__license__="Python"importredefbuildMatchAndApplyFunctions((pattern,search,replace)):matchFunction=lambdaword:re.search(pattern,word)applyFunction=lambdaword:re.sub(search,replace,word)return(matchFunction,applyFunction)patterns= \
(('[sxz]$','$','es'),('[^aeioudgkprt]h$','$','es'),('(qu|[^aeiou])y$','y$','ies'),('$','$','s'))rules=map(buildMatchAndApplyFunctions,patterns)defplural(noun):formatchesRule,applyRuleinrules:ifmatchesRule(noun):returnapplyRule(noun)if__name__=='__main__':importsysifsys.argv[1:]:printplural(sys.argv[1])else:print__doc__