Esempio n. 1
0
def make_job(input_path, output_file):
    """Pair up lines in input_file, save as JSON"""
    
    with open(input_path, 'r') as i:
        for a, b in moreitertools.pairs(i):
            a, b = strip_newline(str(a)), strip_newline(str(b))
            output_file.write(json.dumps([a, b]))
            output_file.write('\n')
Esempio n. 2
0
             help="Specify a line pair to evaluate exclusively (for testing)")
    make_arg('-v', '--visualize', action='store_true', default=False,
             help="Generate PDFs of each regex pair's graph")
    make_arg('-i', '--inspect', action='store_true', default=False,
             help='Generate intermediate .dot files for visualization')
    make_arg('--version', action='version', version='%(prog)s 0.00000001')
    
    args = parser.parse_args(sys.argv[1:])
    
    i = 0
    if args.line is not None:
        a, b = list(moreitertools.line_pairs(args.files))[args.line]
        cg = chunkgraph.chunk_graph_from_string_pair(a, b)
        process_graph(cg)
    else:
        old_graphs = [chunkgraph.chunk_graph_from_string_pair(a, b) for 
                      a, b in moreitertools.line_pairs(args.files)]
        while len(old_graphs) > 1:
            print 'ITERATION!'
            new_graphs = [chunkgraph.ChunkGraph(a=a, b=b) for a, b in
                          moreitertools.pairs(old_graphs)]
            for cg in old_graphs:
                process_graph(cg)
            old_graphs = new_graphs
        print 'Final graphs:'
        for cg in new_graphs:
            process_graph(cg)
    
    for f in args.files:
        f.close()