Skip to main content

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. The maalfrid_toolkit is also used to produce the yearly Målfrid dataset (freely available documents from Norwegian state institutions).

It builds upon:

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 (W)ARC 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

Useful extraction otpions

  • mode: Choose between 'precision' (default) and 'recall'. Recall will give you more language content but probably at the expense of more noise.
  • use_lenient_html_parser: Use a lenient HTML parser to fix broken HTML (more expensive).
  • extract_metadata: Extract metadata from the document and try to infer document publish date.

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

Metadata

Release files for maalfrid_toolkit 1.5.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for maalfrid_toolkit 1.5.6
File Size Uploaded
maalfrid_toolkit-1.5.6.tar.gz 2.3 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for maalfrid_toolkit 1.5.6
File Interpreter ABI Platform
maalfrid_toolkit-1.5.6-py3-none-any.whl Python 3 none any Details

Total release size: 4.1 MB

Release files / maalfrid_toolkit-1.5.6.tar.gz

Download URL maalfrid_toolkit-1.5.6.tar.gz
Size 2.3 MB
Tags Source
SHA-256 checksum
How to use checksums
72e207f78b3ffb5e04eadf64359f9beb987f26102eebe5bc72e2372f4b01de37
BLAKE2b-256 checksum
How to use checksums
07e8495f0d5b02f81b0810fb92f9984fafefe345faaa9a61b4ce48fe9b3ce4c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.26.8 CPython/3.12.3 Linux/6.8.0-110-generic

Release files / maalfrid_toolkit-1.5.6-py3-none-any.whl

Download URL maalfrid_toolkit-1.5.6-py3-none-any.whl
Size 1.8 MB
Tags Python 3
SHA-256 checksum
How to use checksums
aaa3bb707214c4c255dbdd440e223fcfb545dc8903b21fcf4bf201038dc7355d
BLAKE2b-256 checksum
How to use checksums
e15a4095bc2d07db4a14203998b56941c38342ecb70923cb017744f41d90898d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.26.8 CPython/3.12.3 Linux/6.8.0-110-generic

Release history Release notifications | RSS feed

This release

1.5.6 This release

2 release files

1.5.5

2 release files

1.5.4

2 release files

1.5.3

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.5

2 release files

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page