Last active
September 11, 2024 12:05
-
-
Save unhammer/f793d118e11dbc629a55d4e85d198a3d to your computer and use it in GitHub Desktop.
awk -f cg2dot.awk < cg-output.txt > tree.dot && dot -Tpng tree.dot -o tree.png
This file contains hidden or 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/awk -f | |
BEGIN { | |
FS="^\"<|>\"" | |
print "digraph ParseTree {" | |
print "\tnode [shape=plaintext];" | |
print "\tedge [fontname=Helvetica, fontsize=10];" | |
print "" | |
} | |
/^"/{ | |
wf = $2 | |
gsub(/[<>]/, "_", wf) # "escape" html | |
s=s" "wf | |
} | |
/^\t/ { | |
dep=$0; sub(/.* #/, "", dep); sub(/ .*/, "", dep) | |
id=dep; sub(/->.*/, "", id) | |
parent=dep; sub(/.*->/, "", parent) | |
flabel=$0; sub(/.* @/, "", flabel); sub(/ .*/, "", flabel) | |
mainpos=$0; sub(/.*" +/, "", mainpos); sub(/ .*/, "", mainpos) | |
lemma=$0; sub(/^\t+"/, "", lemma); sub(/".*/, "", lemma) | |
# print $0, "\n", dep, id, parent, flabel, mainpos | |
gsub(/[<>]/, "_", flabel) | |
printf "\t\"%d\" [label=<<i>%s</i><br/><font color=\"#665544\" point-size=\"10\">%s</font><br/><font color=\"#337733\" point-size=\"10\">%s</font>>]\n", id, wf, lemma, mainpos | |
printf "\t\"%d\" -> \"%d\" [label=<<font color=\"#443399\">%s</font>>]\n", id, parent, flabel | |
} | |
END { | |
printf "\t{ rank = sink; \n\t\tLegend [shape=none, margin=0, label=<<font point-size=\"12\">%s</font>>];\n\t}\n", s | |
print "\n}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment