-
Notifications
You must be signed in to change notification settings - Fork 0
/
summary.py
executable file
·67 lines (42 loc) · 1.61 KB
/
summary.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
60
61
62
63
64
65
#!/usr/bin/env python3
import json
from loader import pathIterator2
from utils import Dict
paths = '../SemanticAnalyzer/SemanticData/Corpora/json'
# import glob
# for p in glob.glob(paths):
# print(p)
# quit()
frameStats = {}
for path in pathIterator2(paths):
if not path.endswith('.json'):
continue
print(path)
with open(path) as f:
document = json.load(f, object_hook=Dict)
for sentence in document.sentences:
if not sentence.frames:
continue
for frame in sentence.frames:
if frame.type not in frameStats:
frameStats[frame.type] = Dict(count=0, elementNames={}, targets={})
stats = frameStats[frame.type]
stats.count += 1
target = sentence.tokens[frame.tokenIndex-1].lemma
if target not in stats.targets:
stats.targets[target] = 1
else:
stats.targets[target] += 1
for element in frame.elements:
if element.name not in stats.elementNames:
stats.elementNames[element.name] = 0
stats.elementNames[element.name] += 1
with open('summary.txt', 'w') as f:
for frameType,stats in frameStats.items():
print('>>', frameType, file=f)
for target,count in stats.targets.items():
print(' ', target, '=', count, file=f)
# for frameType,stats in frameStats.items():
# print('>>', frameType, '=', stats.count, file=f)
# for elementName,count in stats.elementNames.items():
# print(' ', elementName, '=', count, file=f)