Skip to main content


OpenPecha

Botok – Python Tibetan Tokenizer

GitHub release Documentation Status Coverage Status Code style: black License

Description • Key Features • Installation • Basic Usage • Advanced Usage • Documentation • Development • Contributing • Acknowledgements


Description

Botok is a powerful Python library for tokenizing Tibetan text. It segments text into words with high accuracy and provides optional attributes such as lemma, part-of-speech (POS) tags, and clean forms. The library supports various text formats, custom dialects, and multiple tokenization modes, making it a versatile tool for Tibetan Natural Language Processing (NLP).

Key Features

  • Word Segmentation: Accurate word segmentation with support for affixed particles
  • Multiple Tokenization Modes:
    • Word tokenization
    • Chunk tokenization (groups of meaningful characters)
    • Space-based tokenization
  • Rich Token Attributes:
    • Lemmatization
    • POS tagging
    • Clean form generation
  • Custom Dialect Support: Use pre-configured dialects or create your own
  • File Processing: Process both strings and files with automatic output generation
  • Robust Handling: Manages complex cases like double tseks and spaces within words

Installation

Requirements

  • Python 3.6 or higher
  • pip package manager

Basic Installation

pip install botok

Development Installation

git clone https://github.com/OpenPecha/botok.git
cd botok
pip install -e .

Basic Usage

Simple Word Tokenization

from botok import WordTokenizer
from botok.config import Config
from pathlib import Path

# Initialize tokenizer with default configuration
config = Config(dialect_name="general", base_path=Path.home())
wt = WordTokenizer(config=config)

# Tokenize text
text = "བཀྲ་ཤིས་བདེ་ལེགས་ཞུས་རྒྱུ་ཡིན་ སེམས་པ་སྐྱིད་པོ་འདུག།"
tokens = wt.tokenize(text, split_affixes=False)

# Print each token
for token in tokens:
    print(token)

File Processing

from botok import Text
from pathlib import Path

# Process a file
input_file = Path("input.txt")
t = Text(input_file)
t.tokenize_chunks_plaintext  # Creates input_pybo.txt with tokenized output

Advanced Usage

Custom Dialect Configuration

from botok import WordTokenizer
from botok.config import Config
from pathlib import Path

# Configure custom dialect
config = Config(
    dialect_name="custom",
    base_path=Path.home() / "my_dialects"
)

# Initialize tokenizer with custom config
wt = WordTokenizer(config=config)

# Process text with custom settings
text = "བཀྲ་ཤིས་བདེ་ལེགས།"
tokens = wt.tokenize(
    text,
    split_affixes=True,
    pos_tagging=True,
    lemmatize=True
)

Different Tokenization Modes

from botok import Text

text = """ལེ གས། བཀྲ་ཤིས་མཐའི་ ༆ ཤི་བཀྲ་ཤིས་"""
t = Text(text)

# 1. Word tokenization
words = t.tokenize_words_raw_text

# 2. Chunk tokenization (groups of meaningful characters)
chunks = t.tokenize_chunks_plaintext

# 3. Space-based tokenization
spaces = t.tokenize_on_spaces

Documentation

For comprehensive documentation, visit:

Development

Building from Source

rm -rf dist/
python setup.py clean sdist

Publishing to PyPI

Automated Publishing with Semantic Versioning

The repository is configured with GitHub Actions to automatically handle version bumping and publishing to PyPI when changes are pushed to the master branch. The workflow uses semantic versioning based on commit messages:

  1. Use the following commit message formats:

    • fix: your message - For bug fixes (triggers PATCH version bump)
    • feat: your message - For new features (triggers MINOR version bump)
    • Add BREAKING CHANGE: description in the commit body for breaking changes (triggers MAJOR version bump)

    Examples:

    # This will trigger a PATCH version bump (e.g., 0.8.12 → 0.8.13)
    fix: improve test coverage to 90% and fix Python 3.12 compatibility
    
    # This will trigger a MINOR version bump (e.g., 0.8.12 → 0.9.0)
    feat: add new sentence tokenization mode for complex Tibetan sentences
    
    # This will trigger a MAJOR version bump (e.g., 0.8.12 → 1.0.0)
    feat: refactor token attributes structure
    
    BREAKING CHANGE: Token.attributes now uses a dictionary format instead of properties, requiring changes to code that accesses token attributes directly
    
  2. When you push to the master branch, the CI workflow will:

    • Run all tests across multiple Python versions
    • Analyze commit messages to determine the next version number
    • Update version numbers in the code
    • Create a new release on GitHub
    • Publish the package to PyPI

Manual Publishing

For manual publishing (if needed):

twine upload dist/*

Running Tests

pytest tests/

Contributing

We welcome contributions! Here's how you can help:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Please ensure your PR adheres to:

Project Owners

Acknowledgements

botok is an open source library for Tibetan NLP. We are grateful to our sponsors and contributors:

Sponsors

Contributors

License

Copyright (C) 2019-2025 OpenPecha. Licensed under Apache 2.0.

Metadata

Release files for botok 1.1.7

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

Source distribution (sdist)

Source distribution for botok 1.1.7
File Size Uploaded Provenance Actions
botok-1.1.7.tar.gz 81.3 kB Without provenance Details for botok-1.1.7.tar.gz

Built distribution (wheel)

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

Total release size: 172.4 kB

Release files / botok-1.1.7.tar.gz

Download URL botok-1.1.7.tar.gz
Size 81.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b9c329fcba47d1fbef655c8da685cefb1daa9727b3208a59dc96b99408fd68c6
BLAKE2b-256 checksum
How to use checksums
c92fe1eb0338e1a4500a77b1e3d1d716a25e4b1d15227173d8767421839af1d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / botok-1.1.7-py3-none-any.whl

Download URL botok-1.1.7-py3-none-any.whl
Size 91.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0f2a94b5f8a49845d46fa0e78e2cf3f397a26154853845de61c57029aa7814ee
BLAKE2b-256 checksum
How to use checksums
60fe4617a30a7dc3432054d8ec2eeaf7d5561204608f8544e6091c71037c430a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for botok 1.1.7

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

1.1.7 This release

2 release files No provenance

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