Beispiel #1
0
 def test_split_unicode(self):
     self.assertEquals([], ChineseLanguage.split_unicode(""))
     self.assertEquals(['X'], ChineseLanguage.split_unicode("X"))
     self.assertEquals(['你'], ChineseLanguage.split_unicode("你"))
     self.assertEquals(['你', '好'], ChineseLanguage.split_unicode("你好"))
     self.assertEquals(['X', '你', '好'], ChineseLanguage.split_unicode("X你好"))
     self.assertEquals(['X', '你', '好', 'Y'], ChineseLanguage.split_unicode("X你好Y"))
Beispiel #2
0
 def test_split_unicode(self):
     self.assertEqual([], ChineseLanguage.split_unicode(""))
     self.assertEqual(['X'], ChineseLanguage.split_unicode("X"))
     self.assertEqual(['你'], ChineseLanguage.split_unicode("你"))
     self.assertEqual(['你', '好'], ChineseLanguage.split_unicode("你好"))
     self.assertEqual(['X', '你', '好'], ChineseLanguage.split_unicode("X你好"))
     self.assertEqual(['X', '你', '好', 'Y'],
                      ChineseLanguage.split_unicode("X你好Y"))
Beispiel #3
0
    def _parse_text(self, pattern_text, current_node):

        stripped = pattern_text.strip()
        if self._aiml_parser is not None and \
                        self._aiml_parser.brain is not None and \
                        self._aiml_parser.brain.configuration.language.chinese is True:
            words = ChineseLanguage.split_unicode(stripped)
        else:
            words = stripped.split(" ")

        for word in words:
            if word != '':  # Blank nodes add no value, ignore them
                word = TextUtils.strip_whitespace(word)

                new_node = self.node_from_text(word)

                current_node = current_node.add_child(new_node)

        return current_node
Beispiel #4
0
    def parse_text(self, graph, text):
        if text is not None:
            string = text.strip()
            if string:

                if graph._aiml_parser is not None and \
                                graph._aiml_parser.brain is not None and \
                                graph._aiml_parser.brain.configuration.language.chinese is True:
                    from programy.utils.language.chinese import ChineseLanguage
                    words = ChineseLanguage.split_unicode(string)
                else:
                    words = string.split(" ")
                #words = string.split(" ")

                for word in words:
                    if word is not None and word:
                        word_class = graph.get_node_class_by_name('word')
                        word_node = word_class(word.strip())
                        self.children.append(word_node)
                return True
        return False