Example #1
0
    def test_to_xml_jp(self):
        node1 = PatternISetNode({}, "テスト1, テスト2, テスト3")
        self.assertEqual('<iset words="テスト1, テスト2, テスト3"></iset>\n',
                         node1.to_xml(self._client_context))

        node2 = PatternISetNode({}, "テスト1, テスト2, テスト3", userid="testid")
        self.assertEqual(
            '<iset words="テスト1, テスト2, テスト3"></iset>\n',
            node2.to_xml(self._client_context, include_user=False))
        self.assertEqual(
            '<iset userid="testid" words="テスト1, テスト2, テスト3"></iset>\n',
            node2.to_xml(self._client_context, include_user=True))
Example #2
0
    def test_to_xml(self):
        node1 = PatternISetNode({}, "test1, test2, test3")
        self.assertEqual('<iset words="TEST1, TEST2, TEST3"></iset>\n',
                         node1.to_xml(self._client_context))

        node2 = PatternISetNode({}, "test1, test2, test3", userid="testid")
        self.assertEqual(
            '<iset words="TEST1, TEST2, TEST3"></iset>\n',
            node2.to_xml(self._client_context, include_user=False))
        self.assertEqual(
            '<iset userid="testid" words="TEST1, TEST2, TEST3"></iset>\n',
            node2.to_xml(self._client_context, include_user=True))
Example #3
0
    def test_init(self):
        node = PatternISetNode([], "test1, test2, test3")
        self.assertIsNotNone(node)

        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.assertIsNotNone(node.children)
        self.assertFalse(node.has_children())

        self.assertIsNotNone(node.words)
        self.assertEquals(3, len(node.words))
        self.assertEquals("TEST1", node.words[0])
        self.assertEquals("TEST2", node.words[1])
        self.assertEquals("TEST3", node.words[2])

        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)

        self.assertEqual(
            node.to_string(),
            "ISET [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] words=[TEST1,TEST2,TEST3]"
        )
        self.assertEqual('<iset words="TEST1. TEST2. TEST3"></iset>\n',
                         node.to_xml(self._client_context))