-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.js
44 lines (34 loc) · 891 Bytes
/
data.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
/**
* Module dependencies
*/
var natural = require('natural')
var elex = require('./elex.json')
var prop = require('./prop.json')
/**
* Filter candidates data
*/
var matches = elex
.filter(function(e){ return e.first.length && e.first !== 'Other' })
.map(function(e){
var names = []
var n = e.last.toUpperCase() + ', ' + e.first.toUpperCase()
for(var i = 0; i < prop.length; i++) {
var match = natural.JaroWinklerDistance(prop[i].can_nam, n)
names.push({name: n, match: match, pname: prop[i].can_nam, fecid: prop[i].can_id, elexid: e.unique_id})
}
names.sort(function(a, b){
return b.match - a.match
})
return names[0]
})
// Order by match distance
matches.sort(function(a, b){
return a.match - b.match
})
/**
* Expose Data
*/
module.exports = {
matches: matches,
fecnames: prop.map(function(p){ return { name: p.can_nam, id: p.can_id } })
}