Пример #1
0
 def __adjust_leaf_indices(self, pattern: Pattern):
     """
     Fixes the values of the leaf indices in the positive tree to take the negative events into account.
     """
     leaf_mapping = {}
     # update the leaves
     for leaf in self.get_leaves():
         current_index = leaf.get_leaf_index()
         correct_index = pattern.get_index_by_event_name(leaf.get_event_name())
         leaf.set_leaf_index(correct_index)
         leaf_mapping[current_index] = correct_index
     # update the event definitions in the internal nodes
     # note that it is enough to only update the root since it contains all the event definition objects
     for event_def in self.__root.get_event_definitions():
         event_def.index = leaf_mapping[event_def.index]
Пример #2
0
 def __add_negative_tree_structure(self, pattern: Pattern):
     """
     Adds the negative nodes at the root of the tree.
     """
     top_operator = pattern.full_structure.get_top_operator()
     negative_event_list = pattern.negative_structure.get_args()
     current_root = self.__root
     for negation_operator in negative_event_list:
         if top_operator == SeqOperator:
             new_root = NegativeSeqNode(pattern.window,
                                        is_unbounded=Tree.__is_unbounded_negative_event(pattern, negation_operator))
         elif top_operator == AndOperator:
             new_root = NegativeAndNode(pattern.window,
                                        is_unbounded=Tree.__is_unbounded_negative_event(pattern, negation_operator))
         else:
             raise Exception("Unsupported operator for negation: %s" % (top_operator,))
         negative_event = negation_operator.arg
         leaf_index = pattern.get_index_by_event_name(negative_event.name)
         negative_leaf = LeafNode(pattern.window, leaf_index, negative_event, new_root)
         new_root.set_subtrees(current_root, negative_leaf)
         negative_leaf.set_parent(new_root)
         current_root.set_parent(new_root)
         current_root = new_root
     self.__root = current_root