Search code examples
pythonnlp

How can I conjugate English words to the progressive form in Python?


I have looked at pattern.en's conjugate, but it only conjugates into a few forms, and I would rather not have to sit down and program all of the exceptions to those rules that would allow me to make conjugations such as

  • free - freeing
  • eat - eating
  • bathe - bathing
  • be - being
  • ban - banning

nltk has stemming, but it doesn't seem to have the reverse operation, at least from searching StackOverflow. This seems like a very elementary NLP task, but I cannot find anything modern that does this in Python. Any general conjugation tool would be nice, although the progressive form in English doesn't have irregularities I know of.

I am also trying to see if there are exceptions to this rule, which might work as an alternate function:

def present_to_progressive(x):
    vowels = set(['a','e','i','o','u'])
    size = len(x)
    if size == 2:
        return x + 'ing'
    elif x[size - 2:] == 'ie':
        return x[:(size-2)] + 'ying'
    elif x[size - 1] not in vowels and x[size - 2] not in vowels:
        return x + 'ing'
    elif x[size - 1] == 'e' and x[size-2] not in vowels:
        return x[0:(size-1)] + 'ing'
    elif x[size - 1] not in vowels and x[size-2] in vowels:
        if x[size - 3] not in vowels:
             return x + x[size-1] + 'ing'
        else:
             return x + 'ing'
    else:
        return x + 'ing'

Edit: Added case for "ie" verbs


Solution

  • There is an entire library for this type of modification that does what you want. It is called pattern.en

    you can find it here: pattern.en

    It is a good source.

    Here is an excerpt from the conjugation tutorial on the site:

    conjugate(verb, 
        tense = PRESENT,        # INFINITIVE, PRESENT, PAST, FUTURE
       person = 3,              # 1, 2, 3 or None
       number = SINGULAR,       # SG, PL
         mood = INDICATIVE,     # INDICATIVE, IMPERATIVE, CONDITIONAL, SUBJUNCTIVE
       aspect = IMPERFECTIVE,   # IMPERFECTIVE, PERFECTIVE, PROGRESSIVE 
      negated = False,          # True or False
        parse = True)   
    

    It is quite useful and very expansive!