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
Installation
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file capitalise-delimit-0.1.1.tar.gz.
File metadata
- Download URL: capitalise-delimit-0.1.1.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ece8f142fd620328c41b3d1a4279c0a4677f446cf5066c64877865c8ca7fde6
|
|
| MD5 |
c090e22c777c14aae8c7b66b4ec12424
|
|
| BLAKE2b-256 |
c9a250aeaa370c440ed3bf91741666e97bd98b2c4b2298165264481210e65a14
|
File details
Details for the file capitalise_delimit-0.1.1-py3-none-any.whl.
File metadata
- Download URL: capitalise_delimit-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4651335764e9d6a9b5ee2375471620a2fbc5b1be5b3ed492fb2c8871ccfb924c
|
|
| MD5 |
a78b270abef50e8d600056c1b3a19568
|
|
| BLAKE2b-256 |
ea3bba9ff3d2fa66248b970ba0e07f334d1affaaec723fae543e0a16e9512551
|