0

I have a graphviz file automatically generated, which sometimes produces double connections, e.g.

"test textanalysis" -> "development" [color="white"];
"development" -> "test textanalysis" [color="white"];

I'd like to know

1) if it is possible to show this as a single connection with double arrows at start&end in Graphviz

2) or in alternative if you know a Python way to filter out one of those lines (I dont mind losing that information): I cannot find a regex able to do it!

alessandro
  • 3,330
  • 6
  • 37
  • 52

1 Answers1

2

You can try something like this to filter repeating edges:

import re

edges = {}

with open(dot_file) as fr:
    for line in fr:
        key = tuple(sorted(re.findall('"([a-z ]+)"', line)[:2]))
        edges.setdefault(key, []).append(line.strip())

for v in edges.values():
    if len(v) > 1:
        print re.sub("\[(.+)\]", '[\\1, dir="both"]', v[0])
    else:
        print v[0]

You can also try using concentrate=true option (See: Dot graph language - how to make bidirectional edges?) for details.

Community
  • 1
  • 1
zero323
  • 283,404
  • 79
  • 858
  • 880
  • Interesting python code - but I didnt try it: the concentrate switch which I didnt know did the trick perfectly, thank you! – alessandro Nov 06 '13 at 13:07