Skip to content

Instantly share code, notes, and snippets.

@draplater
Last active August 7, 2018 04:32
Show Gist options
  • Save draplater/07d18e6718c22b4a85f9ebb98ac9f881 to your computer and use it in GitHub Desktop.
Save draplater/07d18e6718c22b4a85f9ebb98ac9f881 to your computer and use it in GitHub Desktop.
Draw EDS
import gzip
import re
from hrgguru.hyper_graph import HyperGraph
from delphin.mrs import eds
file_name = "/home/chenyufei/Development/large-data/deepbank1.1/export/wsj07c/20758069.gz"
with gzip.open(file_name, "rt") as f:
export_contents = f.read()
fields = export_contents.strip().split("\n\n")
eds_literal = fields[-2]
eds_literal = re.sub("\{.*\}", "", eds_literal)
e = eds.loads_one(eds_literal)
hg = HyperGraph.from_eds(e)
# 方法1:直接画到文件,需要安装graphviz
hg.draw("/tmp/abcdef", file_format="pdf")
# 方法2:生成dot源代码,粘贴到http://viz-js.com/在线画图
print(hg.draw("", file_format="source"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment