Skip to main content

Capitalise string by delimiters

Project description

capitalise-delimit

A python library to capitalise words in a string based on a list of given delimiters. This is quite a niche solution but

is useful when capitalising proper nouns that contain multiple different delimiting characters. An example might be

double barreled names, e.g. where jim-bob joe needs to become Jim-Bob Joe

PyPI build can be found here.

Installation

Install this library using


pip install capitalise-delimit

or via PyPI, which is linked above.

Get started

To use the library, simply import and create an instance of the CapitaliseDelimit object, which can be used to access

this library's functionality. You will need to instantiate this class with a list of delimiters that strings using this

class will be split by when being capitalised. Currently, the only supported functionality is the capitalise function.

>>> from capitalise_delimit import CapitaliseDelimit

>>> my_str = 'a sample string'

>>> capitalise_space = CapitaliseDelimit([' '])

>>> capitalise_space.capitalise(my_str)

'A Sample String'

Another example:

>>> name = 'jim-bob joe'

>>> CD_space_hyphen = CapitaliseDelimit([' ', '-'])

>>> CD_space_hyphen.capitalise(name)

'Jim-Bob Joe'

Ignore syncategorematic words

The library provides a defined list of words that can be ignored when capitalising the string. The current list of words

is:

  • upon
  • at
  • the
  • on
  • in

These words are useful mostly when capitalising place names, such as Stratford-upon-Avon. Capitalising this normally

would look like

>>> capitalise_hyphen = CapitaliseDelimit(['-'])

>>> capitalise_hyphen.capitalise('stratford-upon-avon')

'Stratford-Upon-Avon'

However, if we don't want 'upon' to be capitalised, we can supply True as the ignore_words named parameter

>>> capitalise_hyphen.capitalise('stratford-upon-avon', ignore_words=True)

'Stratford-upon-Avon'

If the predefined list of words does not fully suit your needs, you can add a custom list of words using

the custom_ignore_words parameter. Note that this can be used on its own to define a purely custom list, or in

conjunction with ignore_words if you simply want to add some extra words on top of the existing list.

Please also note that when passing a custom list of words, this is saved and used for future capitalisations called on

that instance. The custom list must therefore be kept attention of, and can be updated upon every call of

capitalise(). To reset the custom list, simply pass in an empty list or set when you next call .capitalise(). The

value provided for ignore_words is also remembered, so if you supply the value True when invoking .capitalise(),

all following capitalisation using the same class instance will run with ignore_words=True until it is manually

set back to False.

Footnote

This is my first publicly available python package, so please forgive any naïve mistakes. In fact, if you can be

bothered taking the time to let me know, I am more than happy to take on any constructive criticism.

I do plan on adding features once I think of some that may be relevant. Any feature suggestions are more than welcome.

Thanks for checking out my package :)

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

capitalise-delimit-0.1.2.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

capitalise_delimit-0.1.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file capitalise-delimit-0.1.2.tar.gz.

File metadata

  • Download URL: capitalise-delimit-0.1.2.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.12

File hashes

Hashes for capitalise-delimit-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7d120a14ce895a1459f91d301051d83d30d9e47f64141c43ea1bbb52fc58a41f
MD5 5e9e27c533eab1f770831b97735f90dc
BLAKE2b-256 eb92285d441527722584c033e4e29c8955da9bc624368b04e8017a5f40bb126f

See more details on using hashes here.

File details

Details for the file capitalise_delimit-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for capitalise_delimit-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b1f8f264599119e0df19442f73c9c9302c4f9a8765376acedaa36cfb3f0fc814
MD5 ef7df793c19a59b17d89b177dcd575b3
BLAKE2b-256 3fd59bd9a3f040b33d1332d84e480e620805b63c6fdd15f42d7bbff9997537fb

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