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 are left unstemmed and keep every word, rather than borrowing a neighbour's rules.
  • 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.

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.1.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.1.0
File Size Uploaded Provenance Actions
internetbook_analysis-0.1.0.tar.gz 21.4 kB With provenance Details for internetbook_analysis-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 42.7 kB

Release files / internetbook_analysis-0.1.0.tar.gz

Download URL internetbook_analysis-0.1.0.tar.gz
Size 21.4 kB
Tags Source
SHA-256 checksum
How to use checksums
bdc7d5f1afd0dc6e0c8d79b8ed3ef4dee1752f1b9377d97429bcad22f61008b9
BLAKE2b-256 checksum
How to use checksums
f05b677d13a0c334cc8f556f9ebfd9a60dae11fc339e80879fa26fa9c306cb40
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 16, 2026.

Transparency log

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

Download URL internetbook_analysis-0.1.0-py3-none-any.whl
Size 21.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5839bbe55e4a519ebef8fea39132abe537c8304abeb9ff7fa5fc6d7c76e11617
BLAKE2b-256 checksum
How to use checksums
d7df1aba5000ccf7ef3afd3e33cef33cb583819a55fdebfe0b757631bd58bc2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 16, 2026.

Transparency log

Security for internetbook-analysis 0.1.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.1.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 16, 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