Skip to main content

Tetun tokenizer

Project description

Tetun Tokenizer

Tetun tokenizer is a Python package used to tokenize an input text into tokens. It offers several tokenization techniques:

  1. TetunStandardTokenizer: Segments the input text into individual tokens based on word boundaries, punctuation, and special characters.
  2. TetunSentenceTokenizer: Splits sentences using ending delimiters such as periods (.), question marks (?), and exclamation marks (!). Titles represented by periods, such as Dr. and Ph.D., are preserved.
  3. TetunBlankLineTokenizer: Segments the input text based on the presence of blank lines.
  4. TetunSimpleTokenizer: Extracts only strings and numbers from the input text while discarding punctuations and special characters.
  5. TetunWordTokenizer: Extracts word units from the input text, excluding numbers, punctuation, and special characters.

Installation

You can install the Tetun tokenizer via pip:

pip install tetun-tokenizer

Usage

To utilize the Tetun tokenizer, simply import the desired tokenizer feature/class from the tokenizer module within the Tetun tokenizer package. Here are some examples demonstrating its usage:

  1. Utilizing TetunStandardTokenizer to tokenize the input text.
from tetuntokenizer.tokenizer import TetunStandardTokenizer

# Instantiate TetunStandardTokenizer
tetun_tokenizer = TetunStandardTokenizer()

# Input text
text = "Ha'u mak ita-nia maluk di'ak. Ha'u iha $0.25 atu fó ba ita."

# Tokenize the text
output = tetun_tokenizer.tokenize(text)

# Print the output
print(output)

Expected output:

["Ha'u", 'mak', 'ita-nia', 'maluk', "di'ak", '.', "Ha'u", 'iha', '$', '0.25', 'atu', 'fó', 'ba', 'ita', '.']
  1. 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)

Expected 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!']
  1. Utilizing 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)

Expected output:

["\n            Ha'u mak ita-nia maluk di'ak.\n            Ha'u iha $0.25 atu fó ba ita.\n            "]
  1. 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)

Expected output:

["Ha'u", 'mak', 'ita-nia', 'maluk', "di'ak", "Ha'u", 'iha', '0.25', 'atu', 'fó', 'ba', 'ita']
  1. 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)

Expected output:

["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. Below 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 
...

Citation

If you use this repository or any of its contents for your research, academic work, or publication, we kindly request that you cite it as follows:

@misc{jesus-nunes-2024,
  author       = {Gabriel de Jesus and Sérgio Nunes},
  title        = {Data Collection Pipeline for Low-Resource Languages: A Case Study on Constructing a Tetun Text Corpus},
  year         = {2024},
  note         = {Accepted at LREC-COOLING, 2024},
}

Acknowledgement

This work is financed by National Funds through the Portuguese funding agency, FCT - Fundação para a Ciência e a Tecnologia under the PhD scholarship grant number SFRH/BD/151437/2021.

License

License: MIT

Additional Information

For the source code, visit the GitHub repository for this project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tetun_tokenizer-1.2.1.tar.gz (6.0 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tetun_tokenizer-1.2.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file tetun_tokenizer-1.2.1.tar.gz.

File metadata

  • Download URL: tetun_tokenizer-1.2.1.tar.gz
  • Upload date:
  • Size: 6.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.7

File hashes

Hashes for tetun_tokenizer-1.2.1.tar.gz
Algorithm Hash digest
SHA256 a12b778c1cb4492d53e5713f1c7a832ab7388cdcc71412a62e5c295223101c9c
MD5 ff32da593290165c030770af4e7c7a75
BLAKE2b-256 f9a15f2e2fa807395baaa0f635f0132527780ee9873c6330b912607e3961216c

See more details on using hashes here.

File details

Details for the file tetun_tokenizer-1.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for tetun_tokenizer-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3413d5dc35fc8c03909c243250b7dde5db23e2c14edde8024a631d9ca4006453
MD5 d7973d6bf4bc794ac00b83fc5eb5622f
BLAKE2b-256 f3ab905275c73889384f62845662a4bfd9ba2062d90e8c8047db88a49db69637

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page