Created
August 16, 2023 05:55
-
-
Save fedarko/dffb649120dbb2040da502cc5a4eb566 to your computer and use it in GitHub Desktop.
Checks for "conflicting" node IDs defined multiple times in a DOT file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# | |
# Scans through a jumboDBG / LJA output DOT file; looks for cases where | |
# the same node is "defined" on multiple lines. This can be caused by the | |
# same truncated node ID being misused across lines. | |
# | |
# USAGE: | |
# ./check_for_conflicting_node_ids.py graph.dot | |
# | |
# Note that this assumes that the input graph was output by jumboDBG / LJA -- | |
# that is, all nodes are defined on lines that include the word "filled". | |
# If this is not the case for your graph, this will not notice certain nodes. | |
import sys | |
from collections import Counter | |
if len(sys.argv) != 2: | |
raise ValueError("This program only needs one argument (a DOT file)") | |
graph_fn = sys.argv[1] | |
print(f"Looking in DOT file {graph_fn}...") | |
seen_nodes = [] | |
with open(graph_fn, "r") as f: | |
for line in f: | |
# HACK -- depends on jumboDBG / LJA always labelling nodes as "style=filled" | |
if "filled" in line: | |
nodename = line.split(" ")[0] | |
seen_nodes.append(nodename) | |
c = Counter(seen_nodes) | |
multi = [x for x in c if c[x] > 1] | |
print(f"Saw {len(seen_nodes):,} node line(s) in the DOT file.") | |
if len(multi) > 0: | |
print(f"{len(multi):,} nodes occur more than 1 time:") | |
print(multi) | |
else: | |
print("Phew, no nodes occur more than 1 time.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment