Creating a Corpus Data Package: Wrapping Europarl

Andreas Blätte (andreas.blaette@uni-due.de)

2019-12-09

Creating the ‘europarl’

The European Parliament Proceedings Parallel Corpus 1996-2011, known as Europarl is a classical resource in the CWB community for demonstration purposes. It is a resource valuable in itself. So we will be happy in the following example to use the CWB version of Europarl as an example how to wrap a CWB indexed corpus into a R data package.

Preparations

The example keeps the number of dependencies to a minimum, so we only need to load the cwbtools package.

## Loading required package: usethis

The procedure will be as follow:

We then conclude the example by running a simple test whether the corpora can be used.

For the steps 1 through 5, we use a temporary directory. One precaution in advance: The files that will be downloaded are large (~ 2 GB). So it will be important to remove the temporary data at the end.

And because the whole operation is too much for an ordinary process to build R packages, we set an argument whether all the code is executed to FALSE.

Downloading the CWB version of Europarl

The OPUS project offers a tarball with the Europarl corpus in English, French, German, Dutch, Spanish and Italian. The download may take a while. Take care that you have a good internet connection!

Extract the compressed file

The tarball is large, so please do not be surprised that extracting it may take a while.

Adjust paths

The directory with the extracted files includes a directory registry and data. To be able to move the corpora later on, the paths in the registry files need to point to the correct directories in the data directory.

So these are the corpora. We iterate through the registry files and adjust the path to the data directories.

You now already have working, albeit temporary installation of Europarl on your system. But we want to move things into a data package.

Create data package

We create a directory for the package and generate the directory structure required to put CWB indexed corpus in there.

To acknowledge authorship for the Europarl corpus, we use some information in the readme.txt that is included in the Europarl tarball.

The package might include much more, so we choose a version for the package indicating infancy.

So we generate the DESCRIPTION file …

Moving corpora

The untarred corpus will not be needed at this stage. We remove it, so that we do not waste disk space.

Create and install package tarball

There are large binary data in the package, so this may take a while. The return value of the build-function is the path to the tarball of the package that has been generated. The install.packages-function can be used to install from a local file if we set the argument param to NULL.

Does it work?

The more convenient way to work with the corpora in the package is to use the polmineR-package. You would load the package (library(polmineR)), activate the corpora in the europarl-package (use("europarl")), check which corpora are present (corpus()), and perform some simple query (kwic("EUROPARL-EN", query = "Europe")).

To keep installation requirements to a minimum, the cwbtools-package does not make polmineR a dependency, so we use the low-level functionality of RcppCWB to check whether everything works.

The first question is: Which corpora do we have in the europarl package?

Second, we want to have a look at the concordances of ‘Europe’ in the English version of Europarl.

As mentioned before: Using polmineR is what we recommend for working with CWB corpora from R.

Finally, time to clean up. There are some large files in the temporary directory that has been used. It should be deleted to avoid wasting space on your disk.

Enjoy!