Skip to main content

Fast and parallel snowball stemmer

Project description

py-rust-stemmers

py-rust-stemmers is a high-performance Python wrapper around the rust-stemmers library, utilizing the Snowball stemming algorithm. This library allows for efficient stemming of words with support for parallel processing, making it a powerful tool for text processing tasks. The library is built using maturin to compile the Rust code into a Python package.

Features

  • Snowball Stemmer: Uses the well-known Snowball stemming algorithms for efficient word stemming in multiple languages.
  • Parallelism Support: Offers parallel processing for batch stemming, providing significant speedup for larger text sequences.
  • Rust Performance: Leverages the performance of Rust for fast, reliable text processing.

Installation

You can install py-rust-stemmers via pip:

pip install py-rust-stemmers

Usage

Here's a simple example showing how to use py-rust-stemmers to stem words using the Snowball algorithm:

from py_rust_stemmers import SnowballStemmer

# Initialize the stemmer for the English language
s = SnowballStemmer('english')

# Input text
text = """This stem form is often a word itself, but this is not always the case as this is not a requirement for text search systems, which are the intended field of use. We also aim to conflate words with the same meaning, rather than all words with a common linguistic root (so awe and awful don't have the same stem), and over-stemming is more problematic than under-stemming so we tend not to stem in cases that are hard to resolve. If you want to always reduce words to a root form and/or get a root form which is itself a word then Snowball's stemming algorithms likely aren't the right answer."""
words = text.split()

# Example usage of the methods
stemmed = s.stem_word(words[0])
print(f"Stemmed word: {stemmed}")

# Stem a list of words
stemmed_words = s.stem_words(words)
print(f"Stemmed words: {stemmed_words}")

# Stem words in parallel
stemmed_words_parallel = s.stem_words_parallel(words)
print(f"Stemmed words (parallel): {stemmed_words_parallel}")

Methods

stem_word(word: str) -> str

This method stems a single word. It is best used for small or isolated stemming tasks.

Example:

s.stem_word("running")  # Output: "run"

stem_words(words: List[str]) -> List[str]

This method stems a list of words sequentially. It is ideal for processing short to moderately sized text sequences.

Example:

s.stem_words(["running", "jumps", "easily"])  # Output: ["run", "jump", "easili"]

stem_words_parallel(words: List[str]) -> List[str]

This method stems a list of words in parallel. It provides significant speedup for longer text sequences (e.g., sequences longer than 512 tokens) by utilizing parallel processing. It is ideal for batch processing of large datasets.

Example:

s.stem_words_parallel(["running", "jumps", "easily"])  # Output: ["run", "jump", "easili"]

Build from source

  • Install maturin
  • Go to project dir
maturin build --release
pip install target/wheels/py_rust_stemmers-<your os/architecture/etc>.whl

Development

  • Install uv
  • Install dependencies
uv sync
uv pip install maturin pytest tqdm snowballstemmer
  • Develop the package using maturin develop command
uv run maturin develop
  • Build the package using maturin build command
uv run maturin build
  • Test the package using maturin test command
uv run pytest
  • Run speedtest
uv run python tests/speedtest.py
  • Run benchmark for quantile
uv run python tests/benchmark_for_quantile.py

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

py_rust_stemmers_tuned-0.1.9-cp314-cp314t-manylinux_2_34_x86_64.whl (335.5 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.34+ x86-64

py_rust_stemmers_tuned-0.1.9-cp314-cp314t-manylinux_2_34_aarch64.whl (327.1 kB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.34+ ARM64

py_rust_stemmers_tuned-0.1.9-cp314-cp314t-macosx_11_0_arm64.whl (288.4 kB view details)

Uploaded CPython 3.14tmacOS 11.0+ ARM64

File details

Details for the file py_rust_stemmers_tuned-0.1.9-cp314-cp314t-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for py_rust_stemmers_tuned-0.1.9-cp314-cp314t-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 e0974fee6edb8c77f02b5d345d1107319158a1a9e54c0e8d0175561473f3b0fa
MD5 75a0230906149871d773c8ff19870286
BLAKE2b-256 f45026470e07c15bc53071f3792a607b14eaa412e6b0cc8ec89214c23c837ec5

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_rust_stemmers_tuned-0.1.9-cp314-cp314t-manylinux_2_34_x86_64.whl:

Publisher: publish.yaml on andreribeiro87/py-rust-stemmers-tuned

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_rust_stemmers_tuned-0.1.9-cp314-cp314t-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for py_rust_stemmers_tuned-0.1.9-cp314-cp314t-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 931d971b40a3e515fa69b0d8f988c9c3ae804d23ebb0fff989b7ae6574dbcb45
MD5 59a1256a019e6fc9aa0a0155dd41de33
BLAKE2b-256 036fe61e091b750d861a4edb1bd11df7f86c55bfcf244d6e72fbd6a518ca93a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_rust_stemmers_tuned-0.1.9-cp314-cp314t-manylinux_2_34_aarch64.whl:

Publisher: publish.yaml on andreribeiro87/py-rust-stemmers-tuned

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py_rust_stemmers_tuned-0.1.9-cp314-cp314t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for py_rust_stemmers_tuned-0.1.9-cp314-cp314t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2bd1b46516e7ab6c3d9c3b3ce99fa4dfbab58a44d0ecf54cdf3198017bdcaa90
MD5 07a668bc80e278fbf4cf18b6ce357ff2
BLAKE2b-256 cb76c22b409505225c4eba776768e3a0cec71bd80293733372f969c836017db9

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_rust_stemmers_tuned-0.1.9-cp314-cp314t-macosx_11_0_arm64.whl:

Publisher: publish.yaml on andreribeiro87/py-rust-stemmers-tuned

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page