This repository has been archived by the owner on Nov 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
events.py
executable file
·59 lines (48 loc) · 1.68 KB
/
events.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import collections
import sys
from laf.fabric import LafFabric
processor = LafFabric(verbose='DETAIL')
API = processor.load('bhs3.txt.hdr', '--', 'events',
{
"xmlids": {"node": False, "edge": False},
"features": ("otype", ""),
'primary': True,
}
)
NE = API['NE']
F = API['F']
msg = API['msg']
outfile = API['outfile']
close = API['close']
mode = sys.argv[1] if len(sys.argv) > 1 else '1'
if mode not in ['1', '2']:
mode = '1'
msg("Doing mode {}".format(mode))
'''Crude visualization of the embedding structure of nodes based on node events. '''
out = outfile("output-{}.txt".format(mode))
if mode == '1':
level = 0
for (anchor, events) in NE():
for (node, kind) in events:
otype = F.otype.v(node)
event_rep = ''
if kind == 0:
event_rep = "{}({}[{}]\n".format("\t"*level, otype, node)
level += 1
elif kind == 3:
level -= 1
event_rep = "{}{}[{}])\n".format("\t"*level, otype, node)
elif kind == 1:
event_rep = "{}«{}[{}]\n".format("\t"*level, otype, node)
level += 1
elif kind == 2:
level -= 1
event_rep = "{}{}[{}]»\n".format("\t"*level, otype, node)
out.write(event_rep)
elif mode == '2':
for (anchor, events) in NE():
for (node, kind) in events:
kindr = '(' if kind == 0 else '«' if kind == 1 else '»' if kind == 2 else ')'
otype = F.otype.v(node)
out.write("{} {:>7}: {:<10} {:<7}\n".format(kindr, anchor, otype, node))
close()