当前位置: 首页>>代码示例>>Python>>正文


Python TextUtils.tag_from_text方法代码示例

本文整理汇总了Python中programy.utils.text.text.TextUtils.tag_from_text方法的典型用法代码示例。如果您正苦于以下问题:Python TextUtils.tag_from_text方法的具体用法?Python TextUtils.tag_from_text怎么用?Python TextUtils.tag_from_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在programy.utils.text.text.TextUtils的用法示例。


在下文中一共展示了TextUtils.tag_from_text方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse_expression

# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import tag_from_text [as 别名]
    def parse_expression(self, graph, expression):
        if 'text' in expression.attrib:
            self._text = graph.get_word_node(expression.attrib['text'])

        if 'url' in expression.attrib:
            self._url = graph.get_word_node(expression.attrib['url'])

        if 'postback' in expression.attrib:
            self._postback = graph.get_word_node(expression.attrib['postback'])

        head_text = self.get_text_from_element(expression)
        self.parse_text(graph, head_text)

        for child in expression:
            tag_name = TextUtils.tag_from_text(child.tag)

            if tag_name == 'text':
                self._text = self.parse_children_as_word_node(graph, child)
            elif tag_name == 'url':
                self._url = self.parse_children_as_word_node(graph, child)
            elif tag_name == 'postback':
                self._postback = self.parse_children_as_word_node(graph, child)
            else:
                graph.parse_tag_expression(child, self)

            tail_text = self.get_tail_from_element(child)
            self.parse_text(graph, tail_text)
开发者ID:Freiza,项目名称:program-y,代码行数:29,代码来源:button.py

示例2: parse_expression

# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import tag_from_text [as 别名]
    def parse_expression(self, graph, expression):

        if 'subj' in expression.attrib:
            self._subj = graph.get_word_node(expression.attrib['subj'])

        if 'pred' in expression.attrib:
            self._pred = graph.get_word_node(expression.attrib['pred'])

        if 'obj' in expression.attrib:
            self._obj = graph.get_word_node(expression.attrib['obj'])

        head_text = self.get_text_from_element(expression)
        self.parse_text(graph, head_text)

        for child in expression:
            tag_name = TextUtils.tag_from_text(child.tag)

            if tag_name == 'subj':
                self._subj = self.parse_children_as_word_node(graph, child)
            elif tag_name == 'pred':
                self._pred = self.parse_children_as_word_node(graph, child)
            elif tag_name == 'obj':
                self._obj = self.parse_children_as_word_node(graph, child)
            else:
                graph.parse_tag_expression(child, self)

            tail_text = self.get_tail_from_element(child)
            self.parse_text(graph, tail_text)
开发者ID:Freiza,项目名称:program-y,代码行数:30,代码来源:triple.py

示例3: _parse_node_with_attribs

# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import tag_from_text [as 别名]
    def _parse_node_with_attribs(self, graph, expression):

        self._name = TextUtils.tag_from_text(expression.tag)

        for attrib_name in expression.attrib:
            attrib_value = expression.attrib[attrib_name]
            if "<" in attrib_value and ">" in attrib_value:
                start = attrib_value.find("<")
                end = attrib_value.rfind(">")

                front = attrib_value[:start]
                middle = attrib_value[start:end+1]
                back = attrib_value[end+1:]

                root = TemplateNode()
                root.append(TemplateWordNode(front))

                xml = ET.fromstring(middle)
                xml_node = TemplateNode()
                graph.parse_tag_expression(xml, xml_node)
                root.append(xml_node)

                root.append(TemplateWordNode(back))

                self.set_attrib(attrib_name, root)

            else:
                self.set_attrib(attrib_name, TemplateWordNode(attrib_value))

        self.parse_text(graph, self.get_text_from_element(expression))

        for child in expression:
            graph.parse_tag_expression(child, self)
            self.parse_text(graph, self.get_tail_from_element(child))
开发者ID:Freiza,项目名称:program-y,代码行数:36,代码来源:xml.py

示例4: _parse_node_with_attribs

# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import tag_from_text [as 别名]
    def _parse_node_with_attribs(self, graph, expression, attribs):

        attribs_found = []
        for attrib in attribs:
            attrib_name = attrib[0]
            if attrib_name in expression.attrib:
                self.set_attrib(attrib_name, expression.attrib[attrib_name])
                attribs_found.append(attrib_name)

        self.parse_text(graph, self.get_text_from_element(expression))

        for child in expression:
            tag_name = TextUtils.tag_from_text(child.tag)

            for attrib in attribs:
                attrib_name = attrib[0]
                if tag_name == attrib_name:
                    self.set_attrib(attrib[0], self.get_text_from_element(child))
                else:
                    graph.parse_tag_expression(child, self)

            self.parse_text(graph, self.get_tail_from_element(child))

        for attrib in attribs:
            attrib_name = attrib[0]
            if attrib_name not in attribs_found:
                if attrib[1] is not None:
                    YLogger.debug(self, "Setting default value for attrib [%s]", attrib_name)
                    self.set_attrib(attrib_name, attrib[1])
开发者ID:Freiza,项目名称:program-y,代码行数:31,代码来源:attrib.py

示例5: parse_type3_condition

# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import tag_from_text [as 别名]
    def parse_type3_condition(self, graph, expression):
        for child in expression:
            tag_name = TextUtils.tag_from_text(child.tag)

            if tag_name in ['name', 'var', 'bot']:
                pass

            elif tag_name == 'li':
                list_item = TemplateConditionListItemNode()

                name, var_type = self.get_condition_name(child)
                list_item._name = name
                list_item._var_type = var_type

                list_item._value = self.get_condition_value(graph, child)

                self.children.append(list_item)

                list_item.parse_text(graph, self.get_text_from_element(child))

                for sub_pattern in child:
                    if sub_pattern.tag in ['name', 'var', 'bot', 'value']:
                        pass

                    elif sub_pattern.tag == 'loop':
                        list_item.loop = True

                    else:
                        graph.parse_tag_expression(sub_pattern, list_item)

                    tail_text = self.get_tail_from_element(sub_pattern)
                    list_item.parse_text(graph, tail_text)

            else:
                raise ParserException("Invalid element <%s> in condition element" % (tag_name), xml_element=expression)
开发者ID:Freiza,项目名称:program-y,代码行数:37,代码来源:condition.py

示例6: parse_tag_expression

# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import tag_from_text [as 别名]
 def parse_tag_expression(self, expression, branch):
     tag_name = TextUtils.tag_from_text(expression.tag)
     if self._template_factory.exists(tag_name):
         if tag_name == "condition":
             node_instance = self._template_factory.new_node_class(tag_name)()
         else:
             node_instance = self._template_factory.new_node_class(tag_name)()
         node_instance.parse_expression(self, expression)
         branch.children.append(node_instance)
     else:
         self.parse_unknown_as_xml_node(expression, branch)
开发者ID:Freiza,项目名称:program-y,代码行数:13,代码来源:graph.py

示例7: parse_expression

# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import tag_from_text [as 别名]
    def parse_expression(self, graph, expression):

        if 'format' in expression.attrib:
            self.interval_format = graph.get_word_node(expression.attrib['format'])

        head_text = self.get_text_from_element(expression)
        self.parse_text(graph, head_text)

        for child in expression:
            tag_name = TextUtils.tag_from_text(child.tag)

            if tag_name == 'format':
                self.interval_format = graph.get_word_node(self.get_text_from_element(child))

            elif tag_name == 'style':
                node = graph.get_base_node()
                node.parse_text(graph, self.get_text_from_element(child))
                for sub_child in child:
                    graph.parse_tag_expression(sub_child, node)
                    node.parse_text(graph, self.get_text_from_element(child))
                self.style = node

            elif tag_name == 'from':
                node = graph.get_base_node()
                node.parse_text(graph, self.get_text_from_element(child))
                for sub_child in child:
                    graph.parse_tag_expression(sub_child, node)
                    node.parse_text(graph, self.get_text_from_element(child))
                self.interval_from = node

            elif tag_name == 'to':
                node = graph.get_base_node()
                node.parse_text(graph, self.get_text_from_element(child))
                for sub_child in child:
                    graph.parse_tag_expression(sub_child, node)
                    node.parse_text(graph, self.get_text_from_element(child))
                self.interval_to = node
            else:
                graph.parse_tag_expression(child, self)

            tail_text = self.get_tail_from_element(child)
            self.parse_text(graph, tail_text)

        if self.interval_format is None:
            YLogger.warning(self, "Interval node, format missing, defaulting to 'c%%'!")
            self.interval_format = "%c"
        if self.style is None:
            YLogger.warning(self, "style node, format missing, defaulting to 'days'!")
            self.style = "days"
        if self.interval_from is None:
            YLogger.warning(self, "interval_from node, format missing !")
        if self.interval_to is None:
            YLogger.warning(self, "interval_to node, format missing !")
开发者ID:Freiza,项目名称:program-y,代码行数:55,代码来源:interval.py

示例8: node_from_element

# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import tag_from_text [as 别名]
    def node_from_element(self, element, userid="*"):

        node_name = TextUtils.tag_from_text(element.tag)
        if self._pattern_factory.exists(node_name) is False:
            raise ParserException("Unknown node name [%s]"%node_name)

        text = None
        if element.text is not None:
            text = TextUtils.strip_whitespace(element.text)

        node_class_instance = self._pattern_factory.new_node_class(node_name)
        node_instance = node_class_instance(element.attrib, text, userid)

        return node_instance
开发者ID:Freiza,项目名称:program-y,代码行数:16,代码来源:graph.py

示例9: parse_expression

# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import tag_from_text [as 别名]
    def parse_expression(self, graph, expression):
        li_found = False
        for child in expression:
            tag_name = TextUtils.tag_from_text(child.tag)

            if tag_name == 'li':
                li_found = True
                li_node = graph.get_base_node()
                self.children.append(li_node)
                li_node.parse_template_node(graph, child)
            else:
                raise ParserException("Unsupported random child tag: %s" % (tag_name), xml_element=expression)

        if li_found is False:
            raise ParserException("No li children of random element!", xml_element=expression)
开发者ID:Freiza,项目名称:program-y,代码行数:17,代码来源:rand.py

示例10: parse_expression

# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import tag_from_text [as 别名]
    def parse_expression(self, graph, expression):
        head_text = self.get_text_from_element(expression)
        self.parse_text(graph, head_text)

        for child in expression:
            tag_name = TextUtils.tag_from_text(child.tag)

            if tag_name == 'item':
                item = self.parse_children_as_word_node(graph, child)
                self._items.append(item)
            else:
                graph.parse_tag_expression(child, self)

            tail_text = self.get_tail_from_element(child)
            self.parse_text(graph, tail_text)
开发者ID:Freiza,项目名称:program-y,代码行数:17,代码来源:list.py

示例11: parse_expression

# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import tag_from_text [as 别名]
    def parse_expression(self, graph, expression):
        head_text = self.get_text_from_element(expression)
        self.parse_text(graph, head_text)

        for child in expression:
            tag_name = TextUtils.tag_from_text(child.tag)

            if tag_name == 'card':
                card_class = graph.get_node_class_by_name("card")
                card = card_class()
                card.parse_expression(graph, child)
                self._cards.append(card)
            else:
                graph.parse_tag_expression(child, self)

            tail_text = self.get_tail_from_element(child)
            self.parse_text(graph, tail_text)
开发者ID:Freiza,项目名称:program-y,代码行数:19,代码来源:carousel.py

示例12: parse_expression

# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import tag_from_text [as 别名]
    def parse_expression(self, graph, expression):
        if 'seconds' in expression.attrib:
            self._seconds = graph.get_word_node(expression.attrib['text'])

        head_text = self.get_text_from_element(expression)
        self.parse_text(graph, head_text)

        for child in expression:
            tag_name = TextUtils.tag_from_text(child.tag)

            if tag_name == 'seconds':
                self._seconds = self.parse_children_as_word_node(graph, child)

            else:
                graph.parse_tag_expression(child, self)

            tail_text = self.get_tail_from_element(child)
            self.parse_text(graph, tail_text)
开发者ID:Freiza,项目名称:program-y,代码行数:20,代码来源:delay.py

示例13: _parse_node_with_attrib

# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import tag_from_text [as 别名]
    def _parse_node_with_attrib(self, graph, expression, attrib_name, default_value=None):

        attrib_found = True
        if attrib_name in expression.attrib:
            self.set_attrib(attrib_name, expression.attrib[attrib_name])

        self.parse_text(graph, self.get_text_from_element(expression))

        for child in expression:
            tag_name = TextUtils.tag_from_text(child.tag)

            if tag_name == attrib_name:
                self.set_attrib(attrib_name, self.get_text_from_element(child))
            else:
                graph.parse_tag_expression(child, self)

            self.parse_text(graph, self.get_tail_from_element(child))

        if attrib_found is False:
            YLogger.debug(self, "Setting default value for attrib [%s]", attrib_name)
            self.set_attrib(attrib_name, default_value)
开发者ID:Freiza,项目名称:program-y,代码行数:23,代码来源:attrib.py

示例14: parse_expression

# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import tag_from_text [as 别名]
    def parse_expression(self, graph, expression):

        if 'path' in expression.attrib:
            self.path = expression.attrib['path']

        head_text = self.get_text_from_element(expression)
        self.parse_text(graph, head_text)

        for child in expression:
            tag_name = TextUtils.tag_from_text(child.tag)

            if tag_name == 'path':
                self.path = self.get_text_from_element(child)
            else:
                graph.parse_tag_expression(child, self)

            tail_text = self.get_tail_from_element(child)
            self.parse_text(graph, tail_text)

        if self.path is None:
            raise ParserException("EXTENSION node, path attribute missing !")
开发者ID:Freiza,项目名称:program-y,代码行数:23,代码来源:extension.py

示例15: parse_expression

# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import tag_from_text [as 别名]
    def parse_expression(self, graph, expression):

        name_found = False
        var_found = False

        if 'name' in expression.attrib:
            self.name = self.parse_attrib_value_as_word_node(graph, expression, 'name')
            self.local = False
            name_found = True

        if 'var' in expression.attrib:
            self.name = self.parse_attrib_value_as_word_node(graph, expression, 'var')
            self.local = True
            var_found = True

        self.parse_text(graph, self.get_text_from_element(expression))

        for child in expression:
            tag_name = TextUtils.tag_from_text(child.tag)

            if tag_name == 'name':
                self.name = self.parse_children_as_word_node(graph, child)
                self.local = False
                name_found = True

            elif tag_name == 'var':
                self.name = self.parse_children_as_word_node(graph, child)
                self.local = True
                var_found = True

            else:
                graph.parse_tag_expression(child, self)

            self.parse_text(graph, self.get_tail_from_element(child))

        if name_found is True and var_found is True:
            raise ParserException("Set node has both name AND var values", xml_element=expression)

        if name_found is False and var_found is False:
            raise ParserException("Set node has both name AND var values", xml_element=expression)
开发者ID:Freiza,项目名称:program-y,代码行数:42,代码来源:set.py


注:本文中的programy.utils.text.text.TextUtils.tag_from_text方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。