This repository has been archived by the owner on Jul 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
256 lines (222 loc) · 6.79 KB
/
script.js
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/* Experiment on how far you can get with simple regular expressions
* all times best when guessing one or two (where appropriate) dates and times per event
correct bits % correct events % set
575/610 96% 50/61 82% enronmeetings
546/600 91% 35/60 58% mozilla.dev.planning sept set
516/600 86% 34/60 57% private et set
* latest when guessing one or two (where appropriate) dates and times per event
correct bits % correct events % set
572/610 94% 49/61 80% enronmeetings
515/600 86% 31/60 52% mozilla.dev.planning sept set
514/600 86% 34/60 57% private et set
*/
var corSum = 0;
var wrSum = 0;
var corEvents = 0;
var wrEvents = 0;
var locale = "en-US";
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
var fileCor = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
Components.utils.import("file:/media/Meedia/tty/lt/event-extract/extract.jsm");
// expecting mails in folder arguments[0] (full path with ending slash)
// answers in folder arguments[0] + "_cor"
file.initWithPath(arguments[0]);
fileCor.initWithPath(arguments[0] + "../" + file.leafName + "_cor");
if (arguments[1])
locale = arguments[1];
let baseUrl = "file:/media/Meedia/tty/lt/event-extract/patterns/extract_LOCALE.properties";
var mails = file.directoryEntries;
var ans = fileCor.directoryEntries;
var array = [];
var minTime = 99999;
var maxTime = 0;
var total = 0;
while (mails.hasMoreElements()) {
var file = mails.getNext();
var corFile = ans.getNext();
var info = readFile(file);
var answer = readFile(corFile);
dump(info.filename + " " + answer.filename + "\n");
var expected = JSON.parse(answer.contents);
var extr = new Extractor(baseUrl, locale);
var time1 = (new Date()).getTime();
var refDate = findNow(info.contents);
extr.extract(null, info.contents, refDate);
var startGuess = {};
var endGuess = {};
if (expected.to != "task") {
startGuess = extr.guessStart();
endGuess = extr.guessEnd(startGuess);
} else {
startGuess = extr.guessStart(true);
endGuess = extr.guessEnd(startGuess, true);
}
var time2 = (new Date()).getTime();
var time = time2 - time1;
total += time;
if (time < minTime)
minTime = time;
if (time > maxTime)
maxTime = time;
compare(expected, startGuess, endGuess);
dump("---------------------------------------------------------\n");
}
dump("total: " + corSum + "/" + (corSum + wrSum) + "\n");
dump("total events: " + corEvents + "/" + (corEvents + wrEvents) + "\n");
var avg = total * 1.0 / (corEvents + wrEvents);
dump("total: " + total + " minTime: " + minTime + " maxTime: " + maxTime + " avg: " + avg + "\n");
function readFile(nsiFile) {
var info = {};
nsiFile.QueryInterface(Components.interfaces.nsIFile);
info.filename = nsiFile.leafName;
info.contents = "";
var fstream = Components.classes["@mozilla.org/network/file-input-stream;1"]
.createInstance(Components.interfaces.nsIFileInputStream);
var cstream = Components.classes["@mozilla.org/intl/converter-input-stream;1"]
.createInstance(Components.interfaces.nsIConverterInputStream);
fstream.init(nsiFile, -1, 0, 0);
cstream.init(fstream, "UTF-8", 0, 0);
let (str = {}) {
cstream.readString(-1, str);
info.contents = str.value;
}
cstream.close();
return info;
}
function findNow(email) {
var now = new Date();
now.setDate(1); // else some guesses at the end of month come out wrong
// use date header
var re = /^Date:\s\w{3},\s+(\d{1,2})\s(\w{3})\s(\d{4})\s(\d{2}):(\d{1,2})/m;
var res = re.exec(email);
now.setFullYear(parseInt(res[3], 10));
switch (res[2]) {
case "Jan":
now.setMonth(0);
break;
case "Feb":
now.setMonth(1);
break;
case "Mar":
now.setMonth(2);
break;
case "Apr":
now.setMonth(3);
break;
case "May":
now.setMonth(4);
break;
case "Jun":
now.setMonth(5);
break;
case "Jul":
now.setMonth(6);
break;
case "Aug":
now.setMonth(7);
break;
case "Sep":
now.setMonth(8);
break;
case "Oct":
now.setMonth(9);
break;
case "Nov":
now.setMonth(10);
break;
case "Dec":
now.setMonth(11);
break;
}
now.setDate(parseInt(res[1], 10));
now.setHours(parseInt(res[4], 10));
now.setMinutes(parseInt(res[5], 10));
return now;
}
function compare(correct, guessed, guessedEnd) {
let r = wrSum;
if (correct.year === guessed.year ||
correct.year === undefined && guessed.year === null) {
corSum++;
} else {
dump(correct.year + " S " + guessed.year + " year\n");
wrSum++;
}
if (correct.month === guessed.month ||
correct.month === undefined && guessed.month === null) {
corSum++;
} else {
dump(correct.month + " S " + guessed.month + " month\n");
wrSum++;
}
if (correct.day === guessed.day ||
correct.day === undefined && guessed.day === null) {
corSum++;
} else {
dump(correct.day + " S " + guessed.day + " day\n");
wrSum++;
}
if (correct.hour === guessed.hour ||
correct.hour === undefined && guessed.hour === null
) {
corSum++;
} else {
dump(correct.hour + " S " + guessed.hour + " hour\n");
wrSum++;
}
if (correct.minute === guessed.minute ||
correct.minute === undefined && guessed.minute === null
) {
corSum++;
} else {
dump(correct.minute + " S " + guessed.minute + " minute\n");
wrSum++;
}
if (correct.year2 === guessedEnd.year ||
correct.year2 === undefined && guessedEnd.year === null
) {
corSum++;
} else {
dump(correct.year2 + " E " + guessedEnd.year + " year\n");
wrSum++;
}
if (correct.month2 === guessedEnd.month ||
correct.month2 === undefined && guessedEnd.month === null
) {
corSum++;
} else {
dump(correct.month2 + " E " + guessedEnd.month + " month\n");
wrSum++;
}
if (correct.day2 === guessedEnd.day ||
correct.day2 === undefined && guessedEnd.day === null
) {
corSum++;
} else {
dump(correct.day2 + " E " + guessedEnd.day + " day\n");
wrSum++;
}
if (correct.hour2 === guessedEnd.hour ||
correct.hour2 === undefined && guessedEnd.hour === null
) {
corSum++;
} else {
dump(correct.hour2 + " E " + guessedEnd.hour + " hour\n");
wrSum++;
}
if (correct.minute2 === guessedEnd.minute ||
correct.minute2 === undefined && guessedEnd.minute === null
) {
corSum++;
} else {
dump(correct.minute2 + " E " + guessedEnd.minute + " minute\n");
wrSum++;
}
if (r === wrSum) {
corEvents++;
} else {
wrEvents++;
}
}