コード例 #1
0
    def get_rule(node):
        """
        Extracts the rule corresponding to the XML specification.

        :param node: topNode the XML node
        :return: the corresponding rule
        """

        # extracting the rule type
        rule_type = RuleType.PROB
        if 'util=' in XMLUtils.serialize(node):
            rule_type = RuleType.UTIL

        # setting the rule identifier
        try:
            rule_id = node.attrib['id']
        except:
            rule_id = 'rule' + str(XMLRuleReader._id_counter)
            XMLRuleReader._id_counter += 1

        # creating the rule
        rule = Rule(rule_id, rule_type)

        priority = 1
        if 'priority' in node.keys():
            priority = int(node.attrib['priority'])

        # extracting the rule cases
        for child_node in node:
            if child_node.tag == 'case':
                condition = XMLRuleReader._get_condition(child_node)
                output = XMLRuleReader._get_output(child_node, rule_type, priority)
                rule.add_case(condition, output)
            elif XMLUtils.has_content(node):
                if node.tag == '#text':
                    raise ValueError()

        return rule
コード例 #2
0
 def get_record(self):
     """
     Serialises the XML recordings and returns the output.
     :return: the serialised XML content.
     """
     return XMLUtils.serialize(self._root_node)