-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata-ch.r
475 lines (338 loc) · 19.8 KB
/
data-ch.r
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
#
# scrape full MP listing
#
if (!file.exists("data/sponsors-ch.csv")) {
deputes = data.frame()
for (i in 48:54) {
cat("Parsing MPs in legislature", i, "... ")
h = htmlParse(paste0("http://www.lachambre.be/kvvcr/showpage.cfm?section=/depute&language=fr&rightmenu=right_depute&cfm=cvlist54.cfm?legis=", i, "&today=n"))
h = xpathSApply(h, "//a[contains(@href, 'key=')]/@href")
cat(length(h), "pages\n")
for (j in h) {
hh = htmlParse(paste0("http://www.lachambre.be/kvvcr/", j))
hh = data.frame(legislature = i,
nom = str_clean(xpathSApply(hh, "//form[@id='myform']/center/h2", xmlValue)),
mandate = paste0(xpathSApply(hh, "//div[@id='section']/*/a[contains(@href, 'lactivity=')]", xmlValue), collapse = ";"),
photo = xpathSApply(hh, "//img[contains(@src, 'cv/')]/@src"),
url = j,
bio = xpathSApply(hh, "//table[2]/tr[@valign='top'][2]/td/p", xmlValue))
deputes = rbind(deputes, hh)
cat(".")
}
cat("\n")
}
write.csv(deputes, "data/sponsors-ch.csv", row.names = FALSE)
}
deputes = read.csv("data/sponsors-ch.csv", stringsAsFactors = FALSE)
# download photos
for (i in unique(deputes$photo)) {
photo = gsub("/site/wwwroot/images/cv", "photos_ch", i)
if (!file.exists(photo)) {
h = GET(paste0("http://www.lachambre.be", i))
if (h$status_code == 200)
writeLines(content(h, "text"), photo)
}
if (file.exists(photo)) {
deputes$photo[ deputes$photo == i ] = photo
} else {
deputes$photo[ deputes$photo == i ] = NA
}
}
deputes$bio = str_clean(gsub("▀ ", "", deputes$bio))
# biographies that failed to scrape properly
deputes$bio[ deputes$url == "showpage.cfm?section=/depute&language=fr&rightmenu=right_depute&cfm=cvview54.cfm?key=06536&lactivity=54" ] = "Député socialiste (PS) de la circonscription électorale du Brabant wallon depuis le 30 juillet 2014, en remplacement de monsieur André Flahaut, élu ministre du gouvernement de la Communauté française. Membre du groupe PS. Né à Mons le 10 juillet 1967."
deputes$bio[ deputes$url == "showpage.cfm?section=/depute&language=fr&rightmenu=right_depute&cfm=cvview54.cfm?key=00951&lactivity=54" ] = "Député démocrate Humaniste (cdH) de la circonscription électorale de Bruxelles-Capitale depuis le 30 juillet 2014, en remplacement de madame Céline Fremault, élue membre du gouvernement de la Région de Bruxelles-Capitale. Député de la circonscription électorale de Bruxelles-Hal-Vilvorde du 20 mars 2008 au 13 juin 2010, du 7 décembre 2011 au 16 mai 2013 et du 16 mai 2013 au 25 mai 2014. Membre du groupe cdH. Né à Fataki (Congo belge) le 17 janvier 1958. Sénateur du 13 juin 1999 au 18 mai 2003 et du 12 juillet 2007 au 20 mars 2008. Docteur en médecine, chirurgie et accouchements. Spécialisation en médecine tropicale. Certificat d'épidémiologie et de biostatistique. Maîtrise en politique internationale. Maîtrise en management des institutions de soins de santé. Ancien directeur général de 'Handicap International'. Ancien directeur général adjoint de Médecins sans Frontières. Vice-président de l'Hôpital Brugman. Président du comité de gestion du Fonds des maladies professionnelles. Ancien conseiller communal de Bruxelles. Ancien échevin de Bruxelles. Conseiller communal de Woluwe-Saint-Pierre. Chevalier de l'Ordre de Léopold. Président de la commission des Naturalisations."
deputes$bio[ deputes$url == "showpage.cfm?section=/depute&language=fr&rightmenu=right_depute&cfm=cvview54.cfm?key=04491&lactivity=54" ] = "Député libéral (Open Vld) de la circonscription électorale d Anvers du 7 décembre 2011 au 25 mai 2014 et depuis le 30 juillet 2014, en remplacement de madame Annemie Turtelboom, élue ministre du gouvernement flamand le 25 juillet 2014. Député de la circonscription électorale d'Anvers du 7 décembre 2011 au 25 mai 2014. Membre du groupe Open Vld. Né à Turnhout le 25 avril 1965. Licencié en sciences économiques appliquées. Chef d'entreprise. Ancien conseiller provincial (Anvers) Bourgmestre de Merksplas."
# constituencies (simplified to province due to changing nature over elections)
y = gsub("(.*)\\d+?(.*)", "\\1", deputes$bio)
y = gsub("(.*)(arrondissement|arrondsissement|circonscription( électoral)?(e)?|kieskring)", "", y)
y = gsub("^\\s(d\\s|d'|d\u0092|de\\s|du\\s|de\\sla\\s)+", "", y)
y = gsub("\\s(depuis|sedert)(.*)|\\sdu\\s$|\\s\\(PS\\)", "", y)
y = str_trim(gsub("\\s-\\s", "-", y))
# fill in a few values that are not captured by the code above
y[ deputes$url == "showpage.cfm?section=/depute&language=fr&rightmenu=right_depute&cfm=cvview54.cfm?key=00632&lactivity=48" ] = "Termonde"
y[ deputes$url == "showpage.cfm?section=/depute&language=fr&rightmenu=right_depute&cfm=cvview54.cfm?key=00106&lactivity=51" ] = "Bruxelles-Hal-Vilvorde"
# ==============================================================================
# CHECK CONSTITUENCIES
# ==============================================================================
# Province_du_Brabant_flamand
y[ y %in% c("Brabant flamand") ] = "Province_du_Brabant_flamand"
y[ y %in% c("Bruxelles", "Bruxelles-Capitale") ] = "Province_du_Brabant_flamand" # "Bruxelles"
y[ y %in% c("Bruxelles-Hal-Vilvorde", "Bruxelles-Halle-Vilvorde") ] = "Province_du_Brabant_flamand" # "Bruxelles-Hal-Vilvorde"
y[ y %in% c("Louvain") ] = "Province_du_Brabant_flamand" # "Louvain"
# Province_du_Brabant_wallon
y[ y %in% c("Brabant wallon", "Brabant-wallon") ] = "Province_du_Brabant_wallon"
y[ y %in% c("Nivelles") ] = "Province_du_Brabant_wallon"
# Province_de_Flandre-Occidentale
y[ y %in% c("Flandre occidentale", "Flandre Occidentale") ] = "Province_de_Flandre-Occidentale"
y[ y %in% c("Courtrai", "Courtrai-Roulers-Tielt", "Roulers-Tielt") ] = "Province_de_Flandre-Occidentale"
y[ y %in% c("Furnes-Dixmude-Ostende", "Furnes-Dixmude-Ypres-Ostende", "Ypres") ] = "Province_de_Flandre-Occidentale"
y[ y %in% c("Bruges") ] = "Province_de_Flandre-Occidentale"
# Province_de_Flandre-Orientale
y[ y %in% c("Flandre orientale") ] = "Province_de_Flandre-Orientale"
y[ y %in% c("Gand-Eeklo") ] = "Province_de_Flandre-Orientale"
y[ y %in% c("Saint-Nicolas", "Saint-Nicolas-Termonde", "Termonde") ] = "Province_de_Flandre-Orientale"
y[ y %in% c("Alost", "Alost-Audenarde", "Audenarde") ] = "Province_de_Flandre-Orientale"
# Province_de_Hainaut
y[ y %in% c("Hainaut", "Henegouwen") ] = "Province_de_Hainaut"
y[ y %in% c("Charleroi", "Charleroi-Thuin", "Thuin") ] = "Province_de_Hainaut"
y[ y %in% c("Mons", "Mons-Soignies", "Soignies") ] = "Province_de_Hainaut"
y[ y %in% c("Tournai-Ath-Mouscron", "Ath-Tournai-Mouscron") ] = "Province_de_Hainaut"
# Province_d'Anvers
y[ y %in% c("Anvers") ] = "Province_d'Anvers"
y[ y %in% c("Malines", "Malines-Turnhout", "Turnhout") ] = "Province_d'Anvers"
# Province_de_Liège
y[ y %in% c("Liège") ] = "Province_de_Liège"
y[ y %in% c("Verviers") ] = "Province_de_Liège"
y[ y %in% c("Huy-Waremme") ] = "Province_de_Liège"
# Province_de_Limbourg
y[ y %in% c("Hasselt", "Hasselt-Tongres- Maaseik", "Hasselt-Tongres-Maaseik", "Tongres-Maaseik") ] = "Province_de_Limbourg"
y[ y %in% c("Limbourg", "Limburg") ] = "Province_de_Limbourg"
# Province_de_Luxembourg
y[ y %in% c("Arlon-Marche-en-Famenne-Bastogne", "Arlon-Marche-en-Famenne-Bastogne-Neufchâteau-Virton", "Neufchâteau-Virton") ] = "Province_de_Luxembourg"
y[ y %in% c("Luxembourg") ] = "Province_de_Luxembourg"
# Province_de_Namur
y[ y %in% c("Namur", "Namur-Dinant-Philippeville", "Dinant-Philippeville") ] = "Province_de_Namur"
table(y[ !grepl("_", y)], exclude = NULL)
deputes$constituency = y
cat("Checking constituencies,", sum(is.na(deputes$constituency)), "missing...\n")
for (i in na.omit(unique(deputes$constituency))) {
g = GET(paste0("https://", meta[ "lang" ], ".wikipedia.org/wiki/", i))
if (status_code(g) != 200)
cat("Missing Wikipedia entry:", i, "\n")
g = xpathSApply(htmlParse(g), "//title", xmlValue)
g = gsub("(.*) — Wikipédia(.*)", "\\1", g)
if (gsub("\\s", "_", g) != i)
cat("Discrepancy:", g, "(WP) !=", i ,"(data)\n")
}
deputes$sexe = str_extract(deputes$bio, "Député(e)?")
deputes$sexe[ deputes$nom == "Juliette Boulet" ] = "Députée" # Flemish text
deputes$sexe[ deputes$nom == "Paul Meeus" ] = "Député" # typo
deputes$sexe[ deputes$sexe == "Députée" ] = "F"
deputes$sexe[ deputes$sexe == "Député" ] = "M"
# mandate years (rough approximation)
#deputes$from = as.numeric(sapply(str_extract_all(deputes$mandate, "[0-9]{4}"), min))
#deputes$to = as.numeric(sapply(str_extract_all(deputes$mandate, "[0-9]{4}"), max))
#deputes$nyears = deputes$to - deputes$from + 1
# mandate years (detailed)
deputes$mandate = sapply(deputes$mandate, function(x) {
x = as.numeric(unlist(str_extract_all(x, "[0-9]{4}")))
paste0(seq(min(x), max(x)), collapse = ";")
})
deputes$annee_naissance = str_extract(deputes$bio,
"(N|n)é(e)? (a|à|te) (\\w|,|\\.|'|-|\\(|\\)|\\s)+ le \\d+(er)? \\w+ \\d{4}")
deputes$annee_naissance = as.numeric(str_extract(deputes$annee_naissance, "[0-9]{4}"))
deputes$annee_naissance[ deputes$nom == "Juliette Boulet" ] = 1981 # Flemish text
deputes$annee_naissance[ deputes$nom == "Magda Raemaekers" ] = 1947 # Wikipedia additions
deputes$annee_naissance[ deputes$nom == "Frédéric Daerden" ] = 1970
deputes$annee_naissance[ deputes$nom == "Georges Dallemagne" ] = 1958
deputes$annee_naissance[ deputes$nom == "Frank Wilrycx" ] = 1965
deputes$annee_naissance[ deputes$nom == "Koen Metsu" ] = 1981
deputes$annee_naissance = as.integer(deputes$annee_naissance)
# full URL
deputes$url = paste0("http://www.lachambre.be/kvvcr/", deputes$url)
# ============================================================================
# QUALITY CONTROL
# ============================================================================
# - might be missing: born (int of length 4), constituency (chr),
# photo (chr, folder/file.ext)
# - never missing: sex (chr, F/M), nyears (int), url (chr, URL),
# party (chr, mapped to colors)
cat("Missing", sum(is.na(deputes$annee_naissance)), "years of birth\n")
stopifnot(is.integer(deputes$annee_naissance) &
nchar(deputes$annee_naissance) == 4 | is.na(deputes$annee_naissance))
cat("Missing", sum(is.na(deputes$constituency)), "constituencies\n")
stopifnot(is.character(deputes$constituency))
cat("Missing", sum(is.na(deputes$photo)), "photos\n")
stopifnot(is.character(deputes$photo) &
grepl("^photos(_\\w{2})?/(.*)\\.\\w{3}", deputes$photo) | is.na(deputes$photo))
stopifnot(!is.na(deputes$sexe) & deputes$sexe %in% c("F", "M"))
# stopifnot(!is.na(deputes$nyears) & is.integer(deputes$nyears)) ## computed on the fly
stopifnot(!is.na(deputes$url) & grepl("^http(s)?://(.*)", deputes$url))
stopifnot(deputes$party %in% names(colors))
#
# scrape dossiers in legislatures 47-54
#
root = "http://www.dekamer.be/kvvcr/showpage.cfm?section=/flwb&language=fr&cfm=Listdocument.cfm?legislat="
cat("Scraping raw lower chamber data...\n")
for (i in 47:54) {
file = paste0("data/dossiers-ch", i, ".csv")
if (!file.exists(file)) {
cat("Scraping legislature", i, "... ")
dossiers = data.frame()
h = htmlParse(paste0(root, i))
h = xpathSApply(h, "//a[@class='link']/@href")
cat(length(h), "pages\n")
for (j in h) {
hh = htmlParse(paste0("http://www.dekamer.be/kvvcr/", j))
hh = xpathSApply(hh, "//div[@class='linklist_0']/a/@href")
hh = gsub("(.*)&dossierID=(.*)", "\\2", as.character(hh))
cat("Page", sprintf("%3.0f", which(h == j)),
"scraping", sprintf("%3.0f", length(hh)), "dossiers\n")
for (k in hh) {
t = paste0("http://www.dekamer.be/kvvcr/showpage.cfm?section=flwb&language=fr&leftmenu=none&cfm=/site/wwwcfm/search/fiche.cfm?ID=", i, "K", k, "&db=FLWB&legislat=", i)
t = try(readHTMLTable(t, which = 1, header = FALSE, stringsAsFactors = FALSE))
if (!"try-error" %in% class(t)) {
names(t) = c("variable", "value")
t$variable = str_clean(t$variable)
t$value = str_clean(t$value)
t = data.frame(legislature = i, dossier = k,
t[ t$variable != "" | !is.na(t$value), ])
dossiers = rbind(dossiers, t)
} else {
cat("Error: dossier", k, "legislature", i, "\n")
}
}
}
write.csv(dossiers, file, row.names = FALSE)
cat("Scraped", nrow(dossiers), "rows over",
n_distinct(dossiers$dossier), "dossiers\n")
}
}
# parse sponsors from raw dossiers
dir = dir("data", pattern = "dossiers-ch\\d{2}.csv", full.names = TRUE)
for (k in dir) {
file = gsub("dossiers", "sponsors", k)
if (!file.exists(file)) {
cat("\nParsing Chamber, legislature", gsub("\\D", "", k), "...\n")
cat("Building", file)
d = read.csv(k, stringsAsFactors = FALSE)
d$uid = paste0(d$legislature, "K", sprintf("%04.0f", d$dossier))
uids = unique(d$uid)
authors = data.frame()
cat(" :", length(uids), "dossiers\n")
# sink(gsub("csv$", "log", file))
for (i in uids) {
dd = subset(d, uid == i & !grepl("^NL|NL$", d$variable))
# cat("Parsing dossier", i)
status = dd$value[which(grepl("Etat d'avancement", dd$variable)) + 1]
if (!length(status))
status = NA
topic = unique(dd$value[which(grepl("Eurovoc", dd$variable)) + 2])
topic = paste0(topic, collapse = ",")
sd = which(dd$variable == "Document principal")
dd = dd[ min(sd):nrow(dd), ]
sd = c(1, which(dd$variable == "Document(s) suivant(s)"))
if (length(sd) < 2)
sd = c(sd, nrow(dd))
for (n in 1:(length(sd) - 1)) {
ddd = dd[ sd[ n ]:sd[ n + 1 ], ]
type = ddd$value[ which(ddd$variable == "Type")[1] + 1 ]
au = which(ddd$value == "AUTEUR")
if (length(au)) {
au = sapply(au, function(x)
paste(ddd$value[ x + 2 ], ddd$value[ x + 1 ], "[", ddd$value[ x + 3 ], "]"))
au = unique(au)
} else {
au = NA
}
cs = which(ddd$value == "SIGNATAIRE")
if (length(cs)) {
cs = sapply(cs, function(x)
paste(ddd$value[ x + 2 ], ddd$value[ x + 1 ], "[", ddd$value[ x + 3 ], "]"))
cs = unique(cs)
} else {
cs = NA
}
a = na.omit(c(au, cs))
a = a[ !grepl("ZZZ|0", a) ]
# subset to cosponsored legislation
if (length(a) > 1) {
# cat("\n -", type, ":", length(au), "author(s)",
# ifelse(!length(na.omit(cs)), "",
# paste(length(na.omit(cs)), "cosponsor(s)")))
authors = rbind(authors,
cbind(uid = paste0(i, "-", n),
dossier = i, document = n,
type, topic, status,
n_au = length(a),
authors = paste0(na.omit(au[ !grepl("ZZZ|0", au) ]), collapse = ";"),
cosponsors = paste0(na.omit(cs[ !grepl("ZZZ|0", cs) ]), collapse = ";")))
} else if (length(a) == 1) {
# cat("\n -", type, ":", a)
authors = rbind(authors,
cbind(uid = paste0(i, "-", n),
dossier = i, document = n,
type, topic, status, n_au = 1,
authors = a,
cosponsors = ""))
} else {
# cat("\n -", type, ":", gsub("\\d|\\[|\\]|ZZZ|\\s", "", au))
}
}
# cat("\n\n")
}
# sink()
write.csv(authors, file, row.names = FALSE)
}
}
b = bind_rows(lapply(dir("data", pattern = "sponsors-ch", full.names = TRUE),
read.csv, stringsAsFactors = FALSE))
b$legislature = substr(b$uid, 1, 2)
b$n_a = b$n_au # total
b$n_au = 1 + str_count(b$authors, ";")
b$n_au[ is.na(b$authors) ] = NA
b$n_co = 1 + str_count(b$cosponsors, ";")
b$n_co[ b$cosponsors == "" ] = 0
b$n_co[ is.na(b$cosponsors) ] = 0
b = subset(b, authors != "") # removes only one row -- dossier 52K1939 [ 52 ]
b$type[ grepl("AMENDEMENT|DECISION DE NE PAS AMENDER", b$type) ] = "AMENDEMENT"
b$type[ grepl("ADDENDUM|AVIS|BUDGET|CORRIGE|CONCLUSIONS|DECISION|ERRATA|PROJET|RAPPORT|ANNEXE|TEXTE", b$type) ] = "AUTRE"
b$type[ grepl("PROPOSITION DE LOI", b$type) ] = "PROPOSITION DE LOI"
b$type[ grepl("PROPOSITION", b$type) & !grepl("PROPOSITION DE LOI", b$type) ] = "PROPOSITION"
# print(table(b$type, b$legislature, exclude = NULL))
b$status[ grepl("ADOPTE|TERMINE", b$status) ] = "ADOPTE"
b$status[ grepl("CADUQUE|REJETE", b$status) ] = "REJETE"
b$status[ grepl("SANS OBJET|RETIRE", b$status) ] = NA
# print(table(b$type, b$status, exclude = NULL))
# join authors and cosponsors
b$sponsors = paste(b$authors, b$cosponsors, sep = ";")
b$sponsors = gsub(";(NA)?$", "", b$sponsors)
#
# name and party fixes
#
# Sabien (Lahaye-)Battheu [ 51-54 ]
b$sponsors = gsub("Sabien Battheu", "Sabien Lahaye-Battheu", b$sponsors)
b$sponsors = gsub("Karine Jiroflée", "Karin Jiroflée", b$sponsors)
# Emile Coulonvaux, PLP [ 47 ]
b$sponsors = gsub("\\[ PLP \\]", "[ PVV ]", b$sponsors)
# Jan Decorte INDEP/ROSSEM [ 48 ]
b$sponsors = gsub("Jan Decorte \\[ INDEP \\]", "Jan Decorte [ ROSSEM ]", b$sponsors)
# Arthur Honoré Buysse, libéral flamand [ 49-50 ]
b$sponsors = gsub("\\[ LIB \\]", "[ PVV ]", b$sponsors)
# party code fixes [53]
b$sponsors = gsub("Els Van Hoof \\[ 0 \\]", "Els Van Hoof [ CD&V - N-VA ]", b$sponsors)
b$sponsors = gsub("Stefaan De Clercq \\[ 0 \\]", "Stefaan De Clercq [ CD&V ]", b$sponsors)
b$sponsors = gsub("Myriam Delacroix-Rolin \\[ 0 \\]", "Myriam Delacroix-Rolin [ cdH ]", b$sponsors)
b$sponsors = gsub("Fatma Pehlivan \\[ 0 \\]", "Fatma Pehlivan [ sp.a ]", b$sponsors)
#
# party simplifications
#
b$sponsors = gsub("\\[ Groen(!)? \\]", "[ ECOLO ]", b$sponsors)
b$sponsors = gsub("\\[ (Agalev-)?(ECOLO|Ecolo)(-Groen)?(!)? \\]", "[ ECOLO ]", b$sponsors)
# b$sponsors = gsub("\\[ (PS|SP|sp.a)(-spirit)?(\\+Vl\\.Pro)? \\]", "[ SOC ]", b$sponsors)
b$sponsors = gsub("\\[ PS \\]", "[ SOC-F ]", b$sponsors)
b$sponsors = gsub("\\[ (SP|sp.a)(-spirit)?(\\+Vl\\.Pro)? \\]", "[ SOC-V ]", b$sponsors)
b$sponsors = gsub("\\[ (PVV|Open Vld|VLD) \\]", "[ LIB-V ]", b$sponsors)
b$sponsors = gsub("\\[ (MR|FDF|PRL|FDFPPW|PRLFDF) \\]", "[ LIB-F ]", b$sponsors)
b$sponsors = gsub("\\[ (VU|VU-ID|N-VA) \\]", "[ VOLKS ]", b$sponsors)
b$sponsors = gsub("\\[ (CVP|CD&V) \\]", "[ CDEM-V ]", b$sponsors)
b$sponsors = gsub("\\[ (PSC|cdH) \\]", "[ CDEM-F ]", b$sponsors)
b$sponsors = gsub("\\[ CD&V - N-VA \\]", "[ CDEM-V/VOLKS ]", b$sponsors)
b$sponsors = gsub("\\[ VB \\]", "[ VLAAMS ]", b$sponsors)
b$sponsors = gsub("\\[ PTB-GO! \\]", "[ PT ]", b$sponsors)
b$sponsors = gsub("\\[ MLD \\]", "[ DLB ]", b$sponsors) # Laurent Louis, always alone
b$sponsors = gsub("\\[ (ONAFH|INDEP|INDEP-ONAFH) \\]", "[ IND ]", b$sponsors)
# last fixes on duplicates (leave at end)
b$sponsors = gsub("Lisette Nelis-Van Liedekerke \\[ LIB-V \\]",
"Lisette Nelis-Van Liedekerke [ CDEM-V ]", b$sponsors) # l. 48
b$sponsors = gsub("Philippe Dallons \\[ SOC-F \\]", "Philippe Dallons [ ECOLO ]", b$sponsors) # l. 49
b$sponsors = gsub("Pierrette Cahay-André \\[ LIB-F \\]", "Pierrette Cahay-André [ CDEM-F ]", b$sponsors) # l. 49
b$sponsors = gsub("Richard Fournaux \\[ CDEM-F \\]", "Richard Fournaux [ LIB-F ]", b$sponsors) # l. 51
b$sponsors = gsub("Vincent Decroly \\[ IND \\]", "Vincent Decroly [ ECOLO ]", b$sponsors) # l. 50
# note: fixes do not cover sponsors from legislature 47,
# for which there is no sponsor details (age, sex, etc.)
## all keywords
# kw = unlist(strsplit(b$topic, ","))
# table(kw)[ table(kw) > 600 ]
write.csv(b, "data/bills-ch.csv", row.names = FALSE)