Esempio n. 1
0
def test(Skeleton, *StringPaths):
    global filter_f

    sm = core.DFA()

    idx0 = sm.init_state_index
    for character_sequence in StringPaths:
        idx = construct_path(sm, idx0, character_sequence, Skeleton)

    sm = nfa_to_dfa.do(sm)

    # Path analyzis may not consider the init state, so mount
    # an init state before everything.
    sm.add_transition(7777L, ord('0'), sm.init_state_index)
    sm.init_state_index = 7777L

    sm = sm.normalized_clone()
    path_list = find_core(sm)

    if filter_f:
        path_list = paths.select(path_list)

    for path in sorted(path_list,
                       key=lambda x:
                       (-len(x.step_list), x.step_list[-1].state_index)):
        print "# " + path.get_string().replace("\n", "\n# ")
Esempio n. 2
0
def find_core(sm, SelectF=False):
    print sm.get_graphviz_string(NormalizeF=False)
    print
    analyzer = Analyzer.from_StateMachine(sm, engine.FORWARD)
    for state in analyzer.state_db.itervalues():
        state.entry.categorize(state.index)
    analyzer.drop_out.entry.categorize(E_StateIndices.DROP_OUT)

    for state in analyzer.state_db.itervalues():
        assert state.transition_map is not None
        state.transition_map = state.transition_map.relate_to_DoorIDs(
            analyzer, state.index)

    AvailableStateIndexSet = set(analyzer.state_db.keys())
    CompressionType = E_Compression.PATH
    result = find.do(analyzer,
                     CompressionType=CompressionType,
                     AvailableStateIndexSet=AvailableStateIndexSet)

    print "## A character path does (not yet) produce a common door in the global drop-out"
    print "## (this happens in '.finalize()' of the MegaState."
    if SelectF:
        result = paths.select(result)
        paths.path_list_assert_consistency(result, analyzer,
                                           AvailableStateIndexSet,
                                           CompressionType)

    return result
Esempio n. 3
0
def find_core(sm, SelectF=False):
    print sm.get_graphviz_string(NormalizeF=False)
    print
    analyzer = Analyzer.from_StateMachine(sm, engine.FORWARD)
    for state in analyzer.state_db.itervalues():
        state.entry.categorize(state.index)
    analyzer.drop_out.entry.categorize(E_StateIndices.DROP_OUT)

    for state in analyzer.state_db.itervalues():
        assert state.transition_map is not None
        state.transition_map = state.transition_map.relate_to_DoorIDs(analyzer, state.index)

    AvailableStateIndexSet = set(analyzer.state_db.keys())
    CompressionType        = E_Compression.PATH
    result = find.do(analyzer, 
                     CompressionType=CompressionType, 
                     AvailableStateIndexSet=AvailableStateIndexSet)

    print "## A character path does (not yet) produce a common door in the global drop-out"
    print "## (this happens in '.finalize()' of the MegaState."
    if SelectF:
        result = paths.select(result)
        paths.path_list_assert_consistency(result, analyzer, AvailableStateIndexSet, CompressionType)

    return result
Esempio n. 4
0
def __test(path_list):
    print
    print "BEFORE:"
    for i, path in enumerate(path_list):
        print "  ", i, map(lambda x: x.state_index, path.step_list)

    path_list = select(path_list)

    print "AFTER:"
    for i, path in enumerate(path_list):
        print "  ", i, map(lambda x: x.state_index, path.step_list)
    print
Esempio n. 5
0
def test(Skeleton, *StringPaths):
    global filter_f

    sm = core.StateMachine()

    idx0 = sm.init_state_index
    for character_sequence in StringPaths:
        idx = construct_path(sm, idx0, character_sequence, Skeleton)

    sm = nfa_to_dfa.do(sm)

    # Path analyzis may not consider the init state, so mount 
    # an init state before everything.
    sm.add_transition(7777L, ord('0'), sm.init_state_index)
    sm.init_state_index = 7777L

    sm = sm.normalized_clone()
    path_list = find_core(sm)

    if filter_f:
        path_list = paths.select(path_list)

    for path in sorted(path_list, key=lambda x: (-len(x.step_list), x.step_list[-1].state_index)):
        print "# " + path.get_string().replace("\n", "\n# ")