{"id":19505597,"url":"https://github.com/diasks2/pragmatic_tokenizer","last_synced_at":"2025-04-05T18:12:02.160Z","repository":{"id":55129055,"uuid":"49049674","full_name":"diasks2/pragmatic_tokenizer","owner":"diasks2","description":"A multilingual tokenizer to split a string into tokens","archived":false,"fork":false,"pushed_at":"2024-08-11T21:25:01.000Z","size":317,"stargazers_count":91,"open_issues_count":11,"forks_count":11,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-29T17:11:15.207Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/diasks2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-01-05T07:30:08.000Z","updated_at":"2025-01-18T04:57:49.000Z","dependencies_parsed_at":"2024-11-10T22:33:28.000Z","dependency_job_id":"ea923ab1-c531-48bc-ace8-d5e90d543bc7","html_url":"https://github.com/diasks2/pragmatic_tokenizer","commit_stats":{"total_commits":186,"total_committers":6,"mean_commits":31.0,"dds":0.5,"last_synced_commit":"64e45d955a4bba0cd477e34033d21f62552e2786"},"previous_names":[],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diasks2%2Fpragmatic_tokenizer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diasks2%2Fpragmatic_tokenizer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diasks2%2Fpragmatic_tokenizer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diasks2%2Fpragmatic_tokenizer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/diasks2","download_url":"https://codeload.github.com/diasks2/pragmatic_tokenizer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247378152,"owners_count":20929297,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T22:32:09.478Z","updated_at":"2025-04-05T18:12:02.140Z","avatar_url":"https://github.com/diasks2.png","language":"Ruby","funding_links":[],"categories":["NLP Pipeline Subtasks"],"sub_categories":["Segmentation"],"readme":"# Pragmatic Tokenizer\n\n[![Gem Version](https://badge.fury.io/rb/pragmatic_tokenizer.svg)](https://badge.fury.io/rb/pragmatic_tokenizer) [![Build Status](https://travis-ci.org/diasks2/pragmatic_tokenizer.png)](https://travis-ci.org/diasks2/pragmatic_tokenizer) [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/diasks2/pragmatic_tokenizer/blob/master/LICENSE.txt)\n\nPragmatic Tokenizer is a multilingual tokenizer to split a string into tokens.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n**Ruby**  \n```\ngem install pragmatic_tokenizer\n```\n\n**Ruby on Rails**  \nAdd this line to your application’s Gemfile:  \n```ruby \ngem 'pragmatic_tokenizer'\n```\n\n## Usage\n\n* If no language is specified, the library will default to English.   \n* To specify a language use its two character [ISO 639-1 code](https://www.tm-town.com/languages).\n* Pragmatic Tokenizer will unescape any HTML entities.\n\n**Example Usage**\n```ruby\ntext = \"\\\"I said, 'what're you? Crazy?'\\\" said Sandowsky. \\\"I can't afford to do that.\\\"\"\n\nPragmaticTokenizer::Tokenizer.new.tokenize(text)\n# =\u003e [\"\\\"\", \"i\", \"said\", \",\", \"'\", \"what're\", \"you\", \"?\", \"crazy\", \"?\", \"'\", \"\\\"\", \"said\", \"sandowsky\", \".\", \"\\\"\", \"i\", \"can't\", \"afford\", \"to\", \"do\", \"that\", \".\", \"\\\"\"]\n\n# You can pass many different options to #initialize:\noptions = {\n  language:            :en, # the language of the string you are tokenizing\n  abbreviations:       ['a.b', 'a'], # a user-supplied array of abbreviations (downcased with ending period removed)\n  stop_words:          ['is', 'the'], # a user-supplied array of stop words (downcased)\n  remove_stop_words:   true, # remove stop words\n  contractions:        { \"i'm\" =\u003e \"i am\" }, # a user-supplied hash of contractions (key is the contracted form; value is the expanded form - both the key and value should be downcased)\n  expand_contractions: true, # (i.e. [\"isn't\"] will change to two tokens [\"is\", \"not\"])\n  filter_languages:    [:en, :de], # process abbreviations, contractions and stop words for this array of languages\n  punctuation:         :none, # see below for more details\n  numbers:             :none, # see below for more details\n  remove_emoji:        :true, # remove any emoji tokens\n  remove_urls:         :true, # remove any urls\n  remove_emails:       :true, # remove any emails\n  remove_domains:      :true, # remove any domains\n  hashtags:            :keep_and_clean, # remove the hastag prefix\n  mentions:            :keep_and_clean, # remove the @ prefix\n  clean:               true, # remove some special characters\n  classic_filter:      true, # removes dots from acronyms and 's from the end of tokens\n  downcase:            false, # do not downcase tokens\n  minimum_length:      3, # remove any tokens less than 3 characters\n  long_word_split:     10 # split tokens longer than 10 characters at hypens or underscores\n}\n```\n\n**Options**  \n\n##### `language`\n  **default** = `'en'`\n- To specify a language use its two character [ISO 639-1 code](https://www.tm-town.com/languages) as a symbol (i.e. `:en`) or string (i.e. `'en'`)\n\n\u003chr\u003e\n\n##### `abbreviations`\n  **default** = `nil`\n- You can pass an array of abbreviations to overide or compliment the abbreviations that come stored in this gem. Each element of the array should be a downcased String with the ending period removed.\n\n\u003chr\u003e\n\n##### `stop_words`\n  **default** = `nil`\n- You can pass an array of stop words to overide or compliment the stop words that come stored in this gem. Each element of the array should be a downcased String.\n\n\u003chr\u003e\n\n##### `contractions`\n  **default** = `nil`\n- You can pass a hash of contractions to overide or compliment the contractions that come stored in this gem. Each key is the contracted form downcased and each value is the expanded form downcased.\n\n\u003chr\u003e\n\n##### `remove_stop_words`\n  **default** = `false`\n- `true`  \n  Removes all stop words.\n- `false`   \n  Does not remove stop words.\n\n\u003chr\u003e\n\n##### `expand_contractions`\n  **default** = `false`\n- `true`  \n  Expands contractions (i.e. i'll -\u003e i will).\n- `false`   \n  Leaves contractions as is.\n\n\u003chr\u003e\n\n##### `filter_languages`\n  **default** = `nil`\n- You can pass an array of languages of which you would like to process abbreviations, stop words and contractions. This language can be indepedent of the language of the string you are tokenizing (for example your text might be German but contain some English stop words that you want to remove). If you supply your own abbreviations, stop words or contractions they will be merged with the abbreviations, stop words and contractions of any languages you add in this option. You can pass an array of symbols or strings (i.e. `[:en, :de]` or `['en', 'de']`)\n\n\u003chr\u003e\n\n##### `punctuation`\n  **default** = `'all'`\n- `:all`  \n  Does not remove any punctuation from the result.\n- `:semi`   \n  Removes full stops (i.e. periods) ['。', '．', '.'].\n- `:none`  \n  Removes all punctuation from the result.\n- `:only`  \n  Removes everything except punctuation. The returned result is an array of only the punctuation.\n\n\u003chr\u003e\n\n##### `numbers`\n  **default** = `'all'`\n- `:all`  \n  Does not remove any numbers from the result\n- `:semi`   \n  Removes tokens that include only digits\n- `:none`  \n  Removes all tokens that include a number from the result (including Roman numerals)\n- `:only`  \n  Removes everything except tokens that include a number\n\n\u003chr\u003e\n\n##### `remove_emoji`\n  **default** = `false`\n- `true`  \n  Removes any token that contains an emoji.\n- `false`   \n  Leaves tokens as is.\n\n\u003chr\u003e\n\n##### `remove_urls`\n  **default** = `false`\n- `true`  \n  Removes any token that contains a URL.\n- `false`   \n  Leaves tokens as is.\n\n\u003chr\u003e\n\n##### `remove_domains`\n  **default** = `false`\n- `true`  \n  Removes any token that contains a domain.\n- `false`   \n  Leaves tokens as is.\n\n\u003chr\u003e\n\n##### `remove_domains`\n  **default** = `false`\n- `true`  \n  Removes any token that contains a domain.\n- `false`   \n  Leaves tokens as is.\n\n\u003chr\u003e\n\n##### `clean`\n  **default** = `false`\n- `true`  \n  Removes tokens consisting of only hypens, underscores, or periods as well as some special characters (®, ©, ™). Also removes long tokens or tokens with a backslash.\n- `false`   \n  Leaves tokens as is.\n\n\u003chr\u003e\n\n##### `hashtags`\n  **default** = `:keep_original`\n- `:keep_original`  \n  Does not alter the token at all.\n- `:keep_and_clean`   \n  Removes the hashtag (#) prefix from the token.\n- `:remove`   \n  Removes the token completely.\n\n\u003chr\u003e\n\n##### `mentions`\n  **default** = `:keep_original`\n- `:keep_original`  \n  Does not alter the token at all.\n- `:keep_and_clean`   \n  Removes the mention (@) prefix from the token.\n- `:remove`   \n  Removes the token completely.\n\n\u003chr\u003e\n\n##### `classic_filter`\n  **default** = `false`\n- `true`  \n  Removes dots from acronyms and 's from the end of tokens.\n- `false`   \n  Leaves tokens as is.\n\n\u003chr\u003e\n\n##### `downcase`\n  **default** = `true`\n\n\u003chr\u003e\n\n##### `minimum_length`\n  **default** = `0`  \n  The minimum number of characters a token should be.  \n\n\u003chr\u003e\n\n##### `long_word_split`\n  **default** = `nil`  \n  The number of characters after which a token should be split at hypens or underscores.\n\n## Language Support\n\nThe following lists the current level of support for different languages. Pull requests or help for any languages that are not fully supported would be greatly appreciated.  \n\n*N.B. - contractions might not be applicable for all languages below - in that case the CONTRACTIONS hash should stay empty.*  \n\n##### English\nSpecs: Yes  \nAbbreviations: Yes  \nStop Words: Yes  \nContractions: Yes  \n\n##### Arabic\nSpecs: No  \nAbbreviations: Yes  \nStop Words: Yes  \nContractions: No  \n\n##### Bulgarian\nSpecs: More needed   \nAbbreviations: Yes  \nStop Words: Yes  \nContractions: No  \n\n##### Catalan\nSpecs: No  \nAbbreviations: No  \nStop Words: Yes  \nContractions: No  \n\n##### Czech\nSpecs: No  \nAbbreviations: No  \nStop Words: Yes  \nContractions: No  \n\n##### Danish\nSpecs: No  \nAbbreviations: No  \nStop Words: Yes  \nContractions: No  \n\n##### Deutsch\nSpecs: More needed  \nAbbreviations: Yes  \nStop Words: Yes  \nContractions: No  \n\n##### Finnish\nSpecs: No  \nAbbreviations: No  \nStop Words: Yes  \nContractions: No  \n\n##### French\nSpecs: More needed  \nAbbreviations: Yes  \nStop Words: Yes  \nContractions: No  \n\n##### Greek\nSpecs: No  \nAbbreviations: No  \nStop Words: Yes  \nContractions: No  \n\n##### Indonesian\nSpecs: No  \nAbbreviations: No  \nStop Words: Yes  \nContractions: No  \n\n##### Italian\nSpecs: No  \nAbbreviations: Yes  \nStop Words: Yes  \nContractions: No  \n\n##### Latvian\nSpecs: No  \nAbbreviations: No  \nStop Words: Yes  \nContractions: No  \n\n##### Norwegian\nSpecs: No  \nAbbreviations: No  \nStop Words: Yes  \nContractions: No  \n\n##### Persian\nSpecs: No  \nAbbreviations: No  \nStop Words: Yes  \nContractions: No  \n\n##### Polish\nSpecs: No  \nAbbreviations: Yes  \nStop Words: Yes  \nContractions: No  \n\n##### Portuguese\nSpecs: No  \nAbbreviations: No  \nStop Words: Yes  \nContractions: No  \n\n##### Romanian\nSpecs: No  \nAbbreviations: No  \nStop Words: Yes  \nContractions: No  \n\n##### Russian\nSpecs: No  \nAbbreviations: Yes  \nStop Words: Yes  \nContractions: No  \n\n##### Slovak\nSpecs: No  \nAbbreviations: No  \nStop Words: Yes  \nContractions: No  \n\n##### Spanish\nSpecs: No  \nAbbreviations: Yes  \nStop Words: Yes  \nContractions: Yes  \n\n##### Swedish\nSpecs: No  \nAbbreviations: No  \nStop Words: Yes  \nContractions: No  \n\n##### Turkish\nSpecs: No  \nAbbreviations: No  \nStop Words: Yes  \nContractions: No  \n\n## Resources\n\n* [The Art of Tokenization](https://www.ibm.com/developerworks/community/blogs/nlp/entry/tokenization?lang=en)\n* [Handbook Of Natural Language Processing Second Edition](https://karczmarczuk.users.greyc.fr/TEACH/TAL/Doc/Handbook%20Of%20Natural%20Language%20Processing,%20Second%20Edition%20Chapman%20\u0026%20Hall%20Crc%20Machine%20Learning%20\u0026%20Pattern%20Recognition%202010.pdf)\n\n## Contributing\n\n1. Fork it ( https://github.com/diasks2/pragmatic_tokenizer/fork )\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2016 Kevin S. Dias\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiasks2%2Fpragmatic_tokenizer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiasks2%2Fpragmatic_tokenizer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiasks2%2Fpragmatic_tokenizer/lists"}