sc_crawler.str_utils
Functions:
- wrap – Wrap string between before/after strings (default to spaces) if not empty.
- space_after – Add space after string if not empty.
- snake_case – Convert CamelCase to snake_case.
- plural – Super basic implementation of pluralizing an English word.
- extract_last_number – Extract the last non-negative number from a string.
func wrap
wrap(text, before=' ', after=' ')
Wrap string between before/after strings (default to spaces) if not empty.
Parameters:
- text (
str) – A string. - before (
str) – Characters to be added before thetext. - after (
str) – Characters to be added after thetext.
func space_after
space_after(text)
Add space after string if not empty.
func snake_case
snake_case(text)
Convert CamelCase to snake_case.
Parameters:
- text (
str) – A CamelCase text.
Returns:
str– snake_case version of the text.
Examples:
>>> snake_case('DescriptionToComment')
'description_to_comment'
func plural
plural(text)
Super basic implementation of pluralizing an English word.
Note that grammar exceptions are not handled, so better to use a proper NLP method for real use-cases.
Parameters:
- text (
str) – A singular noun.
Returns:
str– Plural form of the noun.
Examples:
>>> plural('dog')
'dogs'
>>> plural('boy') # :facepalm:
'boies'
func extract_last_number
extract_last_number(text)
Extract the last non-negative number from a string.
Parameters:
- text (
str) – The input string from which to extract the number.
Returns:
Union[float, None]– The last non-negative number found in the string, or None if no number is found.
Examples:
>>> extract_last_number("foo42")
42.0
>>> extract_last_number("foo24.42bar")
24.42