Пример #1
0
 def test_sentence_creation_one_word(self):
     sentence = Sentence(self._bot.brain.tokenizer, "One")
     self.assertIsNotNone(sentence)
     self.assertEqual(1, sentence.num_words())
     with self.assertRaises(Exception):
         sentence.sentence.word(1)
     self.assertEqual("One", sentence.text())
Пример #2
0
 def test_sentence_creation_one_word(self):
     sentence = Sentence(self._bot.brain.tokenizer, "One")
     self.assertIsNotNone(sentence)
     self.assertEqual(1, sentence.num_words())
     with self.assertRaises(Exception):
         sentence.sentence.word(1)
     self.assertEqual("One", sentence.text())
Пример #3
0
 def test_question_create_from_sentence(self):
     sentence = Sentence(self._bot.brain.tokenizer, "One Two Three")
     question = Question.create_from_sentence(sentence)
     self.assertIsNotNone(question)
     self.assertEqual(1, len(question.sentences))
     self.assertEqual(sentence.text(), question.sentence(0).text())
     with self.assertRaises(Exception):
         question.sentence(1)
Пример #4
0
 def test_question_create_from_sentence(self):
     sentence = Sentence(self._bot.brain.tokenizer, "One Two Three")
     question = Question.create_from_sentence(sentence)
     self.assertIsNotNone(question)
     self.assertEqual(1, len(question.sentences))
     self.assertEqual(sentence.text(), question.sentence(0).text())
     with self.assertRaises(Exception):
         question.sentence(1)
Пример #5
0
 def test_words_from_current_pos(self):
     sentence = Sentence(self._bot.brain.tokenizer, "One Two Three")
     self.assertIsNotNone(sentence)
     self.assertEqual("One Two Three", sentence.words_from_current_pos(0))
     self.assertEqual("Two Three", sentence.words_from_current_pos(1))
     self.assertEqual("Three", sentence.words_from_current_pos(2))
     with self.assertRaises(Exception):
         self.assertEqual("Three", sentence.words_from_current_pos(3))
     self.assertEqual("One Two Three", sentence.text())
Пример #6
0
 def test_split_into_words(self):
     sentence = Sentence(self._bot.brain.tokenizer, "HELLO")
     self.assertIsNotNone(sentence)
     self.assertEqual(1, sentence.num_words())
     self.assertEqual("HELLO", sentence.word(0))
     self.assertEqual("HELLO", sentence.words_from_current_pos(0))
     with self.assertRaises(Exception):
         sentence.sentence.word(1)
     self.assertEqual("HELLO", sentence.text())
Пример #7
0
 def test_words_from_current_pos(self):
     sentence = Sentence(self._bot.brain.tokenizer, "One Two Three")
     self.assertIsNotNone(sentence)
     self.assertEqual("One Two Three", sentence.words_from_current_pos(0))
     self.assertEqual("Two Three", sentence.words_from_current_pos(1))
     self.assertEqual("Three", sentence.words_from_current_pos(2))
     with self.assertRaises(Exception):
         self.assertEqual("Three", sentence.words_from_current_pos(3))
     self.assertEqual("One Two Three", sentence.text())
Пример #8
0
 def test_split_into_words(self):
     sentence = Sentence(self._bot.brain.tokenizer, "HELLO")
     self.assertIsNotNone(sentence)
     self.assertEqual(1, sentence.num_words())
     self.assertEqual("HELLO", sentence.word(0))
     self.assertEqual("HELLO", sentence.words_from_current_pos(0))
     with self.assertRaises(Exception):
         sentence.sentence.word(1)
     self.assertEqual("HELLO", sentence.text())
Пример #9
0
 def test_sentence_creation_two_words_diff_split_char(self):
     tokenizer = Tokenizer(",")
     sentence = Sentence(tokenizer, "One,Two",)
     self.assertIsNotNone(sentence)
     self.assertEqual(2, sentence.num_words())
     self.assertEqual("One", sentence.word(0))
     self.assertEqual("Two", sentence.word(1))
     with self.assertRaises(Exception):
         sentence.sentence.word(2)
     self.assertEqual("One,Two", sentence.text())
Пример #10
0
 def test_sentence_creation_two_words_diff_split_char(self):
     tokenizer = Tokenizer(",")
     sentence = Sentence(tokenizer, "One,Two",)
     self.assertIsNotNone(sentence)
     self.assertEqual(2, sentence.num_words())
     self.assertEqual("One", sentence.word(0))
     self.assertEqual("Two", sentence.word(1))
     with self.assertRaises(Exception):
         sentence.sentence.word(2)
     self.assertEqual("One,Two", sentence.text())
Пример #11
0
    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.brain.tokenizer, "Hello word")

        spell_checker.check_spelling_before(client_context, sentence)

        self.assertEqual(sentence.text(), "Hello word")
Пример #12
0
    def test_bot_init_with_spellchecker(self):
        
        bot_config = BotConfiguration()
        bot_config.spelling._classname = "programy.spelling.norvig.NorvigSpellingChecker"
        bot_config.spelling._corpus = os.path.dirname(__file__) + os.sep + "test_corpus.txt"
        bot_config.spelling._check_before = True
        bot_config.spelling._check_and_retry = True
        bot = Bot(bot_config)
        self.assertIsNotNone(bot)

        test_sentence = Sentence(bot.brain.tokenizer, "locetion")
        bot.check_spelling_before(test_sentence)
        self.assertIsNotNone(test_sentence)
        self.assertEqual("LOCATION", test_sentence.text())

        test_sentence = Sentence(bot.brain.tokenizer, "locetion")
        response = bot.check_spelling_and_retry(self._client_context, test_sentence)
        self.assertIsNone(response)
Пример #13
0
    def test_bot_init_with_spellchecker(self):
        
        bot_config = BotConfiguration()
        bot_config.spelling._classname = "programy.spelling.norvig.NorvigSpellingChecker"
        bot_config.spelling._corpus = os.path.dirname(__file__) + os.sep + "test_corpus.txt"
        bot_config.spelling._check_before = True
        bot_config.spelling._check_and_retry = True
        bot = Bot(bot_config)
        self.assertIsNotNone(bot)

        test_sentence = Sentence(bot.brain.tokenizer, "locetion")
        bot.check_spelling_before(test_sentence)
        self.assertIsNotNone(test_sentence)
        self.assertEqual("LOCATION", test_sentence.text())

        test_sentence = Sentence(bot.brain.tokenizer, "locetion")
        response = bot.check_spelling_and_retry(self._client_context, test_sentence)
        self.assertIsNone(response)