Пример #1
0
    def test_init_jp(self):
        node = PatternISetNode({}, "テスト1, テスト2, テスト3")
        self.assertIsNotNone(node)
        self.assertTrue(node._is_CJK)

        self.assertFalse(node.is_root())
        self.assertFalse(node.is_priority())
        self.assertFalse(node.is_wildcard())
        self.assertFalse(node.is_zero_or_more())
        self.assertFalse(node.is_one_or_more())
        self.assertFalse(node.is_set())
        self.assertFalse(node.is_bot())
        self.assertFalse(node.is_template())
        self.assertFalse(node.is_that())
        self.assertFalse(node.is_topic())
        self.assertFalse(node.is_wildcard())
        self.assertTrue(node.is_iset())
        self.assertFalse(node.is_nlu())

        self.assertIsNotNone(node.children)
        self.assertFalse(node.has_children())

        self.assertIsNotNone(node.words)
        self.assertEqual(1, len(node.words))
        self.assertEqual(3, len(node.words["テ"]))
        self.assertTrue("テスト1" in node.words["テ"])
        self.assertTrue("テスト2" in node.words["テ"])
        self.assertTrue("テスト3" in node.words["テ"])

        self.assertTrue(
            node.equivalent(PatternISetNode({}, "テスト1, テスト2, テスト3")))

        sentence = Sentence(self._client_context.brain.tokenizer,
                            "テスト1 テスト2 テスト3")

        result = node.equals(self._client_context, sentence, 0)
        self.assertTrue(result.matched)
        result = node.equals(self._client_context, sentence, 2)
        self.assertTrue(result.matched)
        result = node.equals(self._client_context, sentence, 4)
        self.assertTrue(result.matched)
        result = node.equals(self._client_context, sentence, 6)
        self.assertFalse(result.matched)
Пример #2
0
    def test_init(self):
        node = PatternISetNode({}, "test1, test2, test3")
        self.assertIsNotNone(node)
        self.assertFalse(node._is_CJK)

        self.assertFalse(node.is_root())
        self.assertFalse(node.is_priority())
        self.assertFalse(node.is_wildcard())
        self.assertFalse(node.is_zero_or_more())
        self.assertFalse(node.is_one_or_more())
        self.assertFalse(node.is_set())
        self.assertFalse(node.is_bot())
        self.assertFalse(node.is_template())
        self.assertFalse(node.is_that())
        self.assertFalse(node.is_topic())
        self.assertFalse(node.is_wildcard())
        self.assertTrue(node.is_iset())
        self.assertFalse(node.is_nlu())

        self.assertIsNotNone(node.children)
        self.assertFalse(node.has_children())

        self.assertIsNotNone(node.words)
        self.assertEqual(3, len(node.words))
        self.assertTrue("TEST1" in node.words)
        self.assertTrue("TEST2" in node.words)
        self.assertTrue("TEST3" in node.words)

        self.assertTrue(
            node.equivalent(PatternISetNode({}, "test1, test2, test3")))

        sentence = Sentence(self._client_context.brain.tokenizer,
                            "TEST1 TEST2 TEST3")

        result = node.equals(self._client_context, sentence, 0)
        self.assertTrue(result.matched)
        result = node.equals(self._client_context, sentence, 1)
        self.assertTrue(result.matched)
        result = node.equals(self._client_context, sentence, 2)
        self.assertTrue(result.matched)
        result = node.equals(self._client_context, sentence, 3)
        self.assertFalse(result.matched)