Download Models.py from KarthikaRajagopal/Spell_Checker_NLP: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/KarthikaRajagopal/Spell_Checker_NLP/resolve/main/Models.py
- Command line
-
hf download hf://KarthikaRajagopal/Spell_Checker_NLP/Models.py
-
curl -L -o Models.py https://huggingface.co/KarthikaRajagopal/Spell_Checker_NLP/resolve/main/Models.py
1.06 kB
| from textblob import TextBlob | |
| from gingerit.gingerit import GingerIt | |
| class SpellCheckerModule: | |
| def __init__(self): | |
| self.spell_check = TextBlob("") | |
| self.grammar_check = GingerIt() | |
| def correct_spell(self,text): | |
| # Helo,World, subscribe, to my channel | |
| words = text.split() | |
| corrected_words = [] | |
| for word in words: | |
| corrected_word = str(TextBlob(word).correct()) | |
| corrected_words.append(corrected_word) | |
| return " ".join(corrected_words) | |
| def correct_grammar(self,text): | |
| matches = self.grammar_check.parse(text) | |
| foundmistakes = [] | |
| for error in matches['corrections']: | |
| foundmistakes.append(error['text']) | |
| foundmistakes_count = len(foundmistakes) | |
| return foundmistakes,foundmistakes_count | |
| if __name__ == "__main__": | |
| obj = SpellCheckerModule() | |
| message = "Hello world. I like mashine learning. appple. bananana" | |
| print(obj.correct_spell(message)) | |
| print(obj.correct_grammar(message)) | |