Skip to content

Instantly share code, notes, and snippets.

@gearmonkey
Created January 17, 2013 11:44
Show Gist options
  • Save gearmonkey/4555404 to your computer and use it in GitHub Desktop.
Save gearmonkey/4555404 to your computer and use it in GitHub Desktop.
really stupid plural checker.
def is_plural(a,b):
"""a really stupid pluralisation checker, english only
returns true if b is standard form plural of a (or vis-a-versa) as defined by these rules:
adds s or es
subs y for ies
subs f or fe for ves
based on http://en.wikipedia.org/wiki/English_plural this should cover regular and near-regular plurals
"""
if len(a) == len(b):
#all [near-]regular plurals are longer, so:
return False
singular = min(a,b,key=len).lower()
plural = max(a,b,key=len).lower()
if singular + 's' == plural or singular + 'es' == plural:
return True
if singular[-1] == 'y':
if singular[:-1] + 'ies' == plural:
return True
if singular[-1] == 'f' or singular[-2:] == 'fe':
if singular[:-1] + 'ves' == plural or singular[:-2] + 'ves' == plural:
return True
#fail
return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment