def generate_mql(e):
    """
    Generates a MQL query for the `Expression` `e`.
    """
    start = choose_start_node(e)
    graph = to_bidirected_graph(e)
    generated = {}
    for node in post_order_depth_first(graph, start):
        d = {}
        for relation, other in graph[node]:
            if isnode(other):
                try:
                    other = generated[other]
                except __HOLE__:
                    continue  # other is not in post_order_depth_first order
            d[relation] = other
        generated[node] = [d]

    mql_query = json.dumps(generated[start], sort_keys=True,
                            indent=2, separators=(',', ': '))
    mql_query = _tidy(mql_query)
    target = paths_from_root(graph, start)[e.get_head()]
    return target, mql_query
dataset/ETHPy150Open machinalis/quepy/quepy/mql_generation.py/generate_mql