def __init__(self, spelling_config=None): SpellingChecker.__init__(self, spelling_config) if spelling_config is None: corpus_filename = os.path.dirname(__file__) + os.sep + "corpus.txt" else: corpus_filename = spelling_config.corpus if logging.getLogger().isEnabledFor(logging.INFO): logging.info("Loading spelling corpus [%s]", corpus_filename) self.words = Counter(self._all_words(open(corpus_filename, encoding="utf-8").read())) self.sum_of_words = sum(self.words.values())
def setUp(self): client = TestClient() self._client_context = ClientContext(client, "testid") self._client_context.bot = Bot(BotConfiguration(), client) spelling_config = BotSpellingConfiguration() spelling_config._classname = "programytest.spelling.test_base.MockSpellingChecker" self._client_context.bot._spell_checker = SpellingChecker.initiate_spellchecker(spelling_config, None)
def __init__(self, spelling_config=None): SpellingChecker.__init__(self, spelling_config) self.words = [] self.sum_of_words = 0 if spelling_config is None: corpus_filename = os.path.dirname(__file__) + os.sep + "corpus.txt" else: corpus_filename = spelling_config.corpus if os.path.exists(corpus_filename) is True: YLogger.info(self, "Loading spelling corpus [%s]", corpus_filename) self.words = Counter(self._all_words(open(corpus_filename, encoding="utf-8").read())) self.sum_of_words = sum(self.words.values()) else: YLogger.error(self, "No spelling corpus found[%s]", corpus_filename)
def test_initiate_spellchecker_no_classname(self): spelling_config = BotSpellingConfiguration() spelling_config._classname = None storage_factory = None spell_checker = SpellingChecker.initiate_spellchecker( spelling_config, storage_factory) self.assertIsNone(spell_checker)
def test_initiate_spellchecker_invalid_classname(self): spelling_config = BotSpellingConfiguration() spelling_config._classname = "programytest.spelling.test_base.InvalidSpellingChecker" storage_factory = None spell_checker = SpellingChecker.initiate_spellchecker( spelling_config, storage_factory) self.assertIsNone(spell_checker)
def __init__(self, spelling_config=None): SpellingChecker.__init__(self, spelling_config) self.words = [] self.sum_of_words = 0 if spelling_config is None: corpus_filename = os.path.dirname(__file__) + os.sep + "corpus.txt" else: corpus_filename = spelling_config.corpus if os.path.exists(corpus_filename) is True: YLogger.info(self, "Loading spelling corpus [%s]", corpus_filename) self.words = Counter( self._all_words( open(corpus_filename, encoding="utf-8").read())) self.sum_of_words = sum(self.words.values()) else: YLogger.error(self, "No spelling corpus found[%s]", corpus_filename)
def test_initiate_spellchecker_no_storage(self): spelling_config = BotSpellingConfiguration() spelling_config._load = True spelling_config._classname = "programy.spelling.norvig.NorvigSpellingChecker" client = TestClient() storage_factory = client.storage_factory spell_checker = SpellingChecker.initiate_spellchecker(spelling_config, storage_factory) self.assertIsNotNone(spell_checker)
def test_initiate_spellchecker_load_is_false(self): spelling_config = BotSpellingConfiguration() spelling_config._load = False spelling_config._classname = "programytest.spelling.test_base.MockSpellingChecker" storage_factory = None spell_checker = SpellingChecker.initiate_spellchecker( spelling_config, storage_factory) self.assertIsNone(spell_checker)
def test_check_spelling_before_false(self): spelling_config = BotSpellingConfiguration() spelling_config._classname = "programytest.spelling.test_base.MockSpellingChecker" spelling_config._check_before = False storage_factory = None spell_checker = SpellingChecker.initiate_spellchecker( spelling_config, storage_factory) client = TestClient() client_context = client.create_client_context("user1") sentence = Sentence(client_context, "Hello word") spell_checker.check_spelling_before(client_context, sentence) self.assertEqual(sentence.text(client_context), "Hello word")
def test_check_spelling_and_retry_false(self): spelling_config = BotSpellingConfiguration() spelling_config._classname = "programytest.spelling.test_base.MockSpellingChecker" spelling_config._check_and_retry = False storage_factory = None spell_checker = SpellingChecker.initiate_spellchecker( spelling_config, storage_factory) client = TestClient() client_context = client.create_client_context("user1") tokenizer = client_context.brain.tokenizer client_context._brain = MockBrain() sentence = Sentence(tokenizer, "Hello word") response = spell_checker.check_spelling_and_retry( client_context, sentence) self.assertIsNone(response)
def setUp(self): client = GetAIMLTestClient() self._client_context = client.create_client_context("testid") self._client_context.brain.properties.load_from_text(""" default_get:unknown """) self._client_context.bot.brain.dynamics.add_dynamic_var( 'gettime', "programy.dynamic.variables.datetime.GetTime", None) self._client_context.bot.brain.dynamics.add_dynamic_var( 'spelling', "programy.dynamic.variables.system.spelling.Spelling", None) self._client_context.bot.brain.dynamics.add_dynamic_var( 'splitter', "programy.dynamic.variables.system.splitter.SentenceSplitter", None) spelling_config = BotSpellingConfiguration() spelling_config._classname = "programytest.spelling.test_base.MockSpellingChecker" self._client_context.bot._spell_checker = SpellingChecker.initiate_spellchecker( spelling_config, None) config = BotSentenceSplitterConfiguration() self._client_context.bot._sentence_splitter = SentenceSplitter.initiate_sentence_splitter( config)
def initiate_spellchecker(self): if self.configuration is not None: if self.configuration.spelling is not None: self._spell_checker = SpellingChecker.initiate_spellchecker( self.configuration.spelling, self.client.storage_factory)
def __init__(self, spelling_config=None): SpellingChecker.__init__(self, spelling_config) self._speller = Speller()
def __init__(self, spelling_config=None): SpellingChecker.__init__(self, spelling_config)
def test_ensure_not_implemented(self): checker = SpellingChecker() self.assertIsNotNone(checker) with self.assertRaises(Exception): checker.correct("Test This")
def __init__(self, spelling_config=None): SpellingChecker.__init__(self, spelling_config) self.words = [] self.sum_of_words = 0