[英]filter out symmetrical lines by python
I have a graphviz file automatically generated, which sometimes produces double connections, eg 我有一个自动生成的graphviz文件,有时会生成双连接,例如
"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 1)如果可以在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! 2)或者如果你知道一种Python方法来过滤掉其中一行(我不介意丢失那些信息):或者我找不到正则表达式能够做到这一点!
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. 您还可以尝试使用concentrate=true
选项(请参阅: 点图语言 - 如何制作双向边? )以获取详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.