Beispiel #1
0
    def _build_automaton(self, ot: utils.ObservationTable) -> automaton.DFA:
        """
        Builds an automaton from the observation table.

        :type ot: ObservationTable
        :return: Automaton built from the observation table
        :rtype: Automaton
        """
        dfa = automaton.DFA(self._alphabet)

        states = {automaton.State(i) for i in self._red}

        we = utils.break_strings_in_two(self._red)
        for w, e in we:
            we = w + e
            if we in self._red and ot.entry_exists(w, e):
                val = ot.get(w, e)
                state = automaton.State(we)
                if val == 1:
                    dfa.accept_states.add(state)
                    states.add(state)
                elif val == 0:
                    dfa.reject_states.add(state)
                    states.add(state)

        for w in states:
            for a in self._alphabet:
                for u in self._red:
                    wa = w.name + a
                    if ot.row_exists(u) and ot.row_exists(wa) and \
                            ot.get_row(u) == ot.get_row(wa):
                        dfa.add_transition(w, automaton.State(u), a)

        return dfa
 def test_ot_03(self):
     ot = ObservationTable(set(), {''}, set())
     ot.add_row('a')
     self.assertEqual({}, ot.get_row('a'))
     ot.put('a', 'a', 1)
     ot.put('a', 'b', 0)
     self.assertEqual(0, ot.get('a', 'b'))
     self.assertEqual(True, ot.row_exists('a'))
     self.assertEqual(False, ot.row_exists('b'))
     try:
         ot.get('a', 'c')
         self.fail('Indexing row and column that'
                   ' is not defined should throw an exception!')
     except KeyError:
         self.assertTrue(True)