I was frustrated while changing the tense of a document, and decided to go down the deep dark rabbit hole of creating an automatic tense changer. The basic usage is:
from tenseflow import change_tense change_tense('I will go to the store.', 'past') u'I went to the store.'
Little did past-Ben know, this is a really tough task, for a few reasons. For anyone who wants to venture down this path, here are a few of the finer points you’ll need to deal with:
- Identifying verbs is harder than it looks. For instance, take the word “vacuum.” This word could be used as a noun, (“Please hand me the vacuum.”) or verb (“Please vacuum the dining room.”) Vacuum is not a special word- in fact if you think about it, most verbs in the English language can be used as nouns and most nouns can be used as verbs. If you blindly convert any word that could be a verb, you’ll get nonsense like “Please vacuumed the dining room.” Therefore, in order to properly tense-alter a passage, you need to first parse the sentence to determine what words are are being used as verbs. You also need to parse their role in the sentence. For instance, infinitives do not change with tense. (We don’t want e.g. “You asked me to vacuumed)”.
- Once you have identified which word you want to change, there are so many irregular verbs and special rules, you really need an entire dictionary to do this properly.
- There are more tenses in English than you might realize. Common wisdom is that we have 3: past, present, and future. In fact, there are 12, and each of them has three modes: affirmative, negative, and interrogative.
- There are all sorts of cases where you would want to have multiple tenses in the same sentence, and there isn’t really a good way to infer this automatically.
Despite these obstacles, I managed to make a tool that works… OK. It comes with a web-app. Check it out on GitHub here.