def __create_pattern_for_new_structure(structure: PatternStructure, pattern: Pattern): """ Creates a new pattern for the given transformed structure based on the given pattern. """ if structure == pattern.full_structure: return pattern condition_for_new_pattern = pattern.condition.get_condition_of( structure.get_all_event_names()) return Pattern(structure, condition_for_new_pattern, pattern.window, pattern.consumption_policy, None, pattern.confidence, pattern.statistics)
def __chop_matrix(pattern: Pattern, arg: PatternStructure, selectivity_matrix: List[List[float]]): """ Chop the matrix and returns only the rows and columns that are relevant to this arg (assuming this arg is in pattern's operators), based on the nested events' name in this arg. """ if pattern.count_primitive_events( positive_only=True) != len(selectivity_matrix): raise Exception("size mismatch") event_names = [ name for name in pattern.positive_structure.get_all_event_names() ] primitive_sons = [name for name in arg.get_all_event_names()] chop_start = event_names.index(primitive_sons[0]) chop_end = event_names.index(primitive_sons[-1]) return TreePlanBuilder.__chop_matrix_aux(selectivity_matrix, chop_start, chop_end)