4
from collections import defaultdict
10
import simplejson as json
14
factoids = defaultdict(default)
16
for line in open(argv[1]):
19
match = re.match(r'^verb (.+) (\d+)$', line)
21
name, id = match.groups()
22
factoids[int(id)][0].append(name)
25
match = re.match(r'^(\d+) (action|reply) (.+)$', line)
27
id, action, value = match.groups()
28
factoids[int(id)][1].append('<%s> %s' % (action, value.replace('##', '$1')))
30
for names, values in factoids.values():
33
for index, name in enumerate(names):
34
names[index] = name + ' $arg'
37
print json.dumps(factoids.values(), indent=1)