Parliament of Finland: unofficial API client

March 17, 2015 · View on GitHub

Parliament of Finland: unofficial API client

This R package provides tools to access Parliament of Finland data from the unofficial Kansan Muisti 2.0 API. For API documentation, check here.

Installation and usage

Installing the package (Installing the package)
Gender analysis (Estimating genders)

Available data sources and tools

The following API endpoints are currently wrapped by finpar:

DataAPI endpointFunction
Parliamentary termshttp://kansanmuisti.fi/api/v1/termterm()
Members of the Parliamenthttp://kansanmuisti.fi/api/v1/membermember()
Plenary sessionshttp://kansanmuisti.fi/api/v1/plenary_sessionplenary_session()

Installation

Install the development version:

library(devtools)
install_github("ropengov/finpar")

Load the library:

library(finpar)

Set UTF-8 encoding:

Sys.setlocale(locale="UTF-8") 

Parliament terms

All terms of the Finnish parliament in 1907-2011

all_terms <- term()
# Show the first ones in a table:
library(knitr)
kable(head(all_terms))
beginendnameid
2011-04-20NA20111
2007-03-212011-04-1920072
2003-03-192007-03-2020033
1999-03-242003-03-1819994
1995-03-241999-03-23199536
1991-03-221995-03-23199135

Get a specific term defined by ID

term_2011 <- term(id=1)  
print(term_2011)
##        begin end name id
## 1 2011-04-20  NA 2011  1

Parliament members

Get all parliament members and plot their age distribution

all_members <- member()
ages <- sapply(all_members, function (x) {x$age})
hist(ages, col = "gray", xlab = "Age", main = "Age distribution of parliament members", las = 1)

plot of chunk finparmember

Get a specific member defined by ID:

jorn_donner <- member(id=30)  

# List available variables
print(names(jorn_donner))
##  [1] "activity_days_included" "activity_score"        
##  [3] "age"                    "all_posts"             
##  [5] "birth_date"             "birth_place"           
##  [7] "district_name"          "email"                 
##  [9] "gender"                 "given_names"           
## [11] "homepage_link"          "id"                    
## [13] "info_link"              "last_checked_time"     
## [15] "last_modified_time"     "name"                  
## [17] "origin_id"              "party"                 
## [19] "party_associations"     "phone"                 
## [21] "photo"                  "posts"                 
## [23] "print_name"             "resource_uri"          
## [25] "stats"                  "summary"               
## [27] "surname"                "terms"                 
## [29] "url_name"               "wikipedia_link"
# Check age
jorn_donner$age
## [1] 82

Plenary sessions

Get all plenary sessions

all_plenary_sessions <- plenary_session()

Get a specific plenary session defined by ID

session <- plenary_session(id=30)  

# List available variables
kable(session)
idfieldelementvalue
301date2012-11-23
301info_linkhttp://www.eduskunta.fi/triphome/bin/akxptk.sh?{KEY}=PTK+116/2012+vp
301last_checked_time2013-12-01T00:00:00
301last_modified_timeNA
301name116/2012
301origin_id116/2012
301origin_version2.0
301plenary_votes/api/v1/plenary_vote/1244/
302plenary_votes/api/v1/plenary_vote/1245/
303plenary_votes/api/v1/plenary_vote/1246/
304plenary_votes/api/v1/plenary_vote/1247/
305plenary_votes/api/v1/plenary_vote/1248/
306plenary_votes/api/v1/plenary_vote/1249/
307plenary_votes/api/v1/plenary_vote/1250/
308plenary_votes/api/v1/plenary_vote/1251/
309plenary_votes/api/v1/plenary_vote/1252/
301resource_uri/api/v1/plenary_session/30/
301url_name116-2012

Genders

Use genderizeR to estimate gender for first names (note that there might be some inaccuracies in gender estimation for Finnish names):

# devtools::install_github("kalimu/genderizeR")
library(genderizeR)
## Welcome to genderizeR package version: 1.0.0.1
## 
## Changelog: news(package = 'genderizeR')
## Help & Contact: help(genderizeR)
## 
## If you find this package useful cite it please. Thank you! 
## See: citation('genderizeR')
## 
## To suppress this message use:
## suppressPackageStartupMessages(library(genderizeR))
x <- c("Sauli", "Tarja", "Mauno")
givenNames <- findGivenNames(x, progress = FALSE)
g <- genderize(x, genderDB=givenNames, blacklist=NULL, progress = FALSE)
kable(g)
textgivenNamegendergenderIndicators
Saulisaulimale1
Tarjatarjafemale1
Maunomaunomale1

R code to calculate co-sponsorship networks from bills (and motions) passed in the Finnish Parliament by François briatte

Acknowledgements

R client for the unofficial API of Parliament of Finland provided by NGO Kansan Muisti. Parliament of Finland does not provide an official API, but Kansan Muisti does provide a RESTful API to a database mostly compiled by scraping data from parliament's web page. Great work !

Licensing and Citations

This work can be freely used, modified and distributed under the MIT license.

citation("finpar")
## 
## Kindly cite the finpar R package as follows:
## 
##   (C) Joona Lehtomaki 2014-2015. finpar: R tools for Finnish
##   Parliament Data from the unofficial Kansan Muisti API. URL:
##   http://github.com/ropengov/finpar
## 
## A BibTeX entry for LaTeX users is
## 
##   @Misc{,
##     title = {finpar: R tools for Finnish Parliament Data from the unofficial Kansan Muisti API},
##     author = {Joona Lehtomaki},
##     year = {2014-2015},
##   }
## 
## Many thanks to http://kansanmuisti.fi !

Session info

This vignette was created with

sessionInfo()
## R version 3.1.2 (2014-10-31)
## Platform: x86_64-pc-linux-gnu (64-bit)
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] genderizeR_1.0.0.1 finpar_0.1.2       reshape2_1.4.1    
## [4] httr_0.6.1         knitr_1.9         
## 
## loaded via a namespace (and not attached):
##  [1] assertthat_0.1    bitops_1.0-6      chron_2.3-45     
##  [4] data.table_1.9.4  DBI_0.3.1         dplyr_0.4.1      
##  [7] evaluate_0.5.5    formatR_1.0       jsonlite_0.9.14  
## [10] lazyeval_0.1.10   magrittr_1.5      NLP_0.1-6        
## [13] parallel_3.1.2    plyr_1.8.1        R.cache_0.10.0   
## [16] Rcpp_0.11.5       RCurl_1.95-4.5    R.methodsS3_1.7.0
## [19] R.oo_1.19.0       R.utils_2.0.0     slam_0.1-32      
## [22] stringr_0.6.2     tm_0.6            tools_3.1.2