Skip to main content

ICU-tokenizer is a python package used to perform universal language normalization and tokenization using the International Components for Unicode.

Install

See ./INSTALL.md

Usage (Python)

Sentence splitter

# To split a paragraph into multiple sentences
>>> from icu_tokenizer import SentSplitter
>>> splitter = SentSplitter('zh')

>>> paragraph = """
美国最高法院(英语:Supreme Court of the United States),一般是指美国联邦最高法院,是美国最高级别的联邦法院,为美国三权继总统、国会后最为重要的一环。根据1789年《美国宪法第三条》的规定,最高法院对所有联邦法院、州法院和涉及联邦法律问题的诉讼案件具有最终(并且在很大程度上是有斟酌决定权的)上诉管辖权,以及对小范围案件的具有初审管辖权。在美国的法律制度中,最高法院通常是包括《美国宪法》在内的联邦法律的最终解释者,但仅在具有管辖权的案件范围内。法院不享有判定政治问题的权力;政治问题的执法机关是行政机关,而不是政府的司法部门。
"""
>>> splitter.split(paragraph)
[
    '美国最高法院(英语:Supreme Court of the United States),一般是指美国联邦最高法院,是美国最高级别的联邦法院,为美国三权继总统、国会后最为重要的一环。',
    '根据1789年《美国宪法第三条》的规定,最高法院对所有联邦法院、州法院和涉及联邦法律问题的诉讼案件具有最终(并且在很大程度上是有斟酌决定权的)上诉管辖权,以及对小范围案件的具有初审管辖权。',
    '在美国的法律制度中,最高法院通常是包括《美国宪法》在内的联邦法律的最终解释者,但仅在具有管辖权的案件范围内。',
    '法院不享有判定政治问题的权力;政治问题的执法机关是行政机关,而不是政府的司法部门。'
]

Normalizer

# To normalize text
>>> from icu_tokenizer import Normalizer
>>> normalizer = Normalizer(lang='en', norm_puncts=True)

>>> text = "𝑻𝒉𝒆 𝒑𝒓𝒐𝒅𝒖𝒄𝒕𝒔 𝒚𝒐𝒖 𝒐𝒓𝒅𝒆𝒓𝒆𝒅 𝒘𝒊𝒍𝒍 𝒃𝒆 𝒔𝒉𝒊𝒑𝒑𝒆𝒅 𝒅𝒊𝒓𝒆𝒄𝒕𝒍𝒚 𝒇𝒓𝒐𝒎 𝑲𝒐𝒓𝒆𝒂."
>>> normalizer.normalize(text)
"The products you ordered will be shipped directly from Korea."

>>> text = "【】()"
>>> normalizer.normalize(text)
"[]()"

Tokenizer

>>> from icu_tokenizer import Tokenizer
>>> tokenizer = Tokenizer(lang='th')

>>> text = "ภาษาไทยเป็นภาษาที่มีระดับเสียงของคำแน่นอนหรือวรรณยุกต์เช่นเดียวกับภาษาจีน และออกเสียงแยกคำต่อคำ"
>>> tokenizer.tokenize(text)
['ภาษา', 'ไทย', 'เป็น', 'ภาษา', 'ที่', 'มี', 'ระดับ', 'เสียง', 'ของ', 'คำ', 'แน่นอน', 'หรือ', 'วรรณยุกต์', 'เช่น', 'เดียว', 'กับ', 'ภาษา', 'จีน', 'และ', 'ออก', 'เสียง', 'แยก', 'คำ', 'ต่อ', 'คำ']

Download files

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

Source Distribution

icu_tokenizer-0.0.1.tar.gz (11.2 kB view details)

Uploaded Source

File details

Details for the file icu_tokenizer-0.0.1.tar.gz.

File metadata

  • Download URL: icu_tokenizer-0.0.1.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.4.0.post20200518 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for icu_tokenizer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 0430f5191697904168769938fe3533ddd12e8afd5d84d43e852e9aee4a8b2447
MD5 ae6f7955f673c7313e67fe205fdeba39
BLAKE2b-256 2636d4fdf94a2b58135d4df4b9c12c9602e18a6e1f0267e60802c3bf455e530d

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 file

Supported by

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