Registry / data / segments

segments

JSON →
library2.4.0pypypi✓ verified 21d ago

Segments provides functions to tokenize and segment strings of text into individual characters or graphemes, and into segments according to orthography profiles. It is particularly useful for linguistic data processing using CLDF (Cross-Linguistic Data Formats). The library typically sees a few releases per year, with major versions introducing updates to Unicode standards.

pip install segments
INSTALL
IMPORT
SIG · SEGMENTS
S
segments
datapythonv2.4.0
Install
4.5s avg
Import
Disk
65MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 66.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.5s · import 0.000s · 67MB
65MB installed
● package 65MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

tokenize
from segments import tokenize
from segments.tokenizer import tokenize
Tokenizer
from segments import Tokenizer
Profile
from segments import Profile

Demonstrates basic Unicode grapheme tokenization and custom segmentation using an orthography profile.

import segments # Unicode grapheme segmentation (standard Unicode rules) text_unicode = 'ŋ͡m' graphemes = segments.tokenize(text_unicode) print(f"Unicode graphemes for '{text_unicode}': {graphemes}") # Segmentation using an orthography profile # (example profile for 'ph', 'ch', 'th' as single segments) orthography_profile = { "rules": [ ["ph", "pʰ"], ["ch", "cʰ"], ["th", "tʰ"] ] } segmenter = segments.Segmenter(profile=orthography_profile) text_profile = 'tʰaiph' segments_profile = segmenter.segment(text_profile) print(f"Profile segments for '{text_profile}': {segments_profile}") # Expected output for verification assert graphemes == ['ŋ', '͡', 'm'] assert segments_profile == ['tʰ', 'ai', 'pʰ']
Debug
Known issues
gotchaDistinguish carefully between `segments.tokenize` and `Segmenter.segment`. `segments.tokenize` performs basic Unicode grapheme cluster segmentation only. `Segmenter.segment` is used to apply custom orthography rules provided via a `profile`.
fix
For rule-based segmentation, always instantiate `Segmenter` with a `profile` and use its `.segment()` method. Use `segments.tokenize()` exclusively for standard Unicode grapheme clustering.
affects: All versions
breakingVersion 2.0.0 introduced 'Unicode Standard tokenization', which may result in subtle changes to grapheme cluster output for certain complex character sequences compared to pre-2.0.0 versions. This is a behavioral change based on updated Unicode standards, not an API break.
fix
Review tokenization outputs for critical linguistic data when upgrading from versions <2.0.0 to ensure consistency. Adjust downstream processing if specific grapheme clustering assumptions have changed due to updated Unicode interpretations.
affects: >=2.0.0
gotchaThe `profile` argument for `segments.Segmenter` expects a dictionary with a 'rules' key, formatted as a list of lists (e.g., `[['rule_text', 'ipa_trans']]`). Directly passing file paths or non-conforming dictionaries will fail.
fix
Ensure the `profile` dictionary strictly adheres to the `{'rules': [[...]]}` structure. Refer to `pycldf` documentation for advanced orthography profile handling if loading from files or complex scenarios.
affects: All versions
Upgrade
Version history
2.4.0latest on PyPI · released Mar 7, 2026
Audit
Dependencies
attrsrequiredInternal object modeling and data structures.
clldutilsrequiredUtilities for CLDF data structures, particularly path handling and configuration.
pycldfrequiredHandles CLDF data structures, including orthography profiles used by Segmenter.
Agent activity
6 hits · last 30 days
node
4
OpenAI (training)
1
Resources
segments — pip install segments · libregistry