Toolkit for the Målfrid project
Project description
Maalfrid toolkit
maalfrid_toolkit is a Python package designed for crawling and extracting natural language data from documents found on the web (HTML, PDF, DOC). It is primarily used in the Målfrid project, a collaboration between the National Library of Norway and The Language Council of Norway, which aims to measure the usage of the two official Norwegian language forms, Bokmål and Nynorsk, on Norwegian public sector websites. While the toolkit has a particular emphasis on the Nordic countries, it supports extraction and language detection of more than 60 languages.
It builds upon:
- wget and (custom) browsertrix for crawling
- JusText for HTML boilerplate removal
- Notram PDF text extraction from NB AI-lab
- DOC extraction using docx2txt and antiword
- Gielladetect/pytextcat and GlotLID V3 for language detection
- Simhash for near-duplicate detection
Install
Install with pip
pip install maalfrid_toolkit
With Glotlid / fasttext (optional, see below for caveats):
pip install maalfrid_toolkit[glotlid]
Install with pdm
pdm install
Test run pipeline
On HTML
python -m maalfrid_toolkit.pipeline --url https://www.nb.no/utstilling/opplyst-glimt-fra-en-kulturhistorie/ --to_jsonl
On PDF
python -m maalfrid_toolkit.pipeline --url https://www.nb.no/sbfil/dok/nst_taledat_dk.pdf --to_jsonl
On DOC
python -m maalfrid_toolkit.pipeline --url https://www.nb.no/content/uploads/2018/11/Søknadsskjema-Bokhylla-2.doc --to_jsonl
On WARC file (e.g. from self-crawled material)
python -m maalfrid_toolkit.pipeline --warc_file example_com-00000.warc.gz --calculate_simhash --to_jsonl > warc.jsonl
On sitemap
python -m maalfrid_toolkit.pipeline --url https://example.com/sitemap.xml --crawl_sitemap --to_jsonl > example.jsonl
Database (Postgres)
If you want to store and process the data further in a database, setup a Postgres database and enter your credentials in an .env file in the package root directory (see env-example). Be sure to populate the database with schema and indices found in db/ prior to running the commands in maalfrid_toolkit.db.
OS-level dependencies (tested with Ubuntu 24.04) for optional functionality
For fasttext (optional)
sudo apt-get install build-essential python3-dev
For .doc text extraction (optional)
sudo apt-get install antiword
A note on using Browsertrix
In order to use Browsertrix for crawling JavaScript-heavy pages and extract text from HTML, you must currently clone a custom Browsertrix from:
https://github.com/Sprakbanken/browsertrix-crawler/tree/add-dom-resource
Then build with Docker:
docker build -t maalfrid-browsertrix .
License
GPL
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file maalfrid_toolkit-1.2.0.tar.gz.
File metadata
- Download URL: maalfrid_toolkit-1.2.0.tar.gz
- Upload date:
- Size: 1.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.24.1 CPython/3.12.3 Linux/6.8.0-60-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
170388e815391d8b94d2c4c095e475fe00cf792db3790791f30b65c24376be26
|
|
| MD5 |
8f853d76eae5b0ca7c8c603236b40356
|
|
| BLAKE2b-256 |
0cea4e814cd5c0aa006a3e6465a8415f1cc8f23fc8712f3ff8bd6a3dbca43805
|
File details
Details for the file maalfrid_toolkit-1.2.0-py3-none-any.whl.
File metadata
- Download URL: maalfrid_toolkit-1.2.0-py3-none-any.whl
- Upload date:
- Size: 706.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.24.1 CPython/3.12.3 Linux/6.8.0-60-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8be73e72964bce3d1184852cf58c8ab4815438b66909f625fc54dce1857acd3
|
|
| MD5 |
a50616f64a72a958d5a5ca4645d2a1d2
|
|
| BLAKE2b-256 |
a92d74e7d75f4c692a210bf3535e865f66bd39f39a4e5a6a8d14c675490b91ed
|