Tetun tokenizer package
Project description
Project description
Tetun Tokenizer
Tetun tokenizer is a Python package for tokenizing a string (or a text) into tokens using:
- Word, punctuations, or special characters delimiters
TetunStandardTokenizer(). - Whitespace delimiter
TetunWhiteSpaceTokenizer(). - Blank lines as a delimiter
TetunBlankLineTokenizer().
Additionally, it is also allowed us to tokenize a string (or a text) by:
- Strings and numbers and ignore punctuations and special characters
TetunSimpleTokenizer(). - Strings only and ignore numbers, punctuations, and special characters
TetunWordTokenizer().
Installation
To install Tetun tokenizer, run the following command:
python3 -m pip install tetun-tokenizer
or simply use:
pip install tetun-tokenizer
Usage
To use the Tetun tokenizer, from the tetuntokenizer package, import a specific tokenizer class and the tokenize function as follows:
- Using
TetunStandardTokenizer()to tokenize a string.
from tetuntokenizer import TetunStandardTokenizer
tokenizer = TetunStandardTokenizer()
string_text = "Ha'u, Gabriel de Jesus, ita-nia maluk di'ak. Ha'u iha $0.25 atu fó ba ita."
output = tokenizer.tokenize(string_text)
print(output)
The output will be:
["Ha'u", ',', 'Gabriel', 'de', 'Jesus', ',', 'ita-nia', 'maluk', "di'ak", '.', "Ha'u", 'iha', '$', '0.25', 'atu', 'fó', 'ba', 'ita', '.']
- Using
TetunWhiteSpaceTokenizer()to tokenize a string.
from tetuntokenizer import TetunWhiteSpaceTokenizer
tokenizer = TetunWhiteSpaceTokenizer()
string_text = "Ha'u, Gabriel de Jesus, ita-nia maluk di'ak. Ha'u iha $0.25 atu fó ba ita."
output = tokenizer.tokenize(string_text)
print(output)
The output will be:
["Ha'u,", 'Gabriel', 'de', 'Jesus,', 'ita-nia', 'maluk', "di'ak.", "Ha'u", 'iha', '$0.25', 'atu', 'fó', 'ba', 'ita.']
- Using
TetunBlankLineTokenizer()to tokenize a string.
from tetuntokenizer import TetunBlankLineTokenizer
tokenizer = TetunBlankLineTokenizer()
string = """
Ha'u, Gabriel de Jesus, ita-nia maluk di'ak.
Ha'u iha $0.25 atu fó ba ita.
"""
output = tokenizer.tokenize(string_text)
print(output)
The output will be:
["\n Ha'u, Gabriel de Jesus, ita-nia maluk di'ak.\n Ha'u iha $0.25 atu fó ba ita.\n "]
- Using
TetunSimpleTokenizer()to tokenize a string.
from tetuntokenizer import TetunSimpleTokenizer
tokenizer = TetunSimpleTokenizer()
string_text = "Ha'u, Gabriel de Jesus, ita-nia maluk di'ak. Ha'u iha $0.25 atu fó ba ita."
output = tokenizer.tokenize(string_text)
print(output)
The output will be:
["Ha'u", 'Gabriel', 'de', 'Jesus', 'ita-nia', 'maluk', "di'ak", "Ha'u", 'iha', '0.25', 'atu', 'fó', 'ba', 'ita']
- Using
TetunWordTokenizer()to tokenize a string.
from tetuntokenizer import TetunWordTokenizer
tokenizer = TetunWordTokenizer()
string_text = "Ha'u, Gabriel de Jesus, ita-nia maluk di'ak. Ha'u iha $0.25 atu fó ba ita."
output = tokenizer.tokenize(string_text)
print(output)
The output will be:
["Ha'u", 'Gabriel', 'de', 'Jesus', 'ita-nia', 'maluk', "di'ak", "Ha'u", 'iha', 'atu', 'fó', 'ba', 'ita']
To print the resulting string to the console, with each element on a new line, you can use for loop or simply use join as follows:
print('\n'.join(output))
The output will be:
Ha'u
Gabriel
de
Jesus
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 import TetunSimpleTokenizer
file_path = Path("/myfile/example.txt")
try:
with corpus_path.open('r', encoding='utf-8') as f:
contents = [line.strip() for line in f]
except FileNotFoundError:
print(f"File not found at: {corpus_path}")
output = '\n'.join(tokenizer.tokenize(str(contents)))
print(output)
There are a few more ways to read file contents that you can use to achieve the same output.
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-0.0.1.tar.gz.
File metadata
- Download URL: tetun_tokenizer-0.0.1.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d101b43a004746f5b64a21d03a23e499a066c66a81a6a610f10d8e66c391375b
|
|
| MD5 |
0f4b75332f08aea6073580c66bff5310
|
|
| BLAKE2b-256 |
b822ff1bcec935a2d25e215277e760b37bccee7bd86d6136e1ea8ee6f24e2074
|
File details
Details for the file tetun_tokenizer-0.0.1-py3-none-any.whl.
File metadata
- Download URL: tetun_tokenizer-0.0.1-py3-none-any.whl
- Upload date:
- Size: 15.5 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 |
c8e2926412b4a7ba5332cb3240bd369ceff89a88ec56f0c5f7df7f4a8b606386
|
|
| MD5 |
d3e8682f519819ac0cbe836a43b8af94
|
|
| BLAKE2b-256 |
0baa59c9607bbde471099322c7d820d8d506911d53582a780104f27d50c646d9
|