<commit_before>from os import path
from collections import namedtuple
import click
import graphviz
from functional import seq

ENGINES = ['dot', 'neato', 'twopi', 'circo', 'fdp', 'sfdp', 'patchword', 'osage']
Edge = namedtuple('Edge', 'left right label')


def split_edge(edge):
    edge_label = None
    if ':' in edge:
        edge, edge_label = edge.split(':')
    if '-' in edge:
        left, right = edge.split('-')
        if right == '':
            right = None
    else:
        left, right = edge
    return Edge(left, right, edge_label)


@click.command()
@click.option('--engine', '-e', default='dot', type=click.Choice(ENGINES))
@click.option('--undirected/--directed', '-u/-d', default=True)
@click.option('--format', default='png', type=str)
@click.option('--name', '-n', default=None, type=str)
@click.argument('file', type=click.Path(writable=True))
@click.argument('edges', nargs=-1, required=True)
def main(engine, undirected, format, name, file, edges):
    if undirected:
        graph = graphviz.Graph(engine=engine, format=format)
    else:
        graph = graphviz.Digraph(engine=engine, format=format)
    if name:
        graph.body.append(r'label = "{0}"'.format(name))
    edges = seq(edges).map(split_edge)
    edges.map(lambda e: (e.left, e.right)).flatten().distinct()\
        .filter_not(lambda n: n is None).for_each(lambda n: graph.node(n))
    edges.filter(lambda e: e.right is not None)\
        .for_each(lambda e: graph.edge(e.left, e.right, label=e.label))
    filepath, filename = path.split(file)
    filepath = filepath if filepath != '' else None
    graph.render(filename=filename, directory=filepath, cleanup=True)


if __name__ == '__main__':
    main()<commit_msg>Add flag to save the source<commit_after>from os import path
from collections import namedtuple
import click
import graphviz
from functional import seq

ENGINES = ['dot', 'neato', 'twopi', 'circo', 'fdp', 'sfdp', 'patchword', 'osage']
Edge = namedtuple('Edge', 'left right label')


def split_edge(edge):
    edge_label = None
    if ':' in edge:
        edge, edge_label = edge.split(':')
    if '-' in edge:
        left, right = edge.split('-')
        if right == '':
            right = None
    else:
        left, right = edge
    return Edge(left, right, edge_label)


@click.command()
@click.option('--engine', '-e', default='dot', type=click.Choice(ENGINES))
@click.option('--undirected/--directed', '-u/-d', default=True)
@click.option('--format', default='png', type=str)
@click.option('--name', '-n', default=None, type=str)
@click.option('--dot', is_flag=True)
@click.argument('file', type=click.Path(writable=True))
@click.argument('edges', nargs=-1, required=True)
def main(engine, undirected, format, name, dot, file, edges):
    if undirected:
        graph = graphviz.Graph(engine=engine, format=format)
    else:
        graph = graphviz.Digraph(engine=engine, format=format)
    if name:
        graph.body.append(r'label = "{0}"'.format(name))
    edges = seq(edges).map(split_edge)
    edges.map(lambda e: (e.left, e.right)).flatten().distinct()\
        .filter_not(lambda n: n is None).for_each(lambda n: graph.node(n))
    edges.filter(lambda e: e.right is not None)\
        .for_each(lambda e: graph.edge(e.left, e.right, label=e.label))
    filepath, filename = path.split(file)
    filepath = filepath if filepath != '' else None
    graph.render(filename=filename, directory=filepath, cleanup=not dot)


if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.17015781922525108, 'fraction_numerical': 0.0011477761836441894, 'mean_word_length': 3.7171853856562924, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3985249', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1153, 'n_words': 284}