Exemplo n.º 1
0
    def test_parse_words_jp(self):
        node = PatternISetNode({}, "テスト1")
        self.assertIsNotNone(node)
        self.assertTrue(node._is_CJK)
        self.assertIsNotNone(node.words)
        self.assertEqual(1, len(node.words))
        self.assertEqual(1, len(node.words["テ"]))
        self.assertTrue("テスト1" in node.words["テ"])

        node = PatternISetNode({}, "テスト1,テスト2")
        self.assertIsNotNone(node)
        self.assertTrue(node._is_CJK)
        self.assertIsNotNone(node.words)
        self.assertEqual(1, len(node.words))
        self.assertEqual(2, len(node.words["テ"]))
        self.assertTrue("テスト1" in node.words["テ"])
        self.assertTrue("テスト2" in node.words["テ"])

        node = PatternISetNode({}, " テスト1, テスト2, テスト3 ")
        self.assertIsNotNone(node)
        self.assertTrue(node._is_CJK)
        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["テ"])
Exemplo n.º 2
0
    def test_equivalent(self):
        node1 = PatternISetNode({}, "test1, test2, test3")
        node2 = PatternISetNode({}, "test1, test2, test3")
        node3 = PatternISetNode({}, "test1, test2, test3", userid="testid")
        node4 = PatternISetNode({}, "test1, test2, test3, test4")
        node5 = PatternISetNode({}, "test1, test2, test4")

        self.assertTrue(node1.equivalent(node2))
        self.assertFalse(node1.equivalent(node3))
        self.assertFalse(node1.equivalent(node4))
        self.assertFalse(node1.equivalent(node5))
Exemplo n.º 3
0
    def test_equivalent_jp(self):
        node1 = PatternISetNode({}, "テスト1, テスト2, テスト3")
        node2 = PatternISetNode({}, "テスト1, テスト2, テスト3")
        node3 = PatternISetNode({}, "テスト1, テスト2, テスト3", userid="testid")
        node4 = PatternISetNode({}, "テスト1, テスト2, テスト3, テスト4")
        node5 = PatternISetNode({}, "テスト1, テスト2, テスト4")

        self.assertTrue(node1.equivalent(node2))
        self.assertFalse(node1.equivalent(node3))
        self.assertFalse(node1.equivalent(node4))
        self.assertFalse(node1.equivalent(node5))
Exemplo n.º 4
0
    def test_iset_node_exists(self):
        node = PatternNode()
        self.assertIsNotNone(node)

        new_node1 = PatternISetNode([], "test")

        self.assertIsNone(node._iset_node_exist(new_node1))
        node.add_child(new_node1)
        self.assertIsNotNone(node._iset_node_exist(new_node1))

        new_node2 = PatternISetNode([], "test", userid="testid2")

        self.assertIsNone(node._iset_node_exist(new_node2))
        node.add_child(new_node2)
        self.assertIsNotNone(node._iset_node_exist(new_node2))
Exemplo n.º 5
0
 def test_init_with_attribs(self):
     node = PatternISetNode({"words": "test1, test2, test3"}, "")
     self.assertIsNotNone(node)
     self.assertFalse(node._is_CJK)
     self.assertTrue("TEST1" in node.words)
     self.assertTrue("TEST2" in node.words)
     self.assertTrue("TEST3" in node.words)
Exemplo n.º 6
0
    def test_dump_no_caller(self):
        global str1

        node = PatternNode()
        self.assertIsNotNone(node)

        node.add_child(PatternWordNode("test"))
        node.add_child(PatternPriorityWordNode("pTest"))
        node.add_child(PatternZeroOrMoreWildCardNode("^"))
        node.add_child(PatternZeroOrMoreWildCardNode("#"))
        node.add_child(PatternOneOrMoreWildCardNode("*"))
        node.add_child(PatternOneOrMoreWildCardNode("_"))
        node.add_child(PatternTemplateNode(TemplateNode()))
        node.add_child(PatternSetNode({"name": "test"}, "testtext"))
        node.add_child(PatternISetNode({"name": "test"}, "testtext"))
        node.add_child(PatternBotNode({"name": "test"}, "testtext"))
        node.add_child(PatternRegexNode({"name": ".*"}, "testtext"))

        node.dump("", output_func1)

        self.assertEquals(
            "NODE [*] [P(1)^(1)#(1)C(5)_(1)*(1)To(0)Th(0)Te(1)]	"
            "PWORD [*] [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] word=[pTest]	"
            "ZEROORMORE [*] [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] wildcard=[^]	"
            "ZEROORMORE [*] [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] wildcard=[#]	"
            "ONEORMORE [*] [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] wildcard=[_]	"
            "ONEORMORE [*] [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] wildcard=[*]	"
            "PTEMPLATE [*] [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(1)]	"
            "WORD [*] [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] word=[test]	"
            "SET [*] [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] name=[TESTTEXT]	"
            "ISET [*] [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] words=[TESTTEXT]	"
            "BOT [*] [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] property=[test]	"
            "REGEX [*] [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] pattern=[testtext]",
            str1)
Exemplo n.º 7
0
 def test_init_with_attribs_jp(self):
     node = PatternISetNode({"words": "テスト1, テスト2, テスト3"}, "")
     self.assertIsNotNone(node)
     self.assertTrue(node._is_CJK)
     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["テ"])
Exemplo n.º 8
0
    def test_remove_iset_node(self):
        node = PatternNode()
        self.assertIsNotNone(node)

        child_node = PatternISetNode({"name": "test"}, "testtext")
        node.add_child(child_node)
        self.assertTrue(node._iset_node_exist(child_node))

        node._remove_node(child_node)
        self.assertFalse(node._iset_node_exist(child_node))
Exemplo n.º 9
0
    def test_remove_iset_node(self):
        node = PatternNode()
        self.assertIsNotNone(node)

        child_node = PatternISetNode([], "test")
        node.add_child(child_node)
        self.assertEqual(1, len(node.children))

        node._remove_node(child_node)
        self.assertEqual(0, len(node.children))
Exemplo n.º 10
0
    def test_parse_words(self):
        node = PatternISetNode([], "test1")
        self.assertIsNotNone(node)
        self.assertIsNotNone(node.words)
        self.assertEquals(1, len(node.words))
        self.assertEquals("TEST1", node.words[0])

        node = PatternISetNode([], "test1,test2")
        self.assertIsNotNone(node)
        self.assertIsNotNone(node.words)
        self.assertEquals(2, len(node.words))
        self.assertEquals("TEST1", node.words[0])
        self.assertEquals("TEST2", node.words[1])

        node = PatternISetNode([], " test1, test2 , test3 ")
        self.assertIsNotNone(node)
        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])
Exemplo n.º 11
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))
Exemplo n.º 12
0
    def test_equals(self):
        node1 = PatternISetNode([], "test1, test2, test3")
        node2 = PatternISetNode([], "test1, test2, test3", userid="testid")
        node3 = PatternISetNode([], "test1, test2, test3", userid="testid2")

        match1 = node1.equals(self._client_context,
                              Sentence(self._client_context, 'test1'), 0)
        self.assertIsNotNone(match1)
        self.assertTrue(match1.matched)

        match2 = node2.equals(self._client_context,
                              Sentence(self._client_context, 'test1'), 0)
        self.assertIsNotNone(match2)
        self.assertTrue(match2.matched)

        match3 = node3.equals(self._client_context,
                              Sentence(self._client_context, 'test1'), 0)
        self.assertIsNotNone(match3)
        self.assertFalse(match3.matched)
Exemplo n.º 13
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))
Exemplo n.º 14
0
    def test_parse_words(self):
        node = PatternISetNode({}, "test1")
        self.assertIsNotNone(node)
        self.assertFalse(node._is_CJK)
        self.assertIsNotNone(node.words)
        self.assertEqual(1, len(node.words))
        self.assertTrue("TEST1" in node.words)

        node = PatternISetNode({}, "test1,test2")
        self.assertIsNotNone(node)
        self.assertFalse(node._is_CJK)
        self.assertIsNotNone(node.words)
        self.assertEqual(2, len(node.words))
        self.assertTrue("TEST1" in node.words)
        self.assertTrue("TEST2" in node.words)

        node = PatternISetNode({}, " test1, test2 , test3 ")
        self.assertIsNotNone(node)
        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)
Exemplo n.º 15
0
    def test_to_string(self):
        node1 = PatternISetNode({}, "test1, test2, test3")
        self.assertEqual(node1.to_string(verbose=False),
                         "ISET words=[TEST1,TEST2,TEST3]")
        self.assertEqual(
            node1.to_string(verbose=True),
            "ISET [*] [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] words=[TEST1,TEST2,TEST3]"
        )

        node2 = PatternISetNode({}, "test1, test2, test3", userid="testid")
        self.assertEqual(node2.to_string(verbose=False),
                         "ISET words=[TEST1,TEST2,TEST3]")
        self.assertEqual(
            node2.to_string(verbose=True),
            "ISET [testid] [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] words=[TEST1,TEST2,TEST3]"
        )
Exemplo n.º 16
0
    def test_to_string_jp(self):
        node1 = PatternISetNode({}, "テスト1, テスト2, テスト3")
        self.assertEqual(node1.to_string(verbose=False),
                         "ISET words=[テスト1,テスト2,テスト3]")
        self.assertEqual(
            node1.to_string(verbose=True),
            "ISET [*] [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] words=[テスト1,テスト2,テスト3]"
        )

        node2 = PatternISetNode({}, "テスト1, テスト2, テスト3", userid="testid")
        self.assertEqual(node2.to_string(verbose=False),
                         "ISET words=[テスト1,テスト2,テスト3]")
        self.assertEqual(
            node2.to_string(verbose=True),
            "ISET [testid] [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] words=[テスト1,テスト2,テスト3]"
        )
Exemplo n.º 17
0
    def test_equals_jp(self):
        node1 = PatternISetNode({}, "テスト1, テスト2, テスト3")
        node2 = PatternISetNode({}, "テスト1, テスト2, テスト3", userid="testid")
        node3 = PatternISetNode({}, "テスト1, テスト2, テスト3", userid="testid2")

        match1 = node1.equals(
            self._client_context,
            Sentence(self._client_context.brain.tokenizer, 'テスト1'), 0)
        self.assertIsNotNone(match1)
        self.assertTrue(match1.matched)

        match2 = node2.equals(
            self._client_context,
            Sentence(self._client_context.brain.tokenizer, 'テスト1'), 0)
        self.assertIsNotNone(match2)
        self.assertTrue(match2.matched)

        match3 = node3.equals(
            self._client_context,
            Sentence(self._client_context.brain.tokenizer, 'テスト1'), 0)
        self.assertIsNotNone(match3)
        self.assertFalse(match3.matched)
Exemplo n.º 18
0
    def test_dump_with_caller(self):
        node = PatternNode()
        self.assertIsNotNone(node)

        node.add_child(PatternWordNode("test"))
        node.add_child(PatternPriorityWordNode("pTest"))
        node.add_child(PatternZeroOrMoreWildCardNode("^"))
        node.add_child(PatternZeroOrMoreWildCardNode("#"))
        node.add_child(PatternOneOrMoreWildCardNode("*"))
        node.add_child(PatternOneOrMoreWildCardNode("_"))
        node.add_child(PatternTemplateNode(TemplateNode()))
        node.add_child(PatternSetNode({"name": "test"}, "testtext"))
        node.add_child(PatternISetNode({"name": "test"}, "testtext"))
        node.add_child(PatternBotNode({"name": "test"}, "testtext"))
        node.add_child(PatternRegexNode({"name": ".*"}, "testtext"))

        node.dump("", YLogger.debug)
Exemplo n.º 19
0
 def node_from_element(element):
     if element.tag == 'set':
         if 'name' in element.attrib:
             return PatternSetNode(element.attrib['name'])
         else:
             return PatternSetNode(TextUtils.strip_whitespace(element.text))
     elif element.tag == 'bot':
         if 'name' in element.attrib:
             return PatternBotNode(element.attrib['name'])
         else:
             return PatternBotNode(TextUtils.strip_whitespace(element.text))
     elif element.tag == 'iset':
         return PatternISetNode(TextUtils.strip_whitespace(element.text))
     else:
         raise ParserException("Invalid parser graph node <%s>" %
                               element.tag,
                               xml_element=element)
Exemplo n.º 20
0
 def test_init_with_text(self):
     node = PatternISetNode({}, "test1, test2, test3")
     self.assertIsNotNone(node)
     self.assertEquals("TEST1", node.words[0])
     self.assertEquals("TEST2", node.words[1])
     self.assertEquals("TEST3", node.words[2])
Exemplo n.º 21
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))
Exemplo n.º 22
0
 def test_init_with_nothing(self):
     with self.assertRaises(ParserException) as raised:
         node = PatternISetNode({}, "")
     self.assertEqual(
         str(raised.exception),
         "Invalid iset node, no words specified as attribute or text")
Exemplo n.º 23
0
 def test_init_with_attribs(self):
     node = PatternISetNode({"words": "test1, test2, test3"}, "")
     self.assertIsNotNone(node)
     self.assertEquals("TEST1", node.words[0])
     self.assertEquals("TEST2", node.words[1])
     self.assertEquals("TEST3", node.words[2])
Exemplo n.º 24
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)
Exemplo n.º 25
0
 def test_init_with_invalid_attribs(self):
     with self.assertRaises(ParserException) as raised:
         PatternISetNode({"unknwon": "test1"}, "")
     self.assertEqual(str(raised.exception),
                      "No words specified as attribute or text")
Exemplo n.º 26
0
    def test_not_equivalent(self):
        node1 = PatternISetNode([], "test1, test2, test3")
        node2 = PatternISetNode([], "test1, test2, test4")

        self.assertFalse(node1.equivalent(node2))
Exemplo n.º 27
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)
Exemplo n.º 28
0
    def test_node_exists(self):

        node = PatternNode()
        self.assertIsNotNone(node)

        self.assert_child_node_exists(node, PatternWordNode("word"),
                                      PatternWordNode("word"))
        self.assert_child_node_exists(node,
                                      PatternPriorityWordNode("priority"),
                                      PatternPriorityWordNode("priority"))

        self.assert_child_node_exists(node, PatternOneOrMoreWildCardNode('_'),
                                      PatternOneOrMoreWildCardNode('_'))
        self.assert_child_node_exists(node, PatternOneOrMoreWildCardNode('*'),
                                      PatternOneOrMoreWildCardNode('*'))

        self.assert_child_node_exists(node, PatternZeroOrMoreWildCardNode('#'),
                                      PatternZeroOrMoreWildCardNode('#'))
        self.assert_child_node_exists(node, PatternZeroOrMoreWildCardNode('^'),
                                      PatternZeroOrMoreWildCardNode('^'))

        self.assert_child_node_exists(node, PatternSetNode({}, "setname"),
                                      PatternSetNode([], "setname"))
        self.assert_child_node_exists(node, PatternBotNode({}, "botname"),
                                      PatternBotNode([], "botname"))
        self.assert_child_node_exists(node, PatternISetNode({}, "word1 word2"),
                                      PatternISetNode([], "word1 word2"))

        self.assert_child_node_exists(
            node, PatternRegexNode({"pattern": "^LEGION$"}, None),
            PatternRegexNode({"pattern": "^LEGION$"}, None))
        self.assert_child_node_exists(
            node, PatternRegexNode({"template": "LEGION"}, None),
            PatternRegexNode({"template": "LEGION"}, None))

        topic1 = PatternTopicNode()
        topic2 = PatternTopicNode()
        self.assertIsNone(node._node_exists(topic1))
        node.add_topic(topic1)
        new_node = node._node_exists(topic1)
        self.assertIsNotNone(new_node)
        self.assertEquals(new_node, topic1)
        new_node = node.add_topic(topic2)
        self.assertIsNotNone(new_node)
        self.assertEquals(new_node, topic1)

        that1 = PatternThatNode()
        that2 = PatternThatNode()
        self.assertIsNone(node._node_exists(that1))
        node.add_that(that1)
        new_node = node._node_exists(that1)
        self.assertIsNotNone(new_node)
        self.assertEquals(new_node, that1)
        new_node = node.add_that(that2)
        self.assertIsNotNone(new_node)
        self.assertEquals(new_node, that1)

        template1 = PatternTemplateNode(None)
        template2 = PatternTemplateNode(None)
        self.assertIsNone(node._node_exists(template1))
        node.add_template(template1)
        new_node = node._node_exists(template1)
        self.assertIsNotNone(new_node)
        self.assertEquals(new_node, template1)
        new_node = node.add_template(template2)
        self.assertIsNotNone(new_node)
        self.assertEquals(new_node, template1)

        node.dump("")

        self.assertEqual(
            node.to_xml(None, None), """<priority word="priority"></priority>
<zerormore wildcard="^">
</zerormore>
<zerormore wildcard="#">
</zerormore>
<oneormore wildcard="_">
</oneormore>
<oneormore wildcard="*">
</oneormore>
<topic></topic>
<that></that>
<template></template>
<word word="word"></word>
<set name="SETNAME">
</set><bot property="botname">
</bot><iset words="WORD1 WORD2"></iset>
<regex pattern="^LEGION$"></regex>
<regex template="LEGION"></regex>
""")
Exemplo n.º 29
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.assertTrue(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.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")))

        self.assertTrue(node.equals(None, "testid", "TEST1"))
        self.assertTrue(node.equals(None, "testid", "TEST2"))
        self.assertTrue(node.equals(None, "testid", "TEST3"))
        self.assertFalse(node.equals(None, "testid", "TEST4"))

        self.assertEqual(
            node.to_string(),
            "ISET [P(0)^(0)#(0)C(0)_(0)*(0)To(0)Th(0)Te(0)] name=[TEST1,TEST2,TEST3]"
        )