<commit_before>from romanesco.format import dict_to_vtkarrays, dict_to_vtkrow
import vtk

vtk_builder = vtk.vtkMutableDirectedGraph()
node_fields = input["node_fields"]
edge_fields = input["edge_fields"]
dict_to_vtkarrays(input["node_data"], node_fields, vtk_builder.GetVertexData())
if "children" in input and len(input["children"]) > 0:
    dict_to_vtkarrays(input["children"][0]["edge_data"], edge_fields,
                      vtk_builder.GetEdgeData())


def process_node(vtknode, node):
    if "children" in node:
        for n in node["children"]:
            vtkchild = vtk_builder.AddVertex()
            vtkparentedge = vtk_builder.AddGraphEdge(vtknode, vtkchild).GetId()
            dict_to_vtkrow(n["node_data"], vtk_builder.GetVertexData())
            dict_to_vtkrow(n["edge_data"], vtk_builder.GetEdgeData())
            process_node(vtkchild, n)
vtk_builder.AddVertex()
dict_to_vtkrow(input["node_data"], vtk_builder.GetVertexData())
process_node(0, input)
output = vtk.vtkTree()
output.ShallowCopy(vtk_builder)<commit_msg>tolerate missing edge data<commit_after>from romanesco.format import dict_to_vtkarrays, dict_to_vtkrow
import vtk

vtk_builder = vtk.vtkMutableDirectedGraph()
node_fields = input["node_fields"]
edge_fields = input["edge_fields"]
dict_to_vtkarrays(input["node_data"], node_fields, vtk_builder.GetVertexData())
if "children" in input and len(input["children"]) > 0:
    dict_to_vtkarrays(input["children"][0]["edge_data"], edge_fields,
                      vtk_builder.GetEdgeData())


def process_node(vtknode, node):
    if "children" in node:
        for n in node["children"]:
            vtkchild = vtk_builder.AddVertex()
            vtkparentedge = vtk_builder.AddGraphEdge(vtknode, vtkchild).GetId()
            dict_to_vtkrow(n["node_data"], vtk_builder.GetVertexData())
            if "edge_data" in n:
                dict_to_vtkrow(n["edge_data"], vtk_builder.GetEdgeData())
            process_node(vtkchild, n)
vtk_builder.AddVertex()
dict_to_vtkrow(input["node_data"], vtk_builder.GetVertexData())
process_node(0, input)
output = vtk.vtkTree()
output.ShallowCopy(vtk_builder)
{'fraction_non_alphanumeric': 0.12077067669172932, 'fraction_numerical': 0.002819548872180451, 'mean_word_length': 4.662234042553192, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '3005900', 'n_tokens_mistral': 740, 'n_tokens_neox': 722, 'n_words': 118}