Skip to main content

Probabilistically split concatenated words across 90 languages — incl. English, Spanish, French, German, Italian, Portuguese, Russian, Hebrew, Chinese, Japanese, Korean, Vietnamese, Arabic, Hindi, Bengali, Tamil, Telugu, Thai, Greek, Turkish, Polish, Dutch, Swedish, Norwegian, Finnish, Marathi, Punjabi, Gujarati, Kannada, Burmese, Swahili, Amharic, Welsh, Breton, Mongolian and 50+ more

Project description

image

Word Ninja

Slice your munged together words! Seriously, Take anything, 'imateapot' for example, would become ['im', 'a', 'teapot']. Useful for humanizing stuff (like database tables when people don't like underscores).

This project is repackaging the excellent work from here: http://stackoverflow.com/a/11642687/2449774

Usage

$ python
>>> import wordninja
>>> wordninja.split('derekanderson')
['derek', 'anderson']
>>> wordninja.split('imateapot')
['im', 'a', 'teapot']
>>> wordninja.split('heshotwhointhewhatnow')
['he', 'shot', 'who', 'in', 'the', 'what', 'now']
>>> wordninja.split('thequickbrownfoxjumpsoverthelazydog')
['the', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog']

Performance

It's super fast!

>>> def f():
...   wordninja.split('imateapot')
... 
>>> timeit.timeit(f, number=10000)
0.40885152100236155

It can handle long strings:

>>> wordninja.split('wethepeopleoftheunitedstatesinordertoformamoreperfectunionestablishjusticeinsuredomestictranquilityprovideforthecommondefencepromotethegeneralwelfareandsecuretheblessingsoflibertytoourselvesandourposteritydoordainandestablishthisconstitutionfortheunitedstatesofamerica')
['we', 'the', 'people', 'of', 'the', 'united', 'states', 'in', 'order', 'to', 'form', 'a', 'more', 'perfect', 'union', 'establish', 'justice', 'in', 'sure', 'domestic', 'tranquility', 'provide', 'for', 'the', 'common', 'defence', 'promote', 'the', 'general', 'welfare', 'and', 'secure', 'the', 'blessings', 'of', 'liberty', 'to', 'ourselves', 'and', 'our', 'posterity', 'do', 'ordain', 'and', 'establish', 'this', 'constitution', 'for', 'the', 'united', 'states', 'of', 'america']

And scales well. (This string takes ~7ms to compute.)

How to Install

pip3 install wordninja

Custom Language Models

#1 most requested feature! If you want to do something other than english (or want to specify your own model of english), this is how you do it.

>>> lm = wordninja.LanguageModel('my_lang.txt.gz')
>>> lm.split('derek')
['der','ek']

Language files must be gziped text files with one word per line in decreasing order of probability.

If you want to make your model the default, set:

wordninja.DEFAULT_LANGUAGE_MODEL = wordninja.LanguageModel('my_lang.txt.gz')

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

wordninja_pp-0.3.1.tar.gz (14.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wordninja_pp-0.3.1-py3-none-any.whl (14.4 MB view details)

Uploaded Python 3

File details

Details for the file wordninja_pp-0.3.1.tar.gz.

File metadata

  • Download URL: wordninja_pp-0.3.1.tar.gz
  • Upload date:
  • Size: 14.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for wordninja_pp-0.3.1.tar.gz
Algorithm Hash digest
SHA256 f830763d317e361124f3ccbdc9c272b0b80c5b61ab1be15297737ceebeaef67d
MD5 fc62dc51565abdb2596e9bca75875d38
BLAKE2b-256 df004334fcccc66967f2c876d5c3ff27a310664ebf691f2dc8870dfe878d5dee

See more details on using hashes here.

File details

Details for the file wordninja_pp-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: wordninja_pp-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 14.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for wordninja_pp-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 63ec1f85120611f6fb370d4093fcbf3a3d1cbc2fdf5fdf863d398cf9bd4d3edc
MD5 1fdddffc23c088701e7a223578c943f7
BLAKE2b-256 f9edb0eb9be6ee68e39d2689fa4d8d1663763fbb77f71d66ce171e2926603a9c

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