Just like that, I've managed to program something (to a very loose approximation) like intelligence into my parser. The problem whose solution eluded me yesterday was how to get the right position of the stem using find() (or some variant thereof). I had mentioned the possibility of using len() to figure out which part of the string to look in. I thought about the problem more today, and this is what I came up with -- basically, a test to see whether the stem I'm looking for is in the right part of the string:
def parse(verb):What I realized is that I need to start at the end of the string and go back to the beginning of the stem. So it's actually pretty simple: if parse() finds the beginning of the stem in that position, that's the stem I want. Otherwise, keep looking.
for conj in conjugations:
if verb.rfind(conj) == len(verb)-len(conj):
return(stems[conj])
else:
continue
I could keep improving this app by expanding the dictionary. It only handles a few of the first conjugation entries as it is. But that just seems like a process of adding more data -- I'm not sure how many fresh challenges this app still has for me in terms of implementation. So I may be setting it aside for awhile to work on some other string processing tasks.
Comments
Post a Comment