spell correction
516076
def __correction(self,text):
        
        new_text = []
        for i in text.split():
            if len(i)>3:
                low = i.lower()
                new_text.append(i if WORDS[i] else correction(i))
            else:new_text.append(i)
        return " ".join(new_text)
1022594
def dump_misspelling_list(self):
    """"""
    results = []
    for bad_word in sorted(self._misspelling_dict.keys()):
      for correction in self._misspelling_dict[bad_word]:
        results.append([bad_word, correction])
    return results
580735
def create(spellchecker_cache_path):
    """"""
    user_dictionary = os.path.join(os.getcwd(), "DICTIONARY")
    user_words = read_dictionary_file(user_dictionary)

    valid_words = Dictionary(valid_words_set(user_dictionary, user_words),
                             "valid_words",
                             [user_dictionary],
                             spellchecker_cache_path)

    return (user_words, valid_words)
629216
def CorrectWrongEmails(self, askInput=True):
        ''''''
        for email in self.wrong_emails:
            corrected_email = self.CorrectEmail(email)
            self.emails[self.emails.index(email)] = corrected_email

        self.wrong_emails = []
29609
def spellchecker
      language, words, method = params[:params][0], params[:params][1], params[:method] unless params[:params].blank?
      return render(:nothing => true) if language.blank? || words.blank? || method.blank?
      headers["Content-Type"] = "text/plain"
      headers["charset"] = "utf-8"
      suggestions = check_spelling(words, method, language)
      results = {"id" => nil, "result" => suggestions, "error" => nil}
      render :json => results
    end
798174
def _edit1(self, w):
        
        # Of all spelling errors, 80% is covered by edit distance 1.
        # Edit distance 1 = one character deleted, swapped, replaced or inserted.
        split = [(w[:i], w[i:]) for i in range(len(w) + 1)]
        delete, transpose, replace, insert = (
            [a + b[1:] for a, b in split if b],
            [a + b[1] + b[0] + b[2:] for a, b in split if len(b) > 1],
            [a + c + b[1:] for a, b in split for c in Spelling.ALPHA if b],
            [a + c + b[0:] for a, b in split for c in Spelling.ALPHA]
        )
        return set(delete + transpose + replace + insert)
1041620
def _check_spelling(self, text, lang="en_US"):
        

        chkr = SpellChecker(lang)

        chkr.set_text(text)

        word_starts_ends = []

        for err in chkr:
            start = err.wordpos
            stop = err.wordpos + len(err.word) + 1
            word_starts_ends.append((start, stop))

        return word_starts_ends
1353078
private function correctInputs()
    {
        if (($diff = array_diff_key($this->rules, $this->inputs))) {
            foreach ($diff as $key => $value) {
                $this->inputs[ $key ] = '';
            }
        }
    }
1217934
def correct_word(word_string):
    '''
    
    '''
    if word_string is None:
        return ""
    elif isinstance(word_string, str):
        return max(find_candidates(word_string), key=find_word_prob)
    else:
        raise InputError("string or none type variable not passed as argument to correct_word")
206876
def _construct_user_dictionary(global_options, tool_options):
    """"""
    del global_options

    spellchecker_cache_path = tool_options.get("spellcheck_cache", None)
    valid_words_dictionary_helper.create(spellchecker_cache_path)
515015
def _spelling_pipeline(self, sources, options, personal_dict):
        """"""

        for source in self._pipeline_step(sources, options, personal_dict):
            # Don't waste time on empty strings
            if source._has_error():
                yield Results([], source.context, source.category, source.error)
            elif not source.text or source.text.isspace():
                continue
            else:
                encoding = source.encoding
                if source._is_bytes():
                    text = source.text
                else:
                    # UTF-16 and UTF-32 don't work well with Aspell and Hunspell,
                    # so encode with the compatible UTF-8 instead.
                    if encoding.startswith(('utf-16', 'utf-32')):
                        encoding = 'utf-8'
                    text = source.text.encode(encoding)
                self.log('', 3)
                self.log(text, 3)
                cmd = self.setup_command(encoding, options, personal_dict)
                self.log("Command: " + str(cmd), 4)

                try:
                    wordlist = util.call_spellchecker(cmd, input_text=text, encoding=encoding)
                    yield Results(
                        [w for w in sorted(set(wordlist.replace('\r', '').split('\n'))) if w],
                        source.context,
                        source.category
                    )
                except Exception as e:  # pragma: no cover
                    err = self.get_error(e)
                    yield Results([], source.context, source.category, err)
1190290
def spell_check(T, w):
    
    assert T is not None
    dist = 0
    while True:   # Try increasing distances
        u = search(T, dist, w)
        if u is not None:
            return u
        dist += 1
438415
def spell(word: str, engine: str = "pn") -> List[str]:
    

    return DEFAULT_SPELL_CHECKER.spell(word)
901195
def _correct(token, term_freq):
    
    if token.lower() in term_freq:
        return token
    e1 = [t for t in _ed1(token) if t in term_freq]
    if len(e1) > 0:
        e1.sort(key=term_freq.get)
        return e1[0]
    e2 = [t for t in _ed2(token) if t in term_freq]
    if len(e2) > 0:
        e2.sort(key=term_freq.get)
        return e2[0]
    return token
943000
def fixchars(self):
        """"""
        for key in Config.CHARFIXES:
            self.project.set_search_string(key)
            self.project.set_search_replacement(Config.CHARFIXES[key])
            self.project.replace_all()
54261
def check_spelling(spell_check_text, command, lang)
      xml_response_values = Array.new
      spell_check_text = spell_check_text.join(' ') if command == 'checkWords'
      logger.debug("Spellchecking via:  echo \"#{spell_check_text}\" | #{ASPELL_PATH} -a -l #{lang}")
      spell_check_response = `echo "#{spell_check_text}" | #{ASPELL_PATH} -a -l #{lang}`
      return xml_response_values if spell_check_response.blank?
      spelling_errors = spell_check_response.split("\n").slice(1..-1)
      for error in spelling_errors
        error.strip!
        if (match_data = error.match(ASPELL_WORD_DATA_REGEX))
          if (command == 'checkWords')
            arr = match_data[0].split(' ')
            xml_response_values << arr[1]
          elsif (command == 'getSuggestions')
            xml_response_values << error.split(',')[1..-1].collect(&:strip!)
            xml_response_values = xml_response_values.first
          end
        end
      end
      return xml_response_values
    end
450896
def _edit2(self, w):
        
        # Of all spelling errors, 99% is covered by edit distance 2.
        # Only keep candidates that are actually known words (20% speedup).
        return set(e2 for e1 in self._edit1(w) for e2 in self._edit1(e1) if e2 in self)