File size: 919 Bytes
42e3a78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import spellchecker


def correct_typos(sentence):
    # Initialize the spell checker object
    spell = spellchecker.SpellChecker(language="en")
    # Adds Bibek to its frequency dictionary to make it a known word
    spell.word_frequency.load_words(
        [
            "Bibek",
            "Bibek's",
            "skillsets",
            "skillset",
            "CV",
            "RIRO",
            "Bisonai",
            "IC",
            "BMC",
            "KAIST",
        ]
    )
    sentence_split = sentence.split()
    # Find the typos in the input sentence
    typos = spell.unknown(sentence_split)
    # Correct the typos
    corrected_sentence = [
        spell.correction(word)
        if spell.correction(word)
        else word
        if word in typos
        else word
        for word in sentence_split
    ]
    # Return the corrected sentence as a string
    return " ".join(corrected_sentence)