Esempio n. 1
0
def spell_check_list(text, static=False, file_name='spell_check'):
    """
    Correct the list of the words
    :param static: if do statistic to record the text change
    :param text: the list of the misspelling words
    :param file_name: input the name of the statistic file
    :return: the list of corrected spelling words
    """
    # Check whether or not input the correct type of data
    input_check.input_check_list(text)
    cor_words = []
    # original words list
    origin_words = []
    # affected words list
    affected_words = []
    for word in text:
        # check if the word spells wrong
        cor_word = sc.correction(word)
        # add it into the list if the word is corrected
        if cor_word != word:
            origin_words.append(word)
            affected_words.append(cor_word)
        # filter the word which length is less than 1 such as the punctuation
        if len(word) > 1:
            cor_words.append(cor_word)
    # do statistic
    if static:
        statistic.do_statistic(origin_words, affected_words, file_name)

    return cor_words
def count_words(file):
    count_mispelled = 0
    count_correct_word = 0

    for line in file:
        words = line.lower().split()
        count_mispelled += 1
        mispelled_words_ls.append(words[1])
        edited_word = spelling_correction.correction(words[1])
        edited_words_ls.append(edited_word)
        correct_words_ls.append(words[0])
        if edited_word == words[0]:
            count_correct_word += 1

    return {'mispelled': count_mispelled, 'correct word': count_correct_word}
 def test_insert(self):
     self.assertEqual(spelling_correction.correction('speling'), 'spelling')
 def test_known(self):
     self.assertEqual(spelling_correction.correction('dummy'), 'dummy')
 def test_tranpose_delete(self):
     self.assertEqual(spelling_correction.correction('poetryy'), 'poetry')
 def test_transpose(self):
     self.assertEqual(spelling_correction.correction('baer'), 'bear')
 def test_delete(self):
     self.assertEqual(spelling_correction.correction('salmoon'), 'salmon')
 def test_replace_twice(self):
     self.assertEqual(spelling_correction.correction('inconvineent'),
                      'inconvenient')
 def test_replace_insert(self):
     self.assertEqual(spelling_correction.correction('pschologi'),
                      'psychology')
 def test_replace(self):
     self.assertEqual(spelling_correction.correction('prscticr'),
                      'practice')