bundesdata_markup_nlp | ||
data | ||
docs | ||
.gitignore | ||
README.md | ||
requirements.txt |
What is this?
This software is used to automatically mark the official protocols of the Bundestag. The Bundestag published protocols of every session since 1949 till 2017 in XML. Unforutnatley the markup of those is very rudimentary. It is not possible to see which member of parliament hold what speech etc.
This software can mark every protocol from 1949 till 2017 automatically. The software identifies speakers, their speeches, metadata etc. For detailed information why this software was made and how it works, read the corresponding master thises uploaded here (It is written in german though).
Besides the markup the software can also calculate ngrams for all automatically marked protocols either from lemmatized or just tokenized text with or without stopwords.
Web app based on the protocols and ngrams
The protocols and ngrams are used for differend functiosn of a django web application. The web application displays the protocols, speeches and corresponding speakers for research purposes.
The web app also provides an Ngram Viewer based on the produced ngram data that displays ngram frequencies for all protocols from 1949 till 2017. The Ngram Viewer is similar to the Google Ngram Viewer.
The source code of the web application can be found here: https://gitlab.ub.uni-bielefeld.de/sporada/bundesdata_web_app. A live version of the app is accessible from inside the University Bielefeld network by visiting http://129.70.12.88:8000/.
Input and Output data
The input and output data of this software can be found here: https://gitlab.ub.uni-bielefeld.de/sporada/bundesdata_markup_nlp_data. You can find all automatically marked protocols and ngrams there. Also the official protocols used as input data are included.
Installation and usage
requirements
- Python 3.7.1+
- Python python3.7-dev
- js-beautify (optional if corresponding step is skipped)
- virtualenv
- unix-like os
Installation
- Install the needed requirements mentioned above. Install js-beatify following one of the steps mentioned here: https://github.com/beautify-web/js-beautify#installation. Installing and using js-beautify is optional. How to skip the usage is mentioned in the section below.
- Clone this repository with
git clone https://gitlab.ub.uni-bielefeld.de/sporada/bundesdata_markup_nlp_software.git
. - Create a virtual environment for the software
virtualenv --python=python3.7 path/to/folder/of/your/choice
. - Activate the virtual environment with
source path/to/folger/bin/activate
- Navigate into the cloned repository with
cd path/to/reopsitory
. - Install all requirements mentioned in requirements.txt with
pip install -r requirements.txt
. - Move down into bundesdata_markup_nlp with
cd bundesdata_markup_nlp
. - Execute
./bundesdata_markup.py -h
orpython bundesdata_markup.py -h
to verify the successful installation. - If the help shows up you a ready to go.
Usage
Markup process
- Downlaod some protocols to use them as an input for the markup process. You can either download some files from https://gitlab.ub.uni-bielefeld.de/sporada/bundesdata_markup_nlp_data including the development_data_xml set found in inputs. Or download the protocols directly from https://www.bundestag.de/services/opendata. Only protocols from period 1 to 18 can be used as an input.
- Place the protocols you want to mark in one directory. The directory can contain one level of sub directories in example for protocols of different periods. This tutorial will continue using the folder development_data_xml.
- Now you can start the markup process by executing following command
./bundesdata_markup.py -sp /path/to/development_data_xml /path/to/some/folder/for/the/output
. - After completion the marked protocols can be found in the folder beautiful_xml inside the specified output folder.
- To skip the step that uses js-beautify execute the command
./bundesdata_markup.py -sp /path/to/development_data_xml /path/to/some/folder/for/the/output -kt -sb
- The non beautified protocols can be found in clear_speech_markup. Notice that all other tmp folders containing the intermediate protocols are also kept in the output folder. This is due to using the
-kt
parameter. - The marked protocols can now be used as an input to calculate different n-grams.
N-grams
- Before calculating the n-grams the protocols have either to be lemmatized or tokenized.
Lemmatize
- To lemmatize the protocols execute
./bundesdata_nlp.py -lm -ns -sp /path/to/output/beautiful_xml /path/to/some/folder/for/the/output
or./bundesdata_nlp.py -lm -ns -sp /path/to/clear_speech_markup /path/to/some/folder/for/the/output
if you want to use non beautified files. Notice that the parameter-ns
removes stop words from the lemmatized text. To include stopwords remove the parameter. - The lemmatized protocols can be found in nlp_output/nlp_beuatiful_xml. These protocols are also beautified using js-beautify.
- If you want to skip the beautification add the parameter
-sb
. Non beautified protocols are found in nlp_output/lemmatized.
Tokenize
- To tokenize the protocols execute
./bundesdata_nlp.py -tn -ns -sp /path/to/output/beautiful_xml /path/to/some/folder/for/the/output
or./bundesdata_nlp.py -tn -ns -sp /path/to/clear_speech_markup /path/to/some/folder/for/the/output
if you want to use non beautified files. Notice that the parameter-ns
removes stop words from the tokenized text. To include stopwords remove the parameter. - The tokenized protocols can be found in nlp_output/nlp_beuatiful_xml. These protocols are also beautified using js-beautify.
- If you want to skip the beautification add the parameter
-sb
. Non beautified protocols are found in nlp_output/lemmatized.
Calculating the n-grams
- Now the lemmatized or tokenized (either with our without stop words) protocols can be used as an input for the n-gram calculation. The following steps will be explained using the beautified protocols from nlp_beuatiful_xml.
- To calculate the n-grams for the lemmatized protocols without stop words per year use the command
./bundesdata_nlp.py -cn year lm_ns_year -sp /path/to/nlp_output/nlp_beuatiful_xml/ /path/to/some/folder/for/the/output/
- After that move a copy of bundesdata_markup_nlp/utility/move_ngrams.py into the folder nlp_output/n-grams and execute it with
python move_ngrams.py
. - The n-grams are now ready to be imported into the database of the django web app. (The source code for the app and a tutorial for importing the ngrams can be found here: https://gitlab.ub.uni-bielefeld.de/sporada/bundesdata_web_app)
- If you want to calculate n-grams from tokenized protocols without stopwords per year use this command:
./bundesdata_nlp.py -cn year tk_ns_year -sp /path/to/nlp_output/nlp_beuatiful_xml/ /path/to/some/folder/for/the/output/
. - If you want to calculate n-grams from tokenized protocols with stopwords per speaker use this command:
./bundesdata_nlp.py -cn speaker tk_ws_speaker -sp /path/to/nlp_output/nlp_beuatiful_xml/ /path/to/some/folder/for/the/output/
. - The parameter
-cn
is always followed by two arguments (Example:-cn year lm_ns_year
). The first is used to specifie how the n-grams are counted. It can be set to "year", "mont_year", "speaker" or "speech". N-grams will then be count by year, speaker and so on. The second argument is a user specified string to identify from what kind of protocols the n-grams have been calculated. The string "lm_ns_year" for example describes that the input protocols have been lemmatized (lm) and contain no stop words (ns). The last part (year) specifies that the n-grams have been calculated by year.
Used packages and software
- js-beautify: https://github.com/beautify-web/js-beautify
- Lielmanis, E.; Newman, L.; Stockman, D. & Sanfilippo, S.
- lxml: https://github.com/lxml/lxml
- Behnel, S.; Faassen, M.; Bicking, I.; Joukl, H.; Sapin, S.; Parent, M.-A.; Grisel, O.; Buchcik, K.; Wagner, F.; Kroymann, E.; Everitt, P.; Ng, V.; Kern, R.; Pakulat, A.; Sankel, D.; Kasperski, M.; da Silva, S. & Oberndörfer, P.
- Babel: https://github.com/python-babel/babel
- Ronacher, A.
- tqdm: https://github.com/tqdm/tqdm
- Yorav-Raphael, N.
- spaCy: https://github.com/explosion/spaCy
- Explosion AI
- scikit-learn: https://github.com/scikit-learn/scikit-learn
- Mueller, A.