Tetun tokenizer
Project description
Tetun Tokenizer
Tetun tokenizer is a Python package used to tokenize an input text into tokens. There are several tokenization techniques we built alongside this package as follows:
TetunStandardTokenizer: tokenizes the input text into individual tokens based on word boundaries, punctuations, and special characters.TetunWhiteSpaceTokenizer: tokenizer: breaks the input text into tokens using whitespace as the delimiter.TetunSentenceTokenizer: splits sentences by its ending delimiters such as period (.), question mark (?), and exclamation mark (!). The period used to represent titles, such as Dr., P.hD., etc., are preserved.TetunBlankLineTokenizer: segments the input text based on the presence of blank lines.TetunSimpleTokenizer: extracts only strings and numbers from the input text while discarding punctuations and special characters.TetunWordTokenizer: extracts only word units from the input text and excludes numbers, punctuation, and special characters.
Installation
With pip:
pip install tetun-tokenizer
Usage
To use the Tetun tokenizer, from the tokenizer module on the Tetun tokenizer package, import a tokenizer feature/class. The examples of its usage are as follows:
- Using
TetunStandardTokenizerto tokenize the input text.
from tetuntokenizer.tokenizer import TetunStandardTokenizer
tetun_tokenizer = TetunStandardTokenizer()
text = "Ha'u mak ita-nia maluk di'ak. Ha'u iha $0.25 atu fó ba ita."
output = tetun_tokenizer.tokenize(text)
print(output)
This will be the output:
["Ha'u", 'mak', 'ita-nia', 'maluk', "di'ak", '.', "Ha'u", 'iha', '$', '0.25', 'atu', 'fó', 'ba', 'ita', '.']
- Using
TetunWhiteSpaceTokenizerto tokenize the input text.
from tetuntokenizer.tokenizer import TetunWhiteSpaceTokenizer
tetun_tokenizer = TetunWhiteSpaceTokenizer()
text = "Ha'u mak ita-nia maluk di'ak. Ha'u iha $0.25 atu fó ba ita."
output = tetun_tokenizer.tokenize(text)
print(output)
This will be the output:
["Ha'u", 'mak', 'ita-nia', 'maluk', "di'ak.", "Ha'u", 'iha', '$0.25', 'atu', 'fó', 'ba', 'ita.']
- Using
TetunSentenceTokenizerto tokenize the input text.
from tetuntokenizer.tokenizer import TetunSentenceTokenizer
tetun_tokenizer = TetunSentenceTokenizer()
text = "Ha'u ema-ida ne'ebé baibain de'it. Tebes ga? Ita-nia maluk Dr. ka Ph.D sira hosi U.S.A mós dehan!"
output = tetun_tokenizer.tokenize(text)
print(output)
This will be the output:
["Ha'u ema-ida ne'ebé baibain de'it.", 'Tebes ga?', 'Ita-nia maluk Dr. ka Ph.D sira hosi U.S.A mós dehan!']
- Using
TetunBlankLineTokenizerto tokenize the input text.
from tetuntokenizer.tokenizer import TetunBlankLineTokenizer
tetun_tokenizer = TetunBlankLineTokenizer()
text = """
Ha'u mak ita-nia maluk di'ak.
Ha'u iha $0.25 atu fó ba ita.
"""
output = tetun_tokenizer.tokenize(text)
print(output)
This will be the output:
["\n Ha'u mak ita-nia maluk di'ak.\n Ha'u iha $0.25 atu fó ba ita.\n "]
- Using
TetunSimpleTokenizerto tokenize a given text.
from tetuntokenizer.tokenizer import TetunSimpleTokenizer
tetun_tokenizer = TetunSimpleTokenizer()
text = "Ha'u mak ita-nia maluk di'ak. Ha'u iha $0.25 atu fó ba ita."
output = tetun_tokenizer.tokenize(text)
print(output)
This will be the output:
["Ha'u", 'mak', 'ita-nia', 'maluk', "di'ak", "Ha'u", 'iha', '0.25', 'atu', 'fó', 'ba', 'ita']
- Using
TetunWordTokenizerto tokenize the input text.
from tetuntokenizer.tokenizer import TetunWordTokenizer
tetun_tokenizer = TetunWordTokenizer()
text = "Ha'u mak ita-nia maluk di'ak. Ha'u iha $0.25 atu fó ba ita."
output = tetun_tokenizer.tokenize(text)
print(output)
This will be the output:
["Ha'u", 'mak', 'ita-nia', 'maluk', "di'ak", "Ha'u", 'iha', 'atu', 'fó', 'ba', 'ita']
To print the resulting output in the console, with each element on a new line, you can use simply use join() as follows:
print('\n'.join(output))
The output will be:
Ha'u
mak
ita-nia
maluk
di'ak
Ha'u
iha
atu
fó
ba
ita
You can also use the tokenizer to tokenize a text from a file. Here is an example:
# Assume that we use Path instead of a string for the file path
from pathlib import Path
from tetuntokenizer.tokenizer import TetunSimpleTokenizer
file_path = Path("myfile/example.txt")
try:
with file_path.open('r', encoding='utf-8') as f:
contents = [line.strip() for line in f]
except FileNotFoundError:
print(f"File not found at: {file_path}")
# You can also lowercase the contents before tokenizing them.
lowercase_contents = contents.lower()
tetun_tokenizer = TetunSimpleTokenizer()
output = '\n'.join(tetun_tokenizer.tokenize(str(lowercase_contents)))
print(output)
This is the example of the output:
ha'u
orgullu
dezenvolve
ha'u-nia
lian
tetun
...
For the source code, visit the GitHub repository for this project.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tetun_tokenizer-1.1.4.tar.gz.
File metadata
- Download URL: tetun_tokenizer-1.1.4.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
566c9b921a98c3b0e1d5f0a254727d98d7988dc240c60095031e94c94177eaa5
|
|
| MD5 |
ea8d5cf27966c29ac30042a0ce3b7388
|
|
| BLAKE2b-256 |
271aa43ecb4264e0fd253fba50a4f21083271051f8e7449759961dd27ce2a7ab
|
File details
Details for the file tetun_tokenizer-1.1.4-py3-none-any.whl.
File metadata
- Download URL: tetun_tokenizer-1.1.4-py3-none-any.whl
- Upload date:
- Size: 16.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c609ae6009bdc2dfc12a919193e833407b04a8b008d8970c7777d1e48874ac4f
|
|
| MD5 |
c92f39561952bb3e83be8edf0d3da108
|
|
| BLAKE2b-256 |
5360154683e70dfe356719a2eed11538fbee9bb1486fc731552449d0c2537084
|