Segmentation with orthography profiles
Project Links
Meta
Author: Steven Moran and Robert Forkel
Requires Python: >=3.8
Classifiers
Development Status
- 5 - Production/Stable
Intended Audience
- Developers
- Science/Research
Natural Language
- English
Operating System
- OS Independent
Programming Language
- Python :: 3
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: 3.13
- Python :: Implementation :: CPython
- Python :: Implementation :: PyPy
License
- OSI Approved :: Apache Software License
segments
The segments package provides Unicode Standard tokenization routines and orthography segmentation,
implementing the linear algorithm described in the orthography profile specification from
The Unicode Cookbook (Moran and Cysouw 2018 ).
Command line usage
Create a text file:
$ echo "aäaaöaaüaa" > text.txt
Now look at the profile:
$ cat text.txt | segments profile
Grapheme frequency mapping
a 7 a
ä 1 ä
ü 1 ü
ö 1 ö
Write the profile to a file:
$ cat text.txt | segments profile > profile.prf
Edit the profile:
$ more profile.prf
Grapheme frequency mapping
aa 0 x
a 7 a
ä 1 ä
ü 1 ü
ö 1 ö
Now tokenize the text without profile:
$ cat text.txt | segments tokenize
a ä a a ö a a ü a a
And with profile:
$ cat text.txt | segments --profile=profile.prf tokenize
a ä aa ö aa ü aa
$ cat text.txt | segments --mapping=mapping --profile=profile.prf tokenize
a ä x ö x ü x
API
>>> from segments import Profile, Tokenizer
>>> t = Tokenizer()
>>> t('abcd')
'a b c d'
>>> prf = Profile({'Grapheme': 'ab', 'mapping': 'x'}, {'Grapheme': 'cd', 'mapping': 'y'})
>>> print(prf)
Grapheme mapping
ab x
cd y
>>> t = Tokenizer(profile=prf)
>>> t('abcd')
'ab cd'
>>> t('abcd', column='mapping')
'x y'
Feb 20, 2025
2.3.0
Jul 08, 2022
2.2.1
Jan 08, 2021
2.2.0
Nov 21, 2019
2.1.3
Nov 07, 2019
2.1.2
Nov 05, 2019
2.1.1
Sep 19, 2019
2.1.0
Jul 01, 2019
2.0.2
Aug 02, 2018
2.0.1
Aug 01, 2018
2.0.0
Jun 22, 2018
1.2.2
Apr 30, 2018
1.2.1
Nov 16, 2017
1.1.1
Feb 02, 2017
1.1.0
Jan 25, 2017
1.0.0
Jan 13, 2017
0.3.0
Jan 12, 2017
0.2.0
Jan 09, 2017
0.1.0