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 along with this package as follows:
TetunStandardTokenizer(): tokenize the input text byword,punctuations, andspecial characters.TetunWhiteSpaceTokenizer(): tokenize the input text bywhitespacedelimiter.TetunSentenceTokenizer(): tokenize the input text by period (.), question mark (?) and exclamation mark (!) delimiters.TetunBlankLineTokenizer(): tokenize the input text byblank linesdelimiter.TetunSimpleTokenizer(): tokenize the input text by extractingonly string and numberand ignore punctuations and special characters.TetunWordTokenizer(): tokenize the input text by extractingonly stringand ignore numbers, punctuations, and special characters.
Installation
To install Tetun tokenizer, run the following command in your console:
python3 -m pip install tetun-tokenizer
or simply run:
pip install tetun-tokenizer
It also supports conda and pipenv or similar commands.
Usage
To use Tetun tokenizer, from the tokenizer module on the tetuntokenizer package, import a tokenizer class. Instantiate the imported class and then call a tokenize function as follows:
- Using
TetunStandardTokenizer()to 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)
The output will be:
["Ha'u", 'mak', 'ita-nia', 'maluk', "di'ak", '.', "Ha'u", 'iha', '$', '0.25', 'atu', 'fó', 'ba', 'ita', '.']
- Using
TetunWhiteSpaceTokenizer()to 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)
The output will be:
["Ha'u", 'mak', 'ita-nia', 'maluk', "di'ak.", "Ha'u", 'iha', '$0.25', 'atu', 'fó', 'ba', 'ita.']
- Using
TetunSentenceTokenizer()to 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)
The output will be:
["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
TetunBlankLineTokenizer()to 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)
The output will be:
["\n Ha'u mak ita-nia maluk di'ak.\n Ha'u iha $0.25 atu fó ba ita.\n "]
- Using
TetunSimpleTokenizer()to 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)
The output will be:
["Ha'u", 'mak', 'ita-nia', 'maluk', "di'ak", "Ha'u", 'iha', '0.25', 'atu', 'fó', 'ba', 'ita']
- Using
TetunWordTokenizer()to 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)
The output will be:
["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 for loop or 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)
The output will be:
ha'u
orgullu
dezenvolve
ha'u-nia
lian
tetun
...
There are a few more ways to read file contents that you can use to achieve the same output.
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.3.tar.gz.
File metadata
- Download URL: tetun_tokenizer-1.1.3.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 |
dcc18ebdac4dd9557cabcf92a8de8484707b3fd229a29950f278871217374dd6
|
|
| MD5 |
4b7aebef9e48c06e385f50342130db1c
|
|
| BLAKE2b-256 |
6a536a6e04bec68f3dfb4b84737851e894c35f771f3f319540ae30b11042e12e
|
File details
Details for the file tetun_tokenizer-1.1.3-py3-none-any.whl.
File metadata
- Download URL: tetun_tokenizer-1.1.3-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 |
72f07dc9bb0433e8eb97ffbdca215ddae9e331e742ca6ef8f49f5aa8d1ad6633
|
|
| MD5 |
39b039724001ae2620e8a4fad9afae5c
|
|
| BLAKE2b-256 |
26da9ceb84d1e430a4eb60630caa38f9cd4b51b89e03773891f030bc33056071
|