I need to define a function that translates an sentence from present to past.
A. put all words in lower case and omit all punctuation
B. Plural and singular verbs should be recognized
C. verbs ending in "y" change to "ied"
D. verbs ending in "e" add "d"
E. other verb stems add "ed"
F. treat words as regular verbs if their stems are in regular verb set
G treat words as irregular verbs if their are irregular verb dictionary

I also have 2 List
1. regular verb
2. irregular verb

My problem is this problem seams complex, so i am a little confused. If someone could show me how to get started that would be great. If anyone has a webpage that could walk me through this let me know.

Thanks

Yes, this does seem somewhat complex, but you can do it in steps. After each step, make sure your program continues to work as well as it can at that step.

  1. First, think about how this program interacts with the user. Write something that does the interaction, but none of the 'real' work. Maybe it just prints out (or saves) the sentence unchanged.
  2. Once you have that working correctly, add one thing. I suggest that you figure out how to split the sentence into words, strip punctuation and lower case all the words (hint: Sentences are strings and strings have a method split() that you will probably find useful. Each word is also a string and strings have a method lower() that will also be useful.
  3. Then, I suggest you recognize plural versus singular verbs. How will you do that? Is it possible to do it only for verbs? How?
  4. At this point, you have a simple word to look at, no more special cases left from the spelling or number, so you can start to apply the rules. First rule needs to be 'regular' or 'irregular', so you don't do a 'regular' thing to the irregular verbs. This is an if/else situation.
  5. If the verb stem is irregular, look up the past tense, deal with the plurality, and print/save it
  6. If the verb stem is regular, look at the final letter and based on three choices, change the ending as specified in C, D and E; then print/save the result
  7. Now you have to reconstruct the original sentence into a past-tense version. Way up at step 2, you broke the sentence apart and altered the case and punctuation. Now, way down here, you want that information back again. Fortunately, you can handle each word in the sentence one at a time, keeping the original and making a lower-case, punctuation-removed, stemmed version to look up in the verb list. If it isn't in the list, just move on, but if it is, then you will do the work only for that word. You can actually alter the original, once you have recognized it, then the only issue is replacing punctuation if you it was there. For instance, the sentence "They run." will be looked at as:
    1. Is there more? Yes:
    2. Do 'They' -> 'they'-> not irregular -> not regular: Place original: "They".
    3. Is there more? Yes: place a space.
    4. Do: 'run.' -> 'run'(save the period) -> is irregular -> 'ran' -> (replace period) 'ran.' place 'ran.'
    5. Is there more? No. Done

Remember, writing this program/function is a step by step process: Don't get overwhelmed by the initial size: Just do one thing at a time; and each step will be small enough to handle. And if you do as I suggest, by starting with a very simple program that does nothing much (but does it well), you will always have something that you know worked a minute ago, so you can always test, edit, test, edit, ... without fear of getting into a dead end where "nothing works".

PS. Don't worry if things come out odd. "Run!" says Sally. will translate to "Ran!" said Sally. Nothing you can reasonably do about it: It turns out that parsing natural language sentences is extremely hard.

Edited 6 Years Ago by griswolf: n/a

This code would be extremely helpfull starting point if you can handle it. You would probably need to do some read up on itertools and list comprehensions before you continue:

from itertools import groupby

def isletter(c):
    return c.isalpha()

sentence = "First, think about how this program interacts with the user. Write something that does the interaction, but none of the 'real' work."
parsing = [''.join(letters) for group, letters in groupby(sentence, isletter)]
print parsing
# only every second
print 'Words:\n\t','\n\t'.join(parsing[::2])
print 'Punctuations/whitespace: ', parsing[1::2]

Edited 6 Years Ago by pyTony: n/a

Post some trial code for as much of
"A. put all words in lower case and omit all punctuation"
as you can so we have something to comment on.

"put all words in lower case" = use the lower() function
"omit all punctuation" = loop through the text and omit anything that is not, since it now all lower case, between "a" and "z".

Edited 6 Years Ago by woooee: n/a

This article has been dead for over six months. Start a new discussion instead.