def test_parallel_many_events(self):
        event_group = EventGroupParallel([
            EventGroupParallel([Event('a'), Event('b')]),
            # Event('c'), Event('d'), Event('e'), Event('f'), Event('g'),
            # Event('h'),
            # Event('i'),
            Event('j'),
            Event('k'),
            Event('l'),
            Event('m'),
            Event('n'),
            EventGroupParallel([Event('o'), Event('p'),
                                Event('q')])
        ])

        alignment_cached = BestAlignmentCached()
        result, model_result = alignment_cached.get_best_alignment(
            event_group, [
                'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
                'm', 'n'
            ], dict())
        char_list = events_to_char_list(model_result)
        print(events_to_char_list(model_result))
        self.assertEqual(-10, result)
        self.assertCountEqual([x for x in 'abcdefghijklmn'], char_list)
    def test_additional3(self):
        event_group = EventGroup([
            EventGroupParallel([Event('c'), Event('f')]),
            EventGroupParallel([Event('a'), Event('b')]),
            Event('c')
        ])

        alignment_cached = BestAlignmentCached()
        result, model_result = alignment_cached.get_best_alignment(
            event_group, ['b', 'c', 'd'], dict())
        char_list = events_to_char_list(model_result)
        print(events_to_char_list(model_result))
        self.assertEqual(-4, result)
        self.assertCountEqual([x for x in ['b', 'c']], char_list)
        self.assertEqual(['b', 'c'], events_to_char_list(model_result))
 def test_92(self):
     gate = SeqGate()
     gate.parse('and({a}{f}opt(and({b}{e}lop({c}))){d})')
     all_length_6_routes = gate.get_all_n_length_routes(6)
     expected = [
         EventGroupMatcher(
             EventGroup([
                 EventGroupParallel([
                     Event('a'),
                     Event('f'),
                     EventGroupParallel(string_to_events('bec')),
                     Event('d')
                 ])
             ]))
     ]
     self.assertCountEqual(expected, all_length_6_routes)
    def test_all_events_in_model(self):
        # when your algorithm is smarter than you
        event_group = EventGroupParallel([
            Event('a'),
            Event('f'),
            EventGroupParallel(string_to_events('bec')),
            Event('d')
        ])

        alignment_cached = BestAlignmentCached()
        result, model_result = alignment_cached.get_best_alignment(
            event_group, ['a', 'b', 'c', 'd', 'e', 'f'], dict())
        char_list = events_to_char_list(model_result)
        print(events_to_char_list(model_result))
        self.assertEqual(-2, result)
        self.assertCountEqual([x for x in ['a', 'b', 'c', 'e', 'f']],
                              char_list)
 def test_9(self):
     gate = SeqGate()
     gate.parse('and({c}and({a}lop({e}opt({d}))seq({c}{b})))')
     all_length_5_routes = gate.get_all_n_length_routes(5)
     expected = [
         EventGroupMatcher(
             EventGroup([
                 EventGroupParallel([
                     Event('c'),
                     EventGroupParallel([
                         Event('a'),
                         Event('e'),
                         EventGroup(string_to_events('cb'))
                     ])
                 ])
             ]))
     ]
     self.assertCountEqual(expected, all_length_5_routes)
    def test_legend(self):
        event_group = EventGroup([
            Event('a'),
            EventGroupParallel([Event('c'), Event('d')]),
            Event('e'),
            Event('h')
        ])

        alignment_cached = BestAlignmentCached()
        result, model_result = alignment_cached.get_best_alignment(
            event_group, ['a', 'c', 'd', 'e', 'h'], dict())
        char_list = events_to_char_list(model_result)
        print(events_to_char_list(model_result))
        self.assertEqual(0, result)
        self.assertCountEqual([x for x in ['a', 'c', 'd', 'e', 'h']],
                              char_list)
        self.assertEqual(['a', 'c', 'd', 'e', 'h'],
                         events_to_char_list(model_result))
 def test_8(self):
     gate = SeqGate()
     gate.parse(
         'xor({f}{d}and({e}xor(lop(xor({f}{d}))lop({a}))))and({b}{a})')
     all_length_3_routes = gate.get_all_n_length_routes(3)
     self.assertCountEqual([
         EventGroupMatcher(
             EventGroup(
                 [Event('f'),
                  EventGroupParallel(string_to_events('ba'))])),
         EventGroupMatcher(
             EventGroup(
                 [Event('d'),
                  EventGroupParallel(string_to_events('ba'))])),
         EventGroupMatcher(
             EventGroup(
                 [Event('e'),
                  EventGroupParallel(string_to_events('ba'))]))
     ], all_length_3_routes)
    def test_nw_with_wrapper_parallel_inside_9(self):
        event_group = EventGroup([
            Event('f'),
            EventGroupParallel(
                [EventGroupParallel(string_to_events('dc')),
                 Event('f')]),
            Event('b'),
            EventGroupParallel(
                [EventGroupParallel(string_to_events('df')),
                 Event('e')])
        ])

        alignment_cached = BestAlignmentCached()
        result, model_result = alignment_cached.get_best_alignment(
            event_group, ['a', 'c', 'b', 'd'], dict())
        char_list = events_to_char_list(model_result)
        print(events_to_char_list(model_result))
        self.assertEqual(-6, result)
        self.assertCountEqual([x for x in ['c', 'b', 'd']], char_list)
        self.assertEqual(['c', 'b', 'd'], events_to_char_list(model_result))
    def test_2(self):
        gate = SeqGate()
        gate.parse('{f}xor({d}and({b}lop({c})opt({a})))')

        actual = gate.get_all_n_length_routes(5)
        expected_1 = EventGroupMatcher(
            EventGroup([
                Event('f'),
                EventGroupParallel(
                    [Event('b'),
                     EventGroup(string_to_events('ccc'))])
            ]))
        expected_2 = EventGroupMatcher(
            EventGroup([
                Event('f'),
                EventGroupParallel([
                    Event('b'),
                    EventGroup(string_to_events('cc')),
                    Event('a')
                ])
            ]))
        expected = [expected_1, expected_2]
        self.assertCountEqual(expected, actual)
    def test_nw_with_wrapper_parallel_inside(self):
        event_group = EventGroupParallel(
            [Event('t'),
             EventGroupParallel(string_to_events('spqacezxy'))])

        alignment_cached = BestAlignmentCached()
        result, model_result = alignment_cached.get_best_alignment(
            event_group, ['z', 'x', 'a', 'b', 'c', 'd', 'e', 'z', 't'], dict())
        char_list = events_to_char_list(model_result)
        print(events_to_char_list(model_result))
        self.assertEqual(-7, result)
        self.assertCountEqual([x for x in ['z', 'x', 'a', 'c', 'e', 't']],
                              char_list)
        self.assertEqual(['z', 'x', 'a', 'c', 'e', 't'],
                         events_to_char_list(model_result))
    def test_nw_with_wrapper_model_bigger(self):
        event_group_events = []
        for x in 'pqacezxysabc':
            event_group_events.append(Event(x))
        event_group = EventGroup(event_group_events)

        alignment_cached = BestAlignmentCached()
        result, model_result = alignment_cached.get_best_alignment(
            event_group, ['z', 'x', 'a', 'b', 'c', 'd', 'e', 'z', 'x'], dict())
        print(events_to_char_list(model_result))
        self.assertEqual(-11, result)
        self.assertCountEqual([x for x in ['a', 'c', 'e', 'z', 'x']],
                              events_to_char_list(model_result))
        self.assertEqual(['a', 'c', 'e', 'z', 'x'],
                         events_to_char_list(model_result))
 def test_cache(self):
     event_group = [
         EventGroupParallel([
             Event('a'),
             Event('f'),
             EventGroupParallel(string_to_events('bec')),
             Event('d')
         ])
     ]
     event_group2 = [
         EventGroupParallel([
             Event('a'),
             Event('f'),
             EventGroupParallel(string_to_events('bec')),
             Event('d')
         ])
     ]
     log = ['a', 'b', 'c', 'd', 'e', 'f']
     log2 = ['a', 'b', 'c', 'd', 'e', 'f']
     cache1 = get_cache_id(event_group, log)
     cache2 = get_cache_id(event_group2, log2)
     self.assertEqual(cache1, cache2)
Exemplo n.º 13
0
def string_to_events(string: str):
    event_group_events = []
    for x in string:
        event_group_events.append(Event(x))
    return event_group_events
Exemplo n.º 14
0
    def parse(self, expression: str) -> int:

        numbers = iter(range(len(expression)))
        for i in numbers:
            if expression[i] == "{":
                event = Event(expression[i + 1])
                self.add_element(event)
                consume(numbers, 2)
            elif expression[i] == ")":
                return i + 1
            elif i + 4 < len(expression):
                if expression[i:i + 3] == "seq" and (self.name == "seq"
                                                     or self.name == "lop"):
                    consume(numbers, 3)
                    processed_characters = self.parse(expression[i + 4:])
                    consume(numbers, processed_characters)
                else:
                    if expression[i:i +
                                  2] == 'lo' and expression[i:i + 3] != 'lop':
                        gate_class = getattr(
                            importlib.import_module(
                                "process_discovery.gate.lop_gate"), "LopGate")
                        gate = gate_class(self)
                        consume(numbers, 3)
                        processed_characters = gate.parse(expression[i + 4:])
                        if self.name == "seq" or self.name == "lop":
                            child_number = len(gate.elements)
                            if int(expression[i + 2]) <= child_number:
                                for x in gate.elements[int(expression[i +
                                                                      2]):]:
                                    to_add = deepcopy(x)
                                    to_add.parent = self
                                    self.add_element(to_add)
                        self.add_element(gate)
                        consume(numbers, processed_characters)
                    elif expression[i:i + 3] == "osq":
                        outer_gate_class = getattr(
                            importlib.import_module(
                                "process_discovery.gate.opt_gate"), "OptGate")
                        outer_gate = outer_gate_class(self)
                        gate_class = getattr(
                            importlib.import_module(
                                "process_discovery.gate.seq_gate"), "SeqGate")
                        gate = gate_class(outer_gate)
                        outer_gate.add_element(gate)
                        consume(numbers, 3)
                        processed_characters = gate.parse(expression[i + 4:])
                        self.add_element(outer_gate)
                        consume(numbers, processed_characters)
                    else:
                        gate_class = getattr(
                            importlib.import_module("process_discovery.gate." +
                                                    expression[i:i + 3] +
                                                    "_gate"),
                            expression[i:i + 3].capitalize() + "Gate")
                        gate = gate_class(self)
                        consume(numbers, 3)
                        processed_characters = gate.parse(expression[i + 4:])
                        self.add_element(gate)
                        consume(numbers, processed_characters)
            else:
                raise Exception
 def test_eq4(self):
     e1 = EventGroup([Event('f'), EventGroupParallel([Event('b'),
                                                      EventGroup(string_to_events('ccc'))])])
     e2 = EventGroupParallel([Event('f'), EventGroup([Event('b'),
                                                      EventGroupParallel(string_to_events('ccc'))])])
     self.assertFalse(e1 == e2)