Skip to main content

TglStemmer

A Python library for Tagalog word stemming

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. 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.

Use get_stem to get the root of a word. This 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

Use get_stems() to get the root of each word in a text. This 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']

Use get_stem_candidates to get all the stem candidates of a word. This 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 from the book Balarila ng Wikang Pambansa (Santos, 1939), particularly in sections "Palabuuan ng mga Salita" (pp. 28-34) and "Mga Sangkap ng Pananalita" (pp. 35-37). This is not a "gold" standard dataset but is chosen for testing as the book provides varied examples of inflections during its discussion about the process of affixation. Each inflection was stemmed by TglStemmer and then compared to the original stem. The test included 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

Download files

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

Source Distribution

tglstemmer-0.1.0.tar.gz (137.2 kB view details)

Uploaded Source

Built Distribution

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

tglstemmer-0.1.0-py3-none-any.whl (135.3 kB view details)

Uploaded Python 3

File details

Details for the file tglstemmer-0.1.0.tar.gz.

File metadata

  • Download URL: tglstemmer-0.1.0.tar.gz
  • Upload date:
  • Size: 137.2 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for tglstemmer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fa89f621563ddb09f09eee1a86868cbb050290d7e5cf8e41d94f7717f203620f
MD5 680d514726381f5e68230ccafa724986
BLAKE2b-256 72fdce5969797a6ebe02e07b4d97d16bc9865ce9f45b76b1a2d299c1a8a27c79

See more details on using hashes here.

File details

Details for the file tglstemmer-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tglstemmer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 135.3 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for tglstemmer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cb800381fcf69a27d24d2ffef614f1234aad474f5718d8431aa108766caa02ad
MD5 0243ea58cad0427d8fb4cc6871582af2
BLAKE2b-256 1941dd2667d48c1d3fb77f0ae9d0e7040d23c493d0ac338ea03a525325602141

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.1

2 files

This release

0.1.0 This release

2 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