Primed Toolkit

Build Status Coverage Status Documentation Status Requirements Status PyPI version PyPI license

General utility and NLP functions. Currently under development, so use at your own risk. Tests and thorough documentation will be added at some point (meaning probably never, but I will bear it in mind).

Installation

Simply use pip:

pip install primed --upgrade

Then, import the module:

import primed as ptk

NLP Examples

Text should ideally be cleaned first (i.e. free of punctuation). You can use ptk.clean().

Clean text

Removes extra spaces, punctuation, and optionally lowers the text. Careful using this if parsing for names, countries, smileys etc.

ptk.clean('Ha, this   is fun! YUP!!!', lower=True)

Case-insensitive replace

Possibly the fastest method for a case-insensitive replace, tested against both using an arrayed string and using re.

ptk.ireplace('I want a hIPpo for my birthday', 'hippo', 'giraffe')

Get all (x to y) grams

Returns a dictionary of the ngrams with counts. Possibly the fastest method when compared with itertools, textblob, sklearn, and nltk.

ptk.ngrams('I love cats meow like really really love cats', min_grams=1, max_grams=10)

Create a comma-separated string using the Oxford comma

Because this is the grammatically correct way…

ptk.oxfordize(['cats', 'kittens', 'quantum', 'simulation'])

Capitalize i’s

Pretty elementary implementation, included just in case.

ptk.capi('i am british, and i also codify things.')

Correct a / an select

Uses the Carnegie Mellon University Pronouncing Dictionary (CMUdict), based on the DoD ARPAbet. Currently uses a naive fall-back; a better alternative would be to guess / learn using existing words in CMUdict.

ptk.a('university')

Convert to snake text

Existing underscores are preserved.

ptk.snake('Hello  There! ')

Convert to Wikipedia URI

Naive implementation for now, hoping redirects will help with the majority of capitalization issues for words subsequent to the first.

ptk.wiki_uri('DELTA-V Budget')

Utility Examples

Colourful printing

ptk.cprint('Text or object to be stringified', style='OK', bold=True, underline=True, newline=True)

Styles available:

'OK':    '\033[92m'
'INFO':  '\033[94m'
'WARN':  '\033[93m'
'ERROR': '\033[91m'
'FATAL': '\033[31m'

Notes

keeper

Using string.translate is quicker than using regular expressions (see https://stackoverflow.com/a/26517161/2178980).