Skip to main content

TglStemmer

A Python library for Tagalog word stemming.

PyPI version Downloads License GitHub stars CI pre-commit.ci status

About

TglStemmer is a library that finds the root form of Tagalog words. It works on inflected words, even those with mixed Tagalog-English (Taglish) terms or those not found in dictionaries. It removes affixes, reduces repeated syllables, and applies transformation rules to find possible root forms. These are filtered using a list of valid words and conditions, and the best root is then chosen based on how much was changed during the process.

Installation

pip install tglstemmer

Usage

TglStemmer acts as a standalone library that can be imported via from tglstemmer import stemmer.

get_stem

Gets the root of a word. Takes a word and returns its stem as a Stem object (basically a string with affixes, reduplication, transformations, etc. as additional attributes).

stem = stemmer.get_stem("nagsulat")
print(stem)
# Output: 'sulat'

Since get_stem returns a Stem object, the properties used in the stemming process can be accessed as attributes.

prefix = stem.pre
print(prefix)
# Output: 'nag'

suffix = stem.suf
print(suffix)
# Output: None

get_stems

Gets the root of each word in a text. Takes a text and returns the stem of each word as a list of Stem objects.

stems = stemmer.get_stems("nagsulat, binasa, at punitin")
print(stems)
# Output: ['sulat', 'basa', 'at', 'punit']

get_stem_candidates

Gets all the stem candidates of a word. Takes a word and returns the possible stems as a list of Stem objects. This is helpful for loose checking, considering candidate selection is not perfect.

candidates = stemmer.get_stem_candidates("pinakamahusay't")
print(candidates)
# Output: ['husay', 'mahusay', 'pinakamahusay']

Accuracy

The accuracy was tested using a list of stems and their corresponding inflections. The list is manually derived from the examples in Balarila ng Wikang Pambansa (Santos, 1939), particularly the sections "Palabuuan ng mga Salita" (pp. 28-34) and "Mga Sangkap ng Pananalita" (pp. 35-37). This is not a "gold" standard dataset but was chosen for testing since the book provides varied examples of inflections during its discussion of the affixation process. Each inflection was stemmed by TglStemmer and then compared to the original stem, across 266 stem-inflection pairs.

Metric Value
Accuracy 75.19%
Correct Attempts 200
Incorrect Attempts 66
Understemming Avg 0.69
Overstemming Avg 0.12
Understemming Total 184
Overstemming Total 33

Development

This project uses uv for dependency management.

Clone the repo and sync dependencies (including dev and test groups):

git clone https://github.com/andrianllmm/tagalog-stemmer.git
cd tagalog-stemmer
uv sync --all-groups

Run the tests:

uv run pytest

Contributing

Contributions are welcome! See CONTRIBUTING.md for more details.

License

Distributed under the MIT License.

Metadata

Release files for tglstemmer 0.1.1

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

Source distribution (sdist)

Source distribution for tglstemmer 0.1.1
File Size Uploaded
tglstemmer-0.1.1.tar.gz 137.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tglstemmer 0.1.1
File Interpreter ABI Platform
tglstemmer-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 272.2 kB

Release files / tglstemmer-0.1.1.tar.gz

Download URL tglstemmer-0.1.1.tar.gz
Size 137.2 kB
Tags Source
SHA-256 checksum
How to use checksums
027be731b2f923b8cc1190ebfa583826b78943dc83019264243cf6bd24aa920c
BLAKE2b-256 checksum
How to use checksums
ed09842b5ee9beae126c3bf5aef4c0db806f102495fd525d7647984c71f8c71b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.33 {"installer":{"name":"uv","version":"0.11.33","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / tglstemmer-0.1.1-py3-none-any.whl

Download URL tglstemmer-0.1.1-py3-none-any.whl
Size 135.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
895823c8180339fcc61aacfade562b8ee12f934098e66c0a755926a8bfd665ea
BLAKE2b-256 checksum
How to use checksums
a83dcd4bfe6d031def017eddf4a298c952231253c2228f09d7f0374b91fb8ddc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.11.33 {"installer":{"name":"uv","version":"0.11.33","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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