def is_same_core(itm_a, itm_b): itm_lst_a = itm_a.to_acc_merged_form().get_sorted_items() itm_lst_b = itm_b.to_acc_merged_form().get_sorted_items() if len(itm_lst_a) != len(itm_lst_b): return False for i in xrange(len(itm_lst_a)): if not express.is_same_core(itm_lst_a[i], itm_lst_b[i]): return False return True
def to_acc_merged_form(self): exp_list = list(self.item_set) new_exps = set() visited = set() for i in xrange(len(exp_list)): if exp_list[i] in visited: continue lst = [exp_list[i]] acc_tokens = set(exp_list[i].acc_tokens) visited.add(exp_list[i]) for j in xrange(i + 1, len(exp_list)): if express.is_same_core(exp_list[i], exp_list[j]): lst.append(exp_list[j]) acc_tokens = acc_tokens.union(exp_list[j].acc_tokens) visited.add(exp_list[j]) new_exps.add(express_factory.create_lr1(exp_list[i].left_token, \ exp_list[i].get_right_tokens(), \ exp_list[i].dot_pos, acc_tokens)) return itemset_factory.create_lr1_itemset(new_exps)