Today's objective is to create a simple spellchecker. Your spellchecker should remove duplicate letters from words to form real words. For instance:
smilee -> smile (remove extra e) stoop -> stoop (stoop doesn't become stop because stoop is a word)
For a bonus also fix incorrect vowels. For English, "weke" could be come "woke" or "wake".
Most Linux distros come with a built in dictionary or you can find one by searching the internet. Here is one I found for English.
Comments:
Nick Krichevsky - 10 years, 7 months ago
Python solution ``` from sys import exit f=open("wordsEn.txt",'r') words=[] for line in f: words.append(line.strip()) word=raw_input() word=word.lower() vowels='aeiouy' if word in words: print "Already spelled correctly." else: origWord=word charCounts={} prevPos=0 for char in word: if char in vowels: for vowel in vowels: if vowel is not char: pos=word.index(char,prevPos) newString=word[0:pos]+vowel+word[pos+1:] if newString in words: print "Did you mean, "+newString exit(0)
if char not in charCounts: charCounts[char]=1 else: charCounts[char]+=1 for i in range(charCounts[char]): prevPos=0 for char in charCounts: if charCounts[char]>1: pos=word.index(char,prevPos) prevPos=pos newString=word[0:pos]+word[pos+1:] if newString in words: print "Did you mean, "+newString exit(0) else: word=origWord if i is charCounts[char]-1: print "Could not spellcheck."
reply permalink
Nick Krichevsky - 10 years, 7 months ago
Python solution
reply permalink
Max Burstein - 10 years, 7 months ago
Nice job!
reply permalink