Closed Zylvian closed 5 years ago
The spellchecker takes a list of words you support (maybe lower them) and checks if a word (with a typo) is in that list.
from helper import SpellChecker
sp = SpellChecker(["Suppe", "Wurst", "Kartoffel"])
print(sp.correct("Suppe"))
print(sp.correct("Supe"))
print(sp.correct("Worst"))
print(sp.correct("Kartoffle"))
prints:
Suppe
Suppe
Wurst
Kartoffel
practical example:
from helper import SpellChecker
goodWords = ["Suppe", "Wurst", "Kartoffel"]
sp = SpellChecker(goodWords)
inputWord = "Worst"
if inputWord in goodWords:
print("good input")
else:
correctedInput = sp.correct(inputWord)
if inputWord != correctedInput:
print("good, it was probably a typo")
else:
print("bad input")
That's awesome! How well does it do with apostrophes and spaces? I.e "Charlie's Mom" or "King of the Sea".
@Zylvian it depends on what you feed the checker. It is very simple and works directly on characters without any grammar or stemming.
So if I was to compare two sentences like "I am the only one!" vs input "i am the only one", should I use re.search()
or this SpellChecker?
If this is an exact quote it should work if yout teach the spell-checker the sentence as one.
I lower-case and remove special charcters from words before I put them into the spellchecker.
[[I am the only one!]] > iamtheonlyone
Talking about the SpellChecker class: https://github.com/d-schmidt/hearthscan-bot/blob/master/helper.py
My bot - Reddit Wikia Bot is heavily based off of your work so I was wondering how you utilized this class, and why.
Thanks!