d-schmidt / hearthscan-bot

🐙🐘🐦🐉🔥🦅🐍🐺 This bot explained cards in reddit.com/r/hearthstone before Reddit killed 3rd party apps. Archived after 8 years on 1.7.2023
https://www.reddit.com/user/hearthscan-bot
MIT License
12 stars 8 forks source link

How/when do you use the "SpellChecker"? #10

Closed Zylvian closed 5 years ago

Zylvian commented 5 years ago

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!

d-schmidt commented 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")
Zylvian commented 4 years ago

That's awesome! How well does it do with apostrophes and spaces? I.e "Charlie's Mom" or "King of the Sea".

d-schmidt commented 4 years ago

@Zylvian it depends on what you feed the checker. It is very simple and works directly on characters without any grammar or stemming.

Zylvian commented 4 years ago

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?

d-schmidt commented 4 years ago

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