-
Notifications
You must be signed in to change notification settings - Fork 0
/
produce_enwiki_titles.py
executable file
·44 lines (37 loc) · 1.18 KB
/
produce_enwiki_titles.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Autore: Cristian Consonni <[email protected]>
# Inspired by this gist by atomotic:
# https://gist.github.com/atomotic/7229203
#
# The code is released with an MIT license
# please see the LICENSE file for details.
import csv
import pickle
INFILE = 'resolv.map'
PICKLE_FILE = 'resolv.map.pkl'
FIELDNAMES_RESOLVMAP = ('wikidata', 'thes_id', 'itwiki', 'enwiki')
if __name__ == '__main__':
try:
with open(INFILE, 'r') as infile:
resolvmap = csv.DictReader(
filter(lambda row: row[0]!='#', infile),
FIELDNAMES_RESOLVMAP,
quotechar='"',
delimiter=',',
dialect=csv.QUOTE_ALL
)
enwiki_titles = {
r['enwiki'].strip().strip('"'): r
for r in resolvmap
}
except IOError as e:
print "Could not open file: {}".format(INFILE)
print "make sure to call:"
print "* make get"
print "* make resolve"
print "Before calling make match"
exit(-1)
with open(PICKLE_FILE, 'w') as outfile:
pickle.dump(enwiki_titles, outfile)