<s> import argparse <EOL> from compreffor import pyCompressor <EOL> class SimpleSubstringFinder ( pyCompressor . SubstringFinder ) : <EOL> def get_substrings ( self , min_freq = <NUM_LIT:2> , check_positive = True , sort_by_length = False ) : <EOL> movetos = set ( ) <EOL> for idx , tok in enumerate ( self . rev_keymap ) : <EOL> if isinstance ( tok , basestring ) and tok [ - <NUM_LIT:6> : ] == "<STR_LIT>" : <EOL> movetos . add ( idx ) <EOL> try : <EOL> hmask = self . rev_keymap . index ( "<STR_LIT>" ) <EOL> except ValueError : <EOL> hmask = None <EOL> matches = { } <EOL> for glyph_idx , program in enumerate ( self . data ) : <EOL> cur_start = <NUM_LIT:0> <EOL> last_op = - <NUM_LIT:1> <EOL> for pos , tok in enumerate ( program ) : <EOL> if tok in movetos : <EOL> stop = last_op + <NUM_LIT:1> <EOL> if stop - cur_start > <NUM_LIT:0> : <EOL> if program [ cur_start : stop ] in matches : <EOL> matches [ program [ cur_start : stop ] ] . freq += <NUM_LIT:1> <EOL> else : <EOL> span = pyCompressor . CandidateSubr ( stop - cur_start , <EOL> ( glyph_idx , cur_start ) , <EOL> <NUM_LIT:1> , <EOL> self . data , <EOL> self . cost_map ) <EOL> matches [ program [ cur_start : stop ] ] = span <EOL> cur_start = pos + <NUM_LIT:1> <EOL> elif tok == hmask : <EOL> last_op = pos + <NUM_LIT:1> <EOL> elif type ( self . rev_keymap [ tok ] ) == str : <EOL> last_op = pos <EOL> constraints = lambda s : ( s . freq >= min_freq and <EOL> ( s . subr_saving ( ) > <NUM_LIT:0> or not check_positive ) ) <EOL> self . substrings = filter ( constraints , matches . values ( ) ) <EOL> if sort_by_length : <EOL> self . substrings . sort ( key = lambda s : len ( s ) ) <EOL> else : <EOL> self . substrings . sort ( key = lambda s : s . subr_saving ( ) , reverse = True ) <EOL> return self . substrings <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT:filename>' , help = '<STR_LIT>' , nargs = '<STR_LIT:*>' ) <EOL> parser . add_argument ( '<STR_LIT>' , required = False , action = '<STR_LIT:store_true>' , <EOL> dest = '<STR_LIT:test>' , default = False ) <EOL> parser . add_argument ( '<STR_LIT>' , required = False , action = '<STR_LIT:store_true>' , <EOL> dest = '<STR_LIT>' , default = False ) <EOL> parser . add_argument ( '<STR_LIT:-c>' , required = False , action = '<STR_LIT:store_true>' , <EOL> dest = '<STR_LIT>' , default = False ) <EOL> kwargs = vars ( parser . parse_args ( ) ) <EOL> pyCompressor . SubstringFinder = SimpleSubstringFinder <EOL> pyCompressor . main ( ** kwargs ) </s>
