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 as follows:

  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 punctuation 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 husi 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 husi 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:

@inproceedings{de-jesus-nunes-2024-labadain-crawler,
    title = "Data Collection Pipeline for Low-Resource Languages: A Case Study on Constructing a Tetun Text Corpus",
    author = "de Jesus, Gabriel  and
      Nunes, S{\'e}rgio Sobral",
    editor = "Calzolari, Nicoletta  and
      Kan, Min-Yen  and
      Hoste, Veronique  and
      Lenci, Alessandro  and
      Sakti, Sakriani  and
      Xue, Nianwen",
    booktitle = "Proceedings of the 2024 Joint International Conference on Computational Linguistics, Language Resources and Evaluation (LREC-COLING 2024)",
    month = may,
    year = "2024",
    address = "Torino, Italia",
    publisher = "ELRA and ICCL",
    url = "https://aclanthology.org/2024.lrec-main.390",
    pages = "4368--4380"
}

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 (DOI 10.54499/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.2.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.2-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tetun_tokenizer-1.2.2.tar.gz
Algorithm Hash digest
SHA256 3ac90458f225b7341cdeed671911f388b81b0ccc1a4b9b3abf431cd4f08969a3
MD5 8165bfc50b6cec1003001c308aab469f
BLAKE2b-256 6d7de0f3df73533ac1a589a8a88980e3112e38c3c12268a8de3be660547cbb44

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tetun_tokenizer-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 39130a28faf36d1cbfb1327f9789b9e44e4fc0e1ee93ccf73022e8c1c85a0618
MD5 d16915475e222b6586267605bc402651
BLAKE2b-256 9fccb76656a0601c8ef7ce3fb5f6a53194ffeb48be9288c597ed64946c48f95f

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