Skip to main content

Tetun tokenizer

Project description

Tetun Tokenizer

Tetun tokenizer is a Python package for tokenizing an input text into tokens. There are several tokenization techniques we built alongside this package as follows:

  1. TetunStandardTokenizer(): tokenize the input text by word, punctuations, and special characters.
  2. TetunWhiteSpaceTokenizer(): tokenize the input text by whitespace delimiter.
  3. TetunSentenceTokenizer(): tokenize the input text by .?! delimiters.
  4. TetunBlankLineTokenizer(): tokenize the input text by blank lines delimiter.
  5. TetunSimpleTokenizer(): tokenize the input text by extracting only string and number and ignore punctuations and special characters.
  6. TetunWordTokenizer(): tokenize the input text by extracting only string and 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:

  1. Using TetunStandardTokenizer() to tokenize a given 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', '.']
  1. Using TetunWhiteSpaceTokenizer() to tokenize a given 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.']
  1. Using TetunSentenceTokenizer() to tokenize a given text.
from tetuntokenizer.tokenizer import TetunSentenceTokenizer

tetun_tokenizer = TetunSentenceTokenizer()

text = "Ha'u ema-ida ne'ebé baibain de'it. Tebes ká? 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 ká?', 'Ita-nia maluk Dr. ka Ph.D sira hosi U.S.A mós dehan!']
  1. Using TetunBlankLineTokenizer() to tokenize a given 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            "]
  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)

The output will be:

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

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.0.8.tar.gz (16.6 kB 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.0.8-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tetun_tokenizer-1.0.8.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.7

File hashes

Hashes for tetun_tokenizer-1.0.8.tar.gz
Algorithm Hash digest
SHA256 9bd0d08c904cbec3f91c8bcdc39fe882e3c6f4f6502c9f5922c2656491a015a8
MD5 14c651d5f85aad1cebb8694467d3fc9b
BLAKE2b-256 c80c87a9f2b623e8d355ca36825e0d28b6429805321fb2f34abd4c826defd0fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tetun_tokenizer-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 e2c011b5926132233ea0536ae8b5abe0636b019755385fdae125cc6417f3fd1b
MD5 43d0136698459eb8b9edeec601cb4c0e
BLAKE2b-256 0f2277e01743b2cb5097c384ca49fd80c9eb7b81ff6de5e491354b4f0f30108f

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