-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatch.js
68 lines (62 loc) · 1.9 KB
/
match.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
const fetch = require('node-fetch')
const wdk = require('wikidata-sdk')
require('dotenv').config()
// const config = {
// username: process.env.WIKI_USER,
// password: process.env.WIKI_PASS,
// verbose: false
// }
// const wdEdit = require('wikidata-edit')(config)
const wikidata = require('./wikidata.json').results.bindings
const lobbywatch = require('./lobbywatch.json').data.parliamentarians
// const parlament = require('./parlament.json')
const wikidataIndex = wikidata.reduce(
(index, item) => {
const parliamentId = item.parliamentId && item.parliamentId.value
if (parliamentId) {
if (!index[parliamentId]) {
index[parliamentId] = []
}
index[parliamentId].push(item)
}
return index
},
{}
)
lobbywatch.forEach(mp => {
const wikidataMp = wikidataIndex[mp.parliamentId]
if (wikidataMp) {
// console.log('matched', mp.name, mp.id, wikidataMp[0].human.value)
} else {
fetch(wdk.searchEntities({
search: mp.name,
limit: 3
}))
.then(response => response.json())
.then(json => {
console.log('Missed', mp.name, mp.parliamentId)
if (json.success) {
// console.log('Wikidata Search', json.search.length)
// console.log(json.search)
const result = json.search[0]
if (
json.search.length === 1
) {
if (result.description === 'Swiss politician') {
console.log('- auto match', result.label, mp.name)
console.log('-', result.id, 'P1307', mp.parliamentId)
// wdEdit.claim.add(result.id, 'P1307', mp.parliamentId)
} else {
console.log('- needs manual check')
console.log('-', result)
}
} else {
console.log('- multi match')
console.log(json.search)
}
} else {
console.log('- no match')
}
})
}
})