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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_rust_stemmers_tuned-0.1.8-cp314-cp314t-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: py_rust_stemmers_tuned-0.1.8-cp314-cp314t-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 335.0 kB
- Tags: CPython 3.14t, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b870d25d1aeeff7a5efe785295076a22a3f81a170a2ecdeb1e57ef077e4fa13
|
|
| MD5 |
994697db8a877f96fe58dff06cb25527
|
|
| BLAKE2b-256 |
d88e47d5a60d8a75608819aae62beb710f01c20355ae95035bbc27c01bd6eeea
|
Provenance
The following attestation bundles were made for py_rust_stemmers_tuned-0.1.8-cp314-cp314t-manylinux_2_34_x86_64.whl:
Publisher:
publish.yaml on andreribeiro87/py-rust-stemmers-tuned
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_rust_stemmers_tuned-0.1.8-cp314-cp314t-manylinux_2_34_x86_64.whl -
Subject digest:
8b870d25d1aeeff7a5efe785295076a22a3f81a170a2ecdeb1e57ef077e4fa13 - Sigstore transparency entry: 693783348
- Sigstore integration time:
-
Permalink:
andreribeiro87/py-rust-stemmers-tuned@e2d7560f75ef6f1350ff51d8b1dcfcda7e3c00a9 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/andreribeiro87
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@e2d7560f75ef6f1350ff51d8b1dcfcda7e3c00a9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_rust_stemmers_tuned-0.1.8-cp314-cp314t-manylinux_2_34_aarch64.whl.
File metadata
- Download URL: py_rust_stemmers_tuned-0.1.8-cp314-cp314t-manylinux_2_34_aarch64.whl
- Upload date:
- Size: 326.5 kB
- Tags: CPython 3.14t, manylinux: glibc 2.34+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9d0f6148e69e93ac97602f44fe769462d141aad4b9d575f957d34168f7e5b05
|
|
| MD5 |
03af2b8f0ae348f10f129a03a59d74a4
|
|
| BLAKE2b-256 |
b301476c160b9f3013f506acf6bffd40fdceb02312baad523d091579a36ab913
|
Provenance
The following attestation bundles were made for py_rust_stemmers_tuned-0.1.8-cp314-cp314t-manylinux_2_34_aarch64.whl:
Publisher:
publish.yaml on andreribeiro87/py-rust-stemmers-tuned
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_rust_stemmers_tuned-0.1.8-cp314-cp314t-manylinux_2_34_aarch64.whl -
Subject digest:
d9d0f6148e69e93ac97602f44fe769462d141aad4b9d575f957d34168f7e5b05 - Sigstore transparency entry: 693783368
- Sigstore integration time:
-
Permalink:
andreribeiro87/py-rust-stemmers-tuned@e2d7560f75ef6f1350ff51d8b1dcfcda7e3c00a9 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/andreribeiro87
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@e2d7560f75ef6f1350ff51d8b1dcfcda7e3c00a9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file py_rust_stemmers_tuned-0.1.8-cp314-cp314t-macosx_11_0_arm64.whl.
File metadata
- Download URL: py_rust_stemmers_tuned-0.1.8-cp314-cp314t-macosx_11_0_arm64.whl
- Upload date:
- Size: 287.9 kB
- Tags: CPython 3.14t, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e3886c046737c06c2b6c187d614ba8686e0544fa71c1551b528e14e79e686c3
|
|
| MD5 |
1ac95d7f5f78f033eb76da1389951e47
|
|
| BLAKE2b-256 |
867f7f512e991e780cb975b8c7e598045e830421d1bb3e49a7b5cdf899936419
|
Provenance
The following attestation bundles were made for py_rust_stemmers_tuned-0.1.8-cp314-cp314t-macosx_11_0_arm64.whl:
Publisher:
publish.yaml on andreribeiro87/py-rust-stemmers-tuned
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py_rust_stemmers_tuned-0.1.8-cp314-cp314t-macosx_11_0_arm64.whl -
Subject digest:
6e3886c046737c06c2b6c187d614ba8686e0544fa71c1551b528e14e79e686c3 - Sigstore transparency entry: 693783333
- Sigstore integration time:
-
Permalink:
andreribeiro87/py-rust-stemmers-tuned@e2d7560f75ef6f1350ff51d8b1dcfcda7e3c00a9 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/andreribeiro87
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@e2d7560f75ef6f1350ff51d8b1dcfcda7e3c00a9 -
Trigger Event:
push
-
Statement type: