Originally from Accountability Hack 2014 [UK Parliament, National Audit Office, ONS]
It's a set of dirty scripts that power http://parli-n-grams.puntofisso.net until I manage to write something better.
Feel free to use it, but it really needs a rewrite using better tech.