-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_fragment_for_CAMEO_conversion.txt
48 lines (41 loc) · 1.43 KB
/
code_fragment_for_CAMEO_conversion.txt
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
def init_CAMEO():
CAMEO_eventcodes = {} # conversion dictionaries
try:
fin = open("CAMEO_codefile.txt",'r')
except IOError:
print("\aError: Could not find the event code file CAMEO_codefile.txt")
exit()
caseno = 1
line = fin.readline()
while len(line) > 0:
if line.startswith('LABEL'):
part = line[line.find(' ')+1:].partition(' ')
CAMEO_eventcodes[part[2][:-1]] = part[0][:-1]
# print CAMEO_eventcodes[part[2][:-1]]
caseno += 1
# if caseno > 32: break # debugging exit
line = fin.readline()
return CAMEO_eventcodes
CAMEO_convert = init_CAMEO()
xlate = {}
for line in open("CAMEO2PLOVER-2021-09-17.txt", "r"):
if line[0] == '#':
continue
if "#" in line:
f1 = line.partition(":")
f2 = f1[2].split(",")
mode = f2[1].strip()
if not mode:
mode = "None"
context = f2[2][:f2[2].find("#")].strip()
if not context:
context = "None"
xlate[f1[0].strip()] = [f2[0].strip(), mode, context]
# Example of usage: this was processing an ICEWS file that had been converted to JSON
# where EVENT_KEY held the text of the event
if rec[EVENT_KEY] in CAMEO_convert:
camcode = CAMEO_convert[rec[EVENT_KEY]]
if camcode in xlate:
evntcode[xlate[camcode][0]] += 1
modecode[xlate[camcode][1]] += 1
cntxcode[xlate[camcode][2]] += 1