Exemplo n.º 1
0
 def __init_strict_conditions(self, pattern_structure: PatternStructure):
     """
     Augment the pattern with the contiguity constraints specified as a part of the consumption policy.
     """
     if not isinstance(pattern_structure, CompositeStructure):
         return
     args = pattern_structure.args
     for i in range(len(args)):
         self.__init_strict_conditions(args[i])
     if pattern_structure.get_top_operator() != SeqOperator:
         return
     for contiguous_sequence in self.consumption_policy.contiguous_names:
         for i in range(len(contiguous_sequence) - 1):
             for j in range(len(args) - 1):
                 if not isinstance(args[i], PrimitiveEventStructure) or \
                         not isinstance(args[i + 1], PrimitiveEventStructure):
                     continue
                 if contiguous_sequence[i] != args[j].name:
                     continue
                 if contiguous_sequence[i + 1] != args[j + 1].name:
                     raise Exception(
                         "Contiguity constraints contradict the pattern structure: "
                         + "%s must follow %s" %
                         (contiguous_sequence[i],
                          contiguous_sequence[i + 1]))
                 self.__add_contiguity_condition(args[i].name,
                                                 args[i + 1].name)
Exemplo n.º 2
0
 def __create_internal_node_by_operator(operator: PatternStructure, sliding_window: timedelta, parent: Node = None):
     """
     Creates an internal node representing a given operator.
     Note that negation node types are intentionally not supported here since the negative part of a pattern is
     added in a separate construction stage.
     """
     operator_type = operator.get_top_operator()
     if operator_type == SeqOperator:
         return SeqNode(sliding_window, parent)
     if operator_type == AndOperator:
         return AndNode(sliding_window, parent)
     if operator_type == KleeneClosureOperator:
         return KleeneClosureNode(sliding_window, operator.min_size, operator.max_size, parent)
     raise Exception("Unknown or unsupported operator %s" % (operator_type,))
Exemplo n.º 3
0
 def __extract_flat_sequences_aux(self, pattern_structure: PatternStructure) -> List[List[str]] or None:
     """
     An auxiliary method for extracting flat sequences from the pattern.
     """
     if isinstance(pattern_structure, PrimitiveEventStructure):
         return None
     if pattern_structure.get_top_operator() == SeqOperator:
         # note the double brackets - we return a list composed of a single list representing this sequence
         return [[arg.name for arg in pattern_structure.args if isinstance(arg, PrimitiveEventStructure)]]
     # the pattern is a composite pattern but not a flat sequence
     result = []
     for arg in pattern_structure.args:
         nested_sequences = self.__extract_flat_sequences_aux(arg)
         if nested_sequences is not None:
             result.extend(nested_sequences)
     return result