-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
291 lines (287 loc) · 8.33 KB
/
index.test.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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
const parse = require('./index')
test('should work on a simple university name', () => Promise.all(
[{
input: "Next year I will study at Université de Technologie de Compiègne, France",
expected: [{
"ngram": "Université de Technologie de Compiègne France",
"value": {
"id": "fr-utc",
"country": "France",
"city": "Compiègne",
"location": [
49.4155636,
2.816239
],
"label": {
"fr": "Université de Technologie de Compiègne",
"en": "University of Technologie of Compiègne, France"
},
"aliases": {
"en": [
"University of Technology of Compiègne",
"University of Technology of Compiègne",
"University of Technology of Compiegne",
"University of Technology of Compiegne",
"University of Technology of Compiègne, France",
"University of Technology of Compiègne France",
"University of Technology of Compiegne, France",
"University of Technology of Compiegne France"
],
"fr": [
"UTC, France",
"UTC, Compiègne",
"UTC, Compiègne, France",
"UTC Compiègne",
"UTC de Compiègne",
"UTC à Compiègne",
"UTC Compiegne",
"UTC, Compiegne",
"UTC de Compiegne",
"UTC a Compiegne",
"Université de Technologie de Compiègne",
"Université de Technologie de Compiègne",
"Université de Technologie de Compiegne",
"Université de Technologie de Compiegne",
"Université de Technologie de Compiègne, France",
"Université de Technologie de Compiègne France",
"Université de Technologie de Compiegne, France",
"Université de Technologie de Compiegne France"
]
},
"programs": [
"Computer Engineering"
]
},
"score": 1,
"position": {
"sentence": 0,
"word": 6,
"begin": 26,
"end": 72
}
}]
},
{
input: "Omggg I've been accepted to Harvard so happy!!! 👩💼 👩⚖️",
expected: [{
"ngram": "Harvard",
"value": {
"id": "us-ma-cambridge-harvard",
"country": "United States",
"state": "Massachusetts",
"city": "Cambridge",
"location": [
42.374444, -71.116944
],
"acceptance_rate": [{
"year": 2016,
"value": 5.4
}],
"students": [{
"year": 2014,
"value": 21000
}],
"label": {
"en": "Harvard University"
},
"aliases": {
"en": [
"Harvard",
"Harvard College",
"Harvard Uni",
"Harvard Uni Cambridge",
"Harvard Univ",
"Harvard Univ Cambridge",
"Harvard University",
"Harvard University Cambridge",
"Harvard University, Cambridge",
"Harvard Cambridge"
]
},
"type": "private university",
"programs": []
},
"score": 1,
"position": {
"sentence": 0,
"word": 5,
"begin": 28,
"end": 35
}
}]
},
{
input: "The professional video game player is a MIT drop-out, he founded is first startup at 7 years old",
expected: [{
"ngram": "MIT",
"value": {
"id": "us-ma-cambridge-mit",
"country": "United States",
"state": "Massachusetts",
"city": "Cambridge",
"location": [
42.35982, -71.09211
],
"acceptance_rate": [{
"year": 2015,
"value": 32
}],
"students": [{
"year": 2015,
"value": 11319
}],
"label": {
"en": "Massachusetts Institute of Technology"
},
"aliases": {
"en": [
"Massachusetts Institute of Technology",
"MIT",
"MIT, Cambridge"
]
},
"type": "private research university",
"programs": []
},
"score": 1,
"position": {
"sentence": 0,
"word": 7,
"begin": 40,
"end": 43
}
}]
}
].map(async ({
input,
expected
}) => expect(await parse(input)).toEqual(expected))
))
test('should work on an unexpected university spelling', () => Promise.all(
[{ // spanish
input: "el año que viene voy a trabajar a la universidad de tecnologica de Compiègne",
expected: [{
"ngram": "universidad de tecnologica de Compiègne",
"value": {
"id": "fr-utc",
"country": "France",
"city": "Compiègne",
"location": [
49.4155636,
2.816239
],
"label": {
"fr": "Université de Technologie de Compiègne",
"en": "University of Technologie of Compiègne, France"
},
"aliases": {
"en": [
"University of Technology of Compiègne",
"University of Technology of Compiègne",
"University of Technology of Compiegne",
"University of Technology of Compiegne",
"University of Technology of Compiègne, France",
"University of Technology of Compiègne France",
"University of Technology of Compiegne, France",
"University of Technology of Compiegne France"
],
"fr": [
"UTC, France",
"UTC, Compiègne",
"UTC, Compiègne, France",
"UTC Compiègne",
"UTC de Compiègne",
"UTC à Compiègne",
"UTC Compiegne",
"UTC, Compiegne",
"UTC de Compiegne",
"UTC a Compiegne",
"Université de Technologie de Compiègne",
"Université de Technologie de Compiègne",
"Université de Technologie de Compiegne",
"Université de Technologie de Compiegne",
"Université de Technologie de Compiègne, France",
"Université de Technologie de Compiègne France",
"Université de Technologie de Compiegne, France",
"Université de Technologie de Compiegne France"
]
},
"programs": [
"Computer Engineering"
]
},
"score": 0.67,
"position": {
"sentence": 0,
"word": 9,
"begin": 37,
"end": 76
}
}]
}].map(async ({
input,
expected
}) => expect(await parse(input)).toEqual(expected))
))
test('return empty list if there is no match', () => Promise.all(
[{
input: ` `,
expected: []
}].map(async ({
input,
expected
}) => expect(await parse(input)).toEqual(expected))
))
test('should match long university names', () => Promise.all(
[{
input: `
1901-1902 Tokyo University.
1979-1982 Hong Kong University of Science and Technology
`,
expected: [{
"ngram": "Tokyo University",
"value": {
"country": "japan",
"label": "Tokyo University",
"aliases": [],
"programs": [
"Computer Engineering"
]
},
"score": 1,
"position": {
"sentence": 0,
"word": 7,
"begin": 16,
"end": 32
}
},
{
"ngram": "Hong Kong University of Science and Technology",
"value": {
"id": "hk-university-of-science-and-technology",
"country": "hong kong",
"label": {
"en": "The Hong Kong University of Science and Technology"
},
"aliases": {
"en": "Hong Kong University of Science and Technology"
},
"programs": [
"Computer Engineering"
]
},
"score": 1,
"position": {
"sentence": 1,
"word": 1,
"begin": 49,
"end": 95
}
}
]
}].map(async ({
input,
expected
}) => expect(await parse(input)).toEqual(expected))
))