-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (55 loc) · 2.16 KB
/
index.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
'use strict'
const ParseEntities = require('@datagica/parse-entities')
const data = require('./database')
class Parser extends ParseEntities {
constructor(opts) {
super({
debug: false,
fields: ['label','aliases'],
data,
maxLength: 7,
spellings: (map, name) => {
// console.log("\nIN: "+name);
// it is about 10% faster without the regex.. maybe this is because we
// didn't compile it
// about 850ms to run the test
/*
const replaced_ = name
.replace(/universi(?:tée|dad|tat) (?:de )?(?:tech?nologica|tech?nologique|tech?nologie|tech?nologique)/gi, 'university of technology')
.replace(/universi(?:tée|dad|tat)/gi, 'university')
.replace(/university/gi, 'uni')
.replace(/ (?:a|au|aux) (?:la|le|les|los) /gi, ' at the ')
.replace(/ (?:la|le|el|les|los) /gi, ' the ')
.replace(/sme /gi, 'sm ')
.replace(/ de /gi, ' of ');
*/
// about 780ms to run the test
const replaced = name
.replace('universitée de technologie', 'university of technology')
.replace('universidad de tecnologica', 'university of technology')
.replace('technische universität', 'university of technology')
.replace('université', 'university')
.replace('universidad', 'university')
.replace('universität', 'university')
.replace(' a la ', ' at the ')
.replace(' le ', ' the ')
.replace(' la ', ' the ')
.replace(' el ', ' the ')
.replace(' les ', ' the ')
.replace(' los ', ' the ')
.replace(' los ', ' the ')
.replace(' de ', ' of ')
.replace(' de ', ' of ') // twice: on purpose
// console.log("OUT:"+replaced)
map.set(replaced, 0.67)
}
})
}
}
const singletonInstance = new Parser()
const singletonMethod = function() { return singletonInstance.parse.apply(singletonInstance, arguments) }
module.exports = singletonMethod
module.exports.default = singletonMethod
module.exports.database = data
module.exports.parser = singletonInstance
module.exports.Parser = Parser