def _espresso_to_symset(cls, sym_text): ''' this funmction receives a single line of the espresso output and returns a single symbolset of that :param sym_text: (string) a single line of the espresso output .p :return: (PackedIntervalSet, String) string represents the function output ''' assert sym_text, "fix this" dims_solutions = sym_text.split() dims_solutions, out_str = dims_solutions[:-1], dims_solutions[-1] max_val_per_dim = len(dims_solutions[0]) - 1 all_dims_result = [] for d in range(len(dims_solutions)): dim_solution = dims_solutions[d] start_indexs = [0] if dim_solution[0] == '1' else [] for zo in cls._to_one_transition_pattern.finditer(dim_solution): start_indexs.append(zo.start() + 1) end_indexes = [] for oz in cls._to_zero_transition_pattern.finditer(dim_solution): end_indexes.append(oz.start()) if dim_solution[-1] == '1': end_indexes.append(max_val_per_dim) assert len(start_indexs) == len(end_indexes) all_dims_result.append([ (s, e) for s, e in zip(start_indexs, end_indexes) ]) new_symbol_set = PackedIntervalSet([]) for p in product(*all_dims_result): left = tuple(s for s, _ in p) right = tuple(e for _, e in p) left_pt = PackedInput(left) right_pt = PackedInput(right) pi = PackedInterval(left_pt, right_pt) new_symbol_set.add_interval(pi) return new_symbol_set, out_str
def _replace_equivalent_symbols(symbol_dictionary_list, atms_list, max_val): ''' :param atms: list of auotmatas :param symbol_dictionary_list: a dictionary from nodes to set of 1D numbers :param max_val new max value :return: a list of automatas with replaces symbols ''' for atm, sym_dic in zip(atms_list, symbol_dictionary_list): node_edge_iter = atm.nodes if atm.is_homogeneous else atm.get_edges() for ne in node_edge_iter: if atm.is_homogeneous and ne.type == ElementsType.FAKE_ROOT: continue sym_set = ne.symbols if atm.is_homogeneous else ne[2]['symbol_set'] new_symbol_set = PackedIntervalSet([]) sym_set.mutable = False ivls = get_interval(list(sym_dic[sym_set])) sym_set.mutable = True for l, r in ivls: left_pt = PackedInput((l,)) right_pt = PackedInput((r,)) new_symbol_set.add_interval(PackedInterval(left_pt, right_pt)) new_symbol_set.prone() new_symbol_set.merge() # this is not necessary. TODO remove it if atm.is_homogeneous: ne.symbols = new_symbol_set else: ne[2]['symbol_set'] = new_symbol_set atm.stride_value = 1 atm.max_val_dim = max_val
from automata import Automatanetwork from automata.elemnts.ste import S_T_E,StartType, PackedIntervalSet, PackedInterval, PackedInput import networkx env = Environment(loader=FileSystemLoader('Templates'), extensions=['jinja2.ext.do']) # template = env.get_template('LUT_match.template') # # rendered_content = template.render(intervals=[[(1, 2), (3, 5)], [(44, 76), (78, 99)]]) # # print rendered_content atm = Automatanetwork(id='temp_automata', is_homogenous=True, stride=2, max_val=255) symbol_set1 = PackedIntervalSet([PackedInterval(PackedInput((1,2)),PackedInput((3,5))), PackedInterval(PackedInput((44,76)),PackedInput((78,99)))]) ste1 = S_T_E(start_type=StartType.start_of_data, is_report=False, is_marked=False, id=atm.get_new_id(), symbol_set=symbol_set1, adjacent_S_T_E_s=None, report_residual=0, report_code=0 ) atm.add_element(ste1) symbol_set2 = PackedIntervalSet([PackedInterval(PackedInput((10,20)),PackedInput((30,50))), PackedInterval(PackedInput((4,76)),PackedInput((7,99)))]) ste2 = S_T_E(start_type=StartType.non_start, is_report=True, is_marked=False, id=atm.get_new_id(), symbol_set=symbol_set2, adjacent_S_T_E_s=None, report_residual=0, report_code=0 )
from automata.automata_network import Automatanetwork from automata.elemnts.ste import S_T_E, PackedIntervalSet, PackedInterval, PackedInput, get_Symbol_type from automata.elemnts.element import StartType from automata.utility.utility import minimize_automata my_Automata = Automatanetwork(id="test1", is_homogenous=True, stride=1, max_val=255) ste1 = S_T_E(start_type=StartType.start_of_data, is_report=False, is_marked=False, id=my_Automata.get_new_id(), symbol_set=get_Symbol_type(True)( [PackedInterval(PackedInput((1, )), PackedInput((1, )))]), adjacent_S_T_E_s=None, report_residual=0, report_code=-1) ste2 = S_T_E(start_type=StartType.non_start, is_report=False, is_marked=False, id=my_Automata.get_new_id(), symbol_set=get_Symbol_type(True)( [PackedInterval(PackedInput((2, )), PackedInput((2, )))]), adjacent_S_T_E_s=None, report_residual=0, report_code=-1) ste3 = S_T_E(start_type=StartType.non_start,
import subprocess from jinja2 import Environment, FileSystemLoader from automata.elemnts.ste import PackedIntervalSet, PackedInterval, PackedInput from automata.Espresso.espresso import get_splitted_sym_sets import re symset = PackedIntervalSet([]) symset.add_interval(PackedInterval(PackedInput((5, 5)), PackedInput((8, 9)))) symset.add_interval(PackedInterval(PackedInput((4, 5)), PackedInput((7, 9)))) symset.add_interval(PackedInterval(PackedInput((8, 1)), PackedInput((9, 6)))) a, b = get_splitted_sym_sets(symset=symset, max_val=15) print a, b