Skip to main content

internetbook-analysis

Text analysis and BM25 weighting shared by internetbook indexing and search.

The internetbook indexer and the search API must turn text into terms the same way: a query term the indexer spelled differently matches nothing, and nothing reports it. This package is the one implementation both use.

What it does

  • Analysis: tokenises, case-folds, drops stopwords, optionally adds compound-word parts, and stems with Snowball. Supported: Danish, English, German, Spanish, French, Italian, Norwegian and Swedish. Faroese, Icelandic and Greenlandic have no Snowball stemmer or stopword list; they keep every word, rather than borrowing a neighbour's rules.
  • Greenlandic, Faroese and Icelandic morphology: Greenlandic and Faroese from GiellaLT's analysers, which are bundled (see below); Icelandic from BÍN, the Database of Icelandic Morphology, through the islenska package. Greenlandic words also get their root and derivation stems: ilinniarfissuarmi adds ilinniar, ilinniar0vik and ilinniar0vik0suaq (greenlandic.py). Faroese words also get their lemma, or a compound's parts: skúlanum adds skúli, arbeiðsuppgávur adds arbeið and uppgáva (faroese.py). Icelandic likewise: skólanum adds skóli, kennslubókinni adds kennslubók, kennsla and bók (icelandic.py). BÍN is licensed CC BY-SA 4.0 (Árni Magnússon Institute); see NOTICE.
  • BM25, split between documents and queries:
    • The document side stores saturated, length-normalised term frequencies.
    • The query side applies IDF.
    • Their dot product is the BM25 score. Document vectors don't change when document frequencies do.
  • pgvector sparse vectors: produces the text form of sparsevec values.
from internetbook_analysis import (
    TermStatistics, analyzer_for, document_weights, query_weights,
    term_frequencies, to_sparsevec,
)

terms = analyzer_for("da").analyze("Planterne laver fotosyntese")
# ['plant', 'lav', 'fotosyntes']

# Document side: term ids come from the indexer's term dictionary.
ids = {"plant": 1, "lav": 2, "fotosyntes": 3}
doc = to_sparsevec(document_weights(
    term_frequencies(ids[t] for t in terms), len(terms), average_length=120.0,
))

# Query side: IDF from document frequencies.
stats = {"plant": TermStatistics(term_id=1, document_frequency=420)}
query = to_sparsevec(query_weights(analyzer_for("da").analyze("planter"), stats, 3_500_000))

Versioning

ANALYZER_VERSION names the analysis output. It changes whenever the same input would produce different terms: a new stopword, tokeniser rule, decompounder or stemmer version. A change means re-indexing everything, so:

  • Consumers pin this package exactly (==).
  • snowballstemmer is pinned exactly here, and upgrading it is a new ANALYZER_VERSION.
  • tests/golden/ holds expected output for real sentences. A change to it is a change to ANALYZER_VERSION.

The package version is separate. Releases that don't change output (documentation, new helpers) keep ANALYZER_VERSION.

analyzer_version(language) is the version a language's terms are written with: ANALYZER_VERSION, plus a language's own analysis version where it has one (Greenlandic: 2+kal1, Faroese: 2+fao1, Icelandic: 2+isl1). Changing one language's analysis then re-indexes only that language's content.

GiellaLT analysers and their licence

src/internetbook_analysis/morphology/ holds GiellaLT's Greenlandic (lang-kal) and Faroese (lang-fao) analysers, bundled unmodified. It is licensed under the GNU GPL, version 3 or later, not under this package's MIT licence; see NOTICE and morphology/README.md, which also records the build it came from. It is read with pyhfst, pinned exactly like snowballstemmer.

Stopwords

The lists in src/internetbook_analysis/stopwords/ are the Snowball project's stop.txt files, copied unmodified; their licence is in NOTICE. Solr's EXT:solr configsets use slightly edited copies of the same lists (English swaps a for us, Swedish has sitta for sitt, French adds ten forms). This package follows Snowball, not those edits.

Constants that must match elsewhere

  • BM25_K1, BM25_B: the k1/b options of the pg_textsearch BM25 index.
  • SPARSE_DIMENSIONS: the dimension of every sparsevec written or queried.

Metadata

Release files for internetbook-analysis 0.3.0

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

Source distribution (sdist)

Source distribution for internetbook-analysis 0.3.0
File Size Uploaded Provenance Actions
internetbook_analysis-0.3.0.tar.gz 10.2 MB With provenance Details for internetbook_analysis-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for internetbook-analysis 0.3.0
File Interpreter ABI Platform Actions
internetbook_analysis-0.3.0-py3-none-any.whl Python 3 none any Details for internetbook_analysis-0.3.0-py3-none-any.whl

Total release size: 20.6 MB

Release files / internetbook_analysis-0.3.0.tar.gz

Download URL internetbook_analysis-0.3.0.tar.gz
Size 10.2 MB
Tags Source
SHA-256 checksum
How to use checksums
0ece4b43eb346b5b59bfb9e89de42359581fde101d8e34f6d553b0e16323108c
BLAKE2b-256 checksum
How to use checksums
6764c76b314ee2840a52717566bae477fab3b18c307a7313e22fead87b14f771
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Release files / internetbook_analysis-0.3.0-py3-none-any.whl

Download URL internetbook_analysis-0.3.0-py3-none-any.whl
Size 10.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
876bb405b9f3686b4117870c55d48202702e7820b92c35fe05c2add5b79708cf
BLAKE2b-256 checksum
How to use checksums
ea6a2cc2e04e908448207cdb4aff5d3d9bdb6ebcaf2ba2366fd7da32faba2743
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

Security for internetbook-analysis 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for internetbook_analysis-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 26, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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