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.2.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.2.0
File Size Uploaded Provenance Actions
internetbook_analysis-0.2.0.tar.gz 973.5 kB With provenance Details for internetbook_analysis-0.2.0.tar.gz

Built distribution (wheel)

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

Total release size: 1.9 MB

Release files / internetbook_analysis-0.2.0.tar.gz

Download URL internetbook_analysis-0.2.0.tar.gz
Size 973.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f8e48c44b92aec7102fd776abf1433c8daeb9d68f4c4b5f7458e36e405818626
BLAKE2b-256 checksum
How to use checksums
6f9538d19d41d65b9792f54e9b8d80db35504630e42a4552e765382cbb8f4df6
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 22, 2026.

Transparency log

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

Download URL internetbook_analysis-0.2.0-py3-none-any.whl
Size 972.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
18c6d674c6b32bc238b3abd6c331fa19c051c06b6b59713c472fb25ef1c3ef95
BLAKE2b-256 checksum
How to use checksums
9e7ade06614289c875a97bf7bc75173b228c4ef4e71cd5d11766c8d452dd9d9f
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 22, 2026.

Transparency log

Security for internetbook-analysis 0.2.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.2.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 22, 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