Skip to main content

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.1.4

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.1.4
File Size Uploaded
polyglot-tokenizer-2.0.1.4.tar.gz 101.1 kB Details

Built distribution (wheel)

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

Total release size: 422.9 kB

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

Download URL polyglot-tokenizer-2.0.1.4.tar.gz
Size 101.1 kB
Tags Source
SHA-256 checksum
How to use checksums
22db75fc256286d74dc4f9260bdfac5f81ab906b6db5f6128d6be05790f0eae3
BLAKE2b-256 checksum
How to use checksums
a621bc881d90d6f499c886412938a36391044585db10fea0f539af3d3d39588a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.11 CPython/2.7.12 Linux/4.15.0-43-generic

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

Download URL polyglot_tokenizer-2.0.1.4-py2.py3-none-any.whl
Size 321.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
9f6f3de28fb52d0161acadb6c072229eabcbb3c0a3c46c278c93b1da3dccfa08
BLAKE2b-256 checksum
How to use checksums
aa3037ce725b650240b390bcf4c509c9edb80e754810e361153e93447dd2e703
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/0.12.11 CPython/2.7.12 Linux/4.15.0-43-generic

Release history Release notifications | RSS feed

2.0.2

2 release files

This release

2.0.1.4 This release

2 release files

2.0.1

2 release files

2.0.0

2 release files

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