def assert_considerations(A, B, result): """Set of rules which must hold in case the '\NotBegin' has been applied. """ assert superset.do(A, result) assert intersection.do([result, B]).is_Empty() assert identity.do(union.do([result, A]), A) assert intersection.do([result, derived.is_begin(A, B)]).is_Empty() assert identity.do(union.do([result, derived.is_begin(A, B)]), A)
def __core(Original, Cutter): print("Original = " + Original).replace("\n", "\\n").replace("\t", "\\t") print("Cutter = " + Cutter).replace("\n", "\\n").replace("\t", "\\t") orig = regex.do(Original, {}).extract_sm() cutter = regex.do(Cutter, {}).extract_sm() #print orig.get_string(NormalizeF=False) #print cutter.get_string(NormalizeF=False) # ComplementBegin = intersection(P, complement(Q)\Any*) result = derived.not_begin(orig, cutter) print if not result.is_Empty(): print "superset(Original, result): %s" % superset.do( orig, result) if not result.is_Empty(): tmp = clean(intersection.do([cutter, result])) print "intersection(Cutter, result) is None: %s" % tmp.is_Empty() tmp = clean(union.do([orig, result])) print "union(Original, result) == Original: %s" % identity.do( tmp, orig) print print "result = ", result.get_string(NormalizeF=True) assert_considerations(orig, cutter, result) return result
def _assert_no_intersections(SmList): # ESSENTIAL: Delimiter state machines shall never match on a common lexeme! if len(SmList) == 1: return intersection_sm = intersection.do(SmList) if intersection_sm.is_Nothing(): return elif intersection_sm.is_Empty(): return error.log("Skip range or indentation: Delimiter patterns intersect!\n" "(This should have been detected earlier during parsing)")
def __core(A_str, B_str): print("A = " + A_str).replace("\n", "\\n").replace("\t", "\\t") print("B = " + B_str).replace("\n", "\\n").replace("\t", "\\t") a_pattern = regex.do(A_str, {}) b_pattern = regex.do(B_str, {}) result = intersection.do([a_pattern.sm, b_pattern.sm]) print "intersection = ", result return result
def snap_intersection(stream, PatternDict): pattern_list = snap_curly_bracketed_expression(stream, PatternDict, "intersection operator", "Intersection", MinN=2, MaxN=INTEGER_MAX) return intersection.do(pattern_list)
def __core(A_str, B_str): print ("A = " + A_str).replace("\n", "\\n").replace("\t", "\\t") print ("B = " + B_str).replace("\n", "\\n").replace("\t", "\\t") a_pattern = regex.do(A_str, {}) b_pattern = regex.do(B_str, {}) result = intersection.do([a_pattern.sm, b_pattern.sm]) print "intersection = ", result return result
def test(SmList): print "-------------------------------------------------------------------------------" for tsm in SmList: print "##sm:", tsm sm = parallelize.do(SmList) print "RESULT:", sm complement_sm = complement.do(sm) assert all(superset.do(sm, tsm) == True for tsm in SmList) assert all( DFA.is_Empty(intersection.do([complement_sm, tsm])) for tsm in SmList)
def do(SM_List): """Result: A state machine that matches what is matched by one of the state machines but by no other. Formula: difference(union(All), intersection(All)) """ # Difference: It only remains in A what is not in A and B. tmp0 = union.do(SM_List) tmp1 = intersection.do(SM_List) return difference.do(tmp0, tmp1)
def __binary_checks(P, Q, Q_plus, Q_star_P): cut_P_Q = __operation(P, Q) cut_P_Qp = __operation(P, Q_plus) cut_QpP_Q = __operation(Q_star_P, Q) # \Intersection{Q \CutEnd{P Q+}} == \Empty assert intersection.do([Q, cut_P_Qp]).is_Empty() # \NotEnd{\CutEnd{P Q+} Q} == \CutEnd{P Q+} assert identity.do(derived.not_end(cut_P_Qp, Q), cut_P_Qp) # \IsEnd{\CutEnd{P Q+} Q} == \Empty assert derived.is_end(cut_P_Qp, Q).is_Empty() return cut_P_Qp
def test(A_str): print "_____________________________________________________________________" if isinstance(A_str, (str, unicode)): print ("A = " + A_str).replace("\n", "\\n").replace("\t", "\\t") sm = regex.do(A_str, {}).sm else: sm = A_str print "A = ", sm result_1st = complement.do(sm) print "complement(A):", result_1st result_2nd = complement.do(result_1st) print print "union(A, complement(A)): All =", is_all(union.do([sm, result_1st])) print "intersection(A, complement(A)): None =", is_none(intersection.do([sm, result_1st])) print "identity(A, complement(complement(A)):", identity.do(sm, result_2nd)
def __core(Original, Cutter): print ("Original = " + Original).replace("\n", "\\n").replace("\t", "\\t") print ("Cutter = " + Cutter).replace("\n", "\\n").replace("\t", "\\t") orig = regex.do(Original, {}).sm cutter = regex.do(Cutter, {}).sm #print orig.get_string(NormalizeF=False) #print cutter.get_string(NormalizeF=False) result = clean(complement_end.do(orig, cutter)) print if not special.is_none(result): print "superset(Original, result): %s" % superset.do(orig, result) if not special.is_none(result): tmp = clean(intersection.do([cutter, result])) print "intersection(Cutter, result) is None: %s" % special.is_none(tmp) tmp = clean(union.do([orig, result])) print "union(Original, result) == Original: %s" % identity.do(tmp, orig) print print "result = ", result.get_string(NormalizeF=True)
def __core(Original, Cutter): print("Original = " + Original).replace("\n", "\\n").replace("\t", "\\t") print("Cutter = " + Cutter).replace("\n", "\\n").replace("\t", "\\t") orig = regex.do(Original, {}).sm cutter = regex.do(Cutter, {}).sm #print orig.get_string(NormalizeF=False) #print cutter.get_string(NormalizeF=False) result = clean(complement_end.do(orig, cutter)) print if not special.is_none(result): print "superset(Original, result): %s" % superset.do( orig, result) if not special.is_none(result): tmp = clean(intersection.do([cutter, result])) print "intersection(Cutter, result) is None: %s" % special.is_none( tmp) tmp = clean(union.do([orig, result])) print "union(Original, result) == Original: %s" % identity.do( tmp, orig) print print "result = ", result.get_string(NormalizeF=True)
def test(A_str): print "_____________________________________________________________________" if isinstance(A_str, (str, unicode)): print("A = " + A_str).replace("\n", "\\n").replace("\t", "\\t") sm = regex.do(A_str, {}).extract_sm() else: sm = A_str print "A = ", sm ## print "##sm:", sm.get_string(NormalizeF=False) result_1st = complement.do(sm) print "complement(A):", result_1st # .get_string(NormalizeF=False) result_2nd = complement.do(result_1st) ## print "##2nd:", result_2nd.get_string(NormalizeF=False) print print "union(A, complement(A)): All =", DFA.is_Universal( union.do([sm, result_1st])) print "intersection(A, complement(A)): None =", DFA.is_Empty( intersection.do([sm, result_1st])) print "identity(A, complement(complement(A)):", identity.do(sm, result_2nd) assert not commonality(sm, result_1st) assert not commonality(result_1st, result_2nd)
def do(A, B): A_and_B = intersection.do([A, B]) not_A_and_B = complement.do(A_and_B) # Difference: It only remains in A what is not in A and B. return intersection.do([A, not_A_and_B])
def itsct(*A): return intersection.do(list(A)) def diff(A, B): return difference.do(A, B)
def is_begin(P, Q): return beautifier.do(intersection.do([P, anything_beginning_with(Q)]))
def snap_intersection(stream, PatternDict): pattern_list = snap_curly_bracketed_expression(stream, PatternDict, "intersection operator", "Intersection", MinN=2, MaxN=sys.maxint) return intersection.do(pattern_list)
def is_end(P, Q): return beautifier.do(intersection.do([P, anything_ending_with(Q)]))
def is_in(P, Q): return beautifier.do(intersection.do([P, anything_containing(Q)]))
def itsct(*A): return intersection.do(list(A))
out_n = 0 def output(Sm): global out_n if "help" not in sys.argv: print "sm%i: %s" % (out_n, Sm) else: open("tmp%i.dot" % out_n, "wb").write(Sm.get_graphviz_string(NormalizeF=True)) print "written 'tmp%i.dot'" % out_n out_n += 1 sm0.mark_state_origins() sm1.mark_state_origins() sm2.mark_state_origins() output(sm0) output(sm1) output(sm2) sm_list = [sm0, sm1, sm2] sm = parallelize.do(sm_list) print "#-------------------------------------------------------------------------------" output(sm) complement_sm = complement.do(sm) assert all(superset.do(sm, tsm) == True for tsm in sm_list) assert all(DFA.is_Empty(intersection.do([complement_sm, tsm])) for tsm in sm_list) print "<terminated>"
def assert_considerations(A, B, result): assert superset.do(A, result) assert intersection.do([result, B]).is_Empty() assert identity.do(union.do([result, A]), A) assert intersection.do([result, derived.is_in(A, B)]).is_Empty() assert identity.do(union.do([result, derived.is_in(A, B)]), A)