@in_place_transformation<EOL>def collapse_nodes_with_same_names(graph: BELGraph) -> None:
survivor_mapping = defaultdict(set) <EOL>victims = set() <EOL>it = tqdm(itt.combinations(graph, r=<NUM_LIT:2>), total=graph.number_of_nodes() * (graph.number_of_nodes() - <NUM_LIT:1>) / <NUM_LIT:2>)<EOL>for a, b in it:<EOL><INDENT>if b in victims:<EOL><INDENT>continue<EOL><DEDENT>a_name, b_name = a.get(NAME), b.get(NAME)<EOL>if not a_name or not b_name or a_name.lower() != b_name.lower():<EOL><INDENT>continue<EOL><DEDENT>if a.keys() != b.keys():  <EOL><INDENT>continue<EOL><DEDENT>for k in set(a.keys()) - {NAME, NAMESPACE}:<EOL><INDENT>if a[k] != b[k]:  <EOL><INDENT>continue<EOL><DEDENT><DEDENT>survivor_mapping[a].add(b)<EOL>victims.add(b)<EOL><DEDENT>collapse_nodes(graph, survivor_mapping)<EOL>
Collapse all nodes with the same name, merging namespaces by picking first alphabetical one.