Created
June 6, 2015 16:02
-
-
Save JeffreyMFarley/73994c4f36ad288ca049 to your computer and use it in GitHub Desktop.
Determine how to create the present participle from the root word
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Participle: | |
def __init__(self, ending): | |
self.vowels = ['a', 'e', 'i', 'o', 'u'] | |
self.doublingConsonants = ['b', 'd', 'g', 'k', 'l', 'm', 'n', | |
'p', 'r', 't', 'v', 'z'] | |
self.vvgExceptions = { | |
'abhor': 'abhorring', | |
'aver': 'averring', | |
'ballot': 'balloting', | |
'babysit': 'babysitting', | |
'baby-sit': 'baby-sitting', | |
'buffet': 'buffeting', | |
'carol': 'caroling', | |
'discomfit' : 'discomfiting', | |
'excel': 'excelling', | |
'fillet': 'filleting', | |
'fret': 'fretting', | |
'gas': 'gassing', | |
'glom': 'glomming', | |
'grit': 'gritting', | |
'mortar': 'mortaring', | |
'murmur': 'murmuring', | |
'nom': 'nomming', | |
'parrot': 'parroting', | |
'pen': 'penning', | |
'pivot': 'pivoting', | |
'pilfer': 'pilfering', | |
'profit': 'profiting', | |
'rebel': 'rebelling', | |
'regret':'regretting', | |
'rival': 'rivaling', | |
'segue': 'segueing', | |
'singe': 'singeing', | |
'surveil': 'surveilling', | |
'target': 'targeting', | |
'vomit': 'vomiting', | |
'whet': 'whetting' | |
} | |
self.vvgPipeline = [self._vvgExceptions, | |
self._addK, | |
self._qDoubleVowel, | |
self._doubleVowel, | |
self._fer, | |
self._pel, | |
self._noDoublingCheckLast2, | |
self._noDoublingCheckLast3, | |
self._noDoublingCheckLast4, | |
self._noDoublingCheckLast5, | |
self._doubleConsonant, | |
self._dropIEaddY, | |
self._dropE, | |
self._default] | |
self.ending = 'ing' | |
def _addK(self, w0): | |
if w0[-2:] in ['ac', 'ic']: | |
return w0 + 'k' + self.ending | |
def _default(self, w0): | |
return w0 + self.ending | |
def _doubleConsonant(self, w0): | |
if len(w0) > 1 and w0[-2] in self.vowels and w0[-1] in self.doublingConsonants: | |
root = w0[:-1] | |
double = w0[-1] | |
return root + double + double + self.ending | |
def _doubleVowel(self, w0): | |
if len(w0) > 2 and w0[-3] in self.vowels and w0[-2] in self.vowels: | |
return w0 + self.ending | |
def _dropE(self, w0): | |
if len(w0) > 1 and w0[-1] == 'e' and w0[-2] not in ['e', 'o']: | |
return w0[:-1] + self.ending | |
def _dropIEaddY(self, w0): | |
if w0[-2:] == 'ie': | |
return w0[:-2] + 'y' + self.ending | |
def _fer(self, w0): | |
if w0[-3:] == 'fer' and w0[-4:] != 'ffer': | |
return w0 + 'r' + self.ending | |
def _noDoublingCheckLast2(self, w0): | |
if w0[-2:] in ['er', 'el', 'en', 'om', 'on', 'or']: | |
return w0 + self.ending | |
def _noDoublingCheckLast3(self, w0): | |
''' | |
check for length greater than 3 because 'pet' and 'vet' double, | |
but not 'carpet' and 'rivet' | |
''' | |
if len(w0) > 3 and w0[-3:] in ['bit', 'cil', 'cit', 'dit', 'gar', | |
'het', 'ket', 'lar', 'met', 'pet', | |
'ret', 'ril', 'rit', 'sit', 'vet', | |
'vil', 'xit']: | |
return w0 + self.ending | |
def _noDoublingCheckLast4(self, w0): | |
if w0[-4:] in ['dget', 'elop', 'llop']: | |
return w0 + self.ending | |
def _noDoublingCheckLast5(self, w0): | |
if w0[-5:] in ['limit', 'pilot']: | |
return w0 + self.ending | |
def _pel(self, w0): | |
if w0[-3:] == 'pel': | |
return w0 + 'l' + self.ending | |
def _qDoubleVowel(self, w0): | |
''' squat, acquit, quiz, quit, equip | |
but not equal and conquer | |
''' | |
if w0[-4:] in ['qual', 'quer']: | |
return None | |
if (len(w0) > 3 and w0[-4] == 'q' | |
and w0[-3] in self.vowels and w0[-2] in self.vowels | |
and w0[-1] in self.doublingConsonants): | |
root = w0[:-1] | |
double = w0[-1] | |
return root + double + double + self.ending | |
def _vvgExceptions(self, w0): | |
if w0 in self.vvgExceptions: | |
return self.vvgExceptions[w0] | |
def toParticiple(self, w0): | |
for fn in self.vvgPipeline: | |
vvg = fn(w0) | |
if vvg: | |
return vvg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment