Tuesday, July 20, 2004

Spell Checking Code

Considering some homegrown spell checking code.. two variants right now, one using a cache and another w/o. I'm not sure if the use of the cache to avoid calls to IsKnownWord will speed up the algorithm much. But its worth some profiling.

IsKnownWord is a fxn that returns a tuplie: boolean for a correctly spelled / known word, and if the boolean is false, an alternative word list. One possible simplication of IsKnownWord is to assume that if the alternative word list is empty that the word is spelled correctly....

but I'm not so sure since the alternative word list is based on soundex, and perhaps there are no alternatives words for that soundex! So keeping the tuple seems safest to me!


def SpellCheckText(self, text):
unknown_words = {}
for word_match in re_word.finditer(file_data):
word = word_match.group(0)
isKnown, altWords = self.IsKnownWord(word)
if not isKnown:
unknown_words[word_match] = altWords


return unknown_words

def SpellCheckTextUsingCache(self, text):
misspelled_list = []
correct_list = []
unknown_words = {}
for word_match in re_word.finditer(file_data):
word = word_match.group(0)
if word in correct_list:
#Do nothing
elif word in misspelled_list:
unknown_words[word_match] = altWords
else:
isKnown, altWords = self.IsKnownWord(word)
if not isKnown:
unknown_words[word_match] = altWords
misspelled_list.append(word)
else:
correct_list.append(word)

return unknown_words

Monday, July 19, 2004

Starting up

Beginning..