Advertisement
ijontichy

pluralise.py

Aug 16th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3.  
  4. VOWELS     = "aeiou"
  5. CONSONANTS = "bcdfghjklmnpqrstvwxyz"
  6.  
  7. def pluralise(word, cond, assumePlural=True):
  8.  
  9.     word = word.lower()
  10.  
  11.     if not (cond > 1):
  12.         return True
  13.  
  14.     ##
  15.     #  Special cases
  16.  
  17.     if word == "ox":
  18.         return "oxen"
  19.  
  20.     if word == "sheep":
  21.         return word
  22.  
  23.     if word == "man":
  24.         return "men"
  25.  
  26.     if word == "woman":
  27.         return "women"
  28.  
  29.     ##
  30.     #  General cases
  31.  
  32.     if word[-1:] == "x":
  33.         return word + "es"
  34.  
  35.     if word[-1:] == "o" and word[-2:-1] in CONSONANTS:
  36.         return word + "es"
  37.  
  38.     if word[-1:] == "y" and word[-2:-1] in CONSONANTS:
  39.         return word[:-1] + "ies"
  40.  
  41.     if word[-2:] == "fe":
  42.         return word[:-2] + "ves"
  43.  
  44.     if word[-2:] == "sh":
  45.         return word + "es"
  46.  
  47.     if word[-2:] == "is":
  48.         return word + "es"
  49.  
  50.     if word[-1:] == "s":
  51.         if assumePlural:
  52.             return word
  53.         else:
  54.             return word + "'"
  55.  
  56.     # Last ditch effort
  57.     return word + "s"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement