Skip to main content

Polyglot Tokenizer

Tokenizer for world’s most spoken languages and social media texts like Facebook, Twitter etc.

Installation

pip install polyglot-tokenizer

Examples

Within Python

>>> from __future__ import unicode_literals
>>> from polyglot_tokenizer import Tokenizer
>>> tk = Tokenizer(lang='en', smt=True) #smt is a flag for social-media-text
>>> text = "RT @BJP_RSS Crack down on Black money.India slides to 75th slot on Swiss bank money list #ModiForeignAchievements @RituRathaur https://t.c…"
>>> tk.tokenize(text)
['RT', '@BJP_RSS', 'Crack', 'down', 'on', 'Black', 'money', '.', 'India', 'slides', 'to', '75th', 'slot', 'on', 'Swiss', 'bank', 'money', 'list', '#ModiForeignAchievements', '@RituRathaur', 'https://t.c…']
>>> tk = Tokenizer(lang='hi')
>>> tk.tokenize("22 साल के लंबे इंतजार के बाद आखिरकार हॉलीवुड स्टार लियोनार्डो डिकैप्रियो को अपनी पहली ऑस्कर ट्रॉफी"
...             " मिल चुकी है। उन्हें ये अवॉर्ड अपनी फिल्म ‘द रेवेनेंट’ में ह्यूज ग्लास के किरदार के लिए मिला, लेकिन उनके"
...             " के लिए रोल निभाना आसान नहीं था।")
['22', 'साल', 'के', 'लंबे', 'इंतजार', 'के', 'बाद', 'आखिरकार', 'हॉलीवुड', 'स्टार', 'लियोनार्डो', 'डिकैप्रियो', 'को', 'अपनी', 'पहली', 'ऑस्कर', 'ट्रॉफी', 'मिल', 'चुकी', 'है', '।', 'उन्हें', 'ये', 'अवॉर्ड', 'अपनी', 'फिल्म', "'", 'द', 'रेवेनेंट', "'", 'में', 'ह्यूज', 'ग्लास', 'के', 'किरदार', 'के', 'लिए', 'मिला', ',', 'लेकिन', 'उनके', 'के', 'लिए', 'रोल', 'निभाना', 'आसान', 'नहीं', 'था', '।']
>>> tk = Tokenizer(lang='hi', split_sen=True)
>>> tk.tokenize("22 साल के लंबे इंतजार के बाद आखिरकार हॉलीवुड स्टार लियोनार्डो डिकैप्रियो को अपनी पहली ऑस्कर ट्रॉफी"
...             " मिल चुकी है। उन्हें ये अवॉर्ड अपनी फिल्म ‘द रेवेनेंट’ में ह्यूज ग्लास के किरदार के लिए मिला, लेकिन उनके"
...             " के लिए रोल निभाना आसान नहीं था। फिल्म एक सीन के लिए लियोनार्डो को भैंस का कच्चा लीवर खाना"
...             " पड़ा था। जबकि असल जिंदगी में वो पूरी तरह शाकाहारी हैं। हालांकि इस सीन के लिए पहले लियोनार्डो को"
...             " मांस जैसे दिखने वाली चीज दी गई थी, लेकिन उन्हें लगा कि ऐसा करना गलत होगा। फिल्म के लिए इम्पोर्ट"
...             " की गई चीटियां...")
[['22', 'साल', 'के', 'लंबे', 'इंतजार', 'के', 'बाद', 'आखिरकार', 'हॉलीवुड', 'स्टार', 'लियोनार्डो', 'डिकैप्रियो', 'को', 'अपनी', 'पहली', 'ऑस्कर', 'ट्रॉफी', 'मिल', 'चुकी', 'है', '।'], ['उन्हें', 'ये', 'अवॉर्ड', 'अपनी', 'फिल्म', "'", 'द', 'रेवेनेंट', "'", 'में', 'ह्यूज', 'ग्लास', 'के', 'किरदार', 'के', 'लिए', 'मिला', ',', 'लेकिन', 'उनके', 'के', 'लिए', 'रोल', 'निभाना', 'आसान', 'नहीं', 'था', '।'], ['फिल्म', 'एक', 'सीन', 'के', 'लिए', 'लियोनार्डो', 'को', 'भैंस', 'का', 'कच्चा', 'लीवर', 'खाना', 'पड़ा', 'था', '।'], ['जबकि', 'असल', 'जिंदगी', 'में', 'वो', 'पूरी', 'तरह', 'शाकाहारी', 'हैं', '।'], ['हालांकि', 'इस', 'सीन', 'के', 'लिए', 'पहले', 'लियोनार्डो', 'को', 'मांस', 'जैसे', 'दिखने', 'वाली', 'चीज', 'दी', 'गई', 'थी', ',', 'लेकिन', 'उन्हें', 'लगा', 'कि', 'ऐसा', 'करना', 'गलत', 'होगा', '।'], ['फिल्म', 'के', 'लिए', 'इम्पोर्ट', 'की', 'गई', 'चीटियां', '...']]

From Console

polyglot-tokenizer --h

usage: polyglot-tokenizer [-h] [-v] [-i] [-s] [-t] [-o] [-l]

Tokenizer for world's most spoken languages


optional arguments:
  -h, --help            show this help message and exit
  -v, --version         show program's version number and exit
  -i , --input          <input-file>
  -s, --split-sentences
                        set this flag to apply sentence segmentation
  -t, --social-media-test
                        set this flag if the input file contains social media
                        text like twitter, facebook and whatsapp
  -o , --output         <output-file>
  -l , --language       select language (2 letter ISO-639 code) {hi, ur, bn,
                        as, gu, ml, pa, te, ta, kn, or, mr, cu, myv, nn, yi,
                        ne, bo, br, ks, en, es, ca, cs, de, el, en, fi, da,
                        eu, kok, nb, uz, fr, ga, hu, is, it, lt, lv, nl, pl,
                        pt, ro, ru, sk, bm, yue, mk, ku, sl, sv, zh, et, fo,
                        gl, hsb, af, ar, be, hy, bg, ka, ug, hr, mn, tk, kk,
                        ky, la, no, fa, uk, tl, tr, vi, yo, ko, got, ckb, he,
                        id, sr}

Example ::

polyglot-tokenizer < raw_file.txt -l en -s > tokenized.txt

Metadata

Release files for polyglot-tokenizer 2.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polyglot-tokenizer 2.0.2
File Size Uploaded Provenance Actions
polyglot-tokenizer-2.0.2.tar.gz 101.3 kB Without provenance Details for polyglot-tokenizer-2.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for polyglot-tokenizer 2.0.2
File Interpreter ABI Platform Actions
polyglot_tokenizer-2.0.2-py2.py3-none-any.whl Python 2, Python 3 none any Details for polyglot_tokenizer-2.0.2-py2.py3-none-any.whl

Total release size: 424.6 kB

Release files / polyglot-tokenizer-2.0.2.tar.gz

Download URL polyglot-tokenizer-2.0.2.tar.gz
Size 101.3 kB
Tags Source
SHA-256 checksum
How to use checksums
8094a9a4b271cb0ac0ae81ace892d804b6806030bb7c2327810251e33ddafd95
BLAKE2b-256 checksum
How to use checksums
a29e94e64554280a3636d4e9ad1185d7aed3d1919981885b9f3756578dee19d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.7 CPython/3.8.5 Linux/5.4.0-74-generic

Release files / polyglot_tokenizer-2.0.2-py2.py3-none-any.whl

Download URL polyglot_tokenizer-2.0.2-py2.py3-none-any.whl
Size 323.3 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
0ddb1101fa212c35795ca916adc02436e4ea7723182449fab5185f8f94caf873
BLAKE2b-256 checksum
How to use checksums
e4d21338a204f5035015d54caa765478a0ceb8d806dceed150f45263f9d3ff98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.7 CPython/3.8.5 Linux/5.4.0-74-generic

Security for polyglot-tokenizer 2.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page