# Path: shorttext/spell/basespellcorrector.py
# class SpellCorrector(ABC):
#     """ Base class for all spell corrector.
# 
#     This class is not implemented; this is an "abstract class."
# 
#     """
#     @abstractmethod
#     def train(self, text):
#         """ Train the spell corrector with the given corpus.
# 
#         :param text: training corpus
#         :type text: str
#         """
#         raise NotImplementedException()
# 
#     @abstractmethod
#     def correct(self, word):
#         """ Recommend a spell correction to given the word.
# 
#         :param word: word to be checked
#         :return: recommended correction
#         :type word: str
#         :rtype: str
#         """
#         return word
# 
# Path: shorttext/spell/editor.py
# def compute_set_edits1(word):
#     return edits1_comb(word)
# 
# def compute_set_edits2(word):
#     return (e2 for e1 in compute_set_edits1(word) for e2 in compute_set_edits1(e1))


import re
from collections import Counter
from . import SpellCorrector
from .editor import compute_set_edits1, compute_set_edits2
        return self.WORDS[word] / float(self.N)

    def correct(self, word):
        """ Recommend a spelling correction to the given word

        :param word: a word
        :return: recommended correction
        :type word: str
        :rtype: str
        """
        return max(self.candidates(word), key=self.P)

    def known(self, words):
        """ Filter away the words that are not found in the training corpus.

        :param words: list of words
        :return: list of words that can be found in the training corpus
        :type words: list
        :rtype: list
        """
        return set(w for w in words if w in self.WORDS)

    def candidates(self, word):
        """ List potential candidates for corrected spelling to the given words.

        :param word: a word
        :return: list of recommended corrections
        :type word: str
        :rtype: list
        """

# Path: shorttext/spell/basespellcorrector.py
# class SpellCorrector(ABC):
#     """ Base class for all spell corrector.
# 
#     This class is not implemented; this is an "abstract class."
# 
#     """
#     @abstractmethod
#     def train(self, text):
#         """ Train the spell corrector with the given corpus.
# 
#         :param text: training corpus
#         :type text: str
#         """
#         raise NotImplementedException()
# 
#     @abstractmethod
#     def correct(self, word):
#         """ Recommend a spell correction to given the word.
# 
#         :param word: word to be checked
#         :return: recommended correction
#         :type word: str
#         :rtype: str
#         """
#         return word
# 
# Path: shorttext/spell/editor.py
# def compute_set_edits1(word):
#     return edits1_comb(word)
# 
# def compute_set_edits2(word):
#     return (e2 for e1 in compute_set_edits1(word) for e2 in compute_set_edits1(e1))


# Path: shorttext/spell/norvig.py
import re
from collections import Counter
from . import SpellCorrector
from .editor import compute_set_edits1, compute_set_edits2

        return self.WORDS[word] / float(self.N)

    def correct(self, word):
        """ Recommend a spelling correction to the given word

        :param word: a word
        :return: recommended correction
        :type word: str
        :rtype: str
        """
        return max(self.candidates(word), key=self.P)

    def known(self, words):
        """ Filter away the words that are not found in the training corpus.

        :param words: list of words
        :return: list of words that can be found in the training corpus
        :type words: list
        :rtype: list
        """
        return set(w for w in words if w in self.WORDS)

    def candidates(self, word):
        """ List potential candidates for corrected spelling to the given words.

        :param word: a word
        :return: list of recommended corrections
        :type word: str
        :rtype: list
        """

        return (self.known([word]) or self.known(compute_set_edits1(word)) or self.known(compute_set_edits2(word)) or [word])