Text
cognite.pygen.utils.text
as_plural(noun)
Pluralize a noun.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
noun
|
str
|
The noun to pluralize. |
required |
Returns: The pluralized noun.
Examples:
>>> as_plural('person')
'persons'
>>> as_plural('Roles')
'Roles'
>>> as_plural('activity')
'activities'
Source code in cognite/pygen/utils/text.py
as_singular(noun)
Singularize a noun.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
noun
|
str
|
The noun to singularize. |
required |
Returns: The singularized noun.
Examples:
Source code in cognite/pygen/utils/text.py
create_name(raw_name, naming, python_variable=True)
Create a name from a raw name and following the given naming convention.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw_name
|
str
|
The raw string to convert. |
required |
naming
|
Naming
|
The naming convention to follow. |
required |
python_variable
|
bool
|
Whether to convert to a valid Python variable name. |
True
|
Returns:
Type | Description |
---|---|
str
|
The converted name. |
Source code in cognite/pygen/utils/text.py
to_camel(string, pluralize=False, singularize=False)
Convert snake_case_name to camelCaseName.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string
|
str
|
The string to convert. |
required |
pluralize
|
bool
|
Whether to pluralize the last word. |
False
|
singularize
|
bool
|
Whether to singularize the last word. |
False
|
Returns: camelCase of the input string.
Examples:
>>> to_camel("a_b")
'aB'
>>> to_camel('camel_case', pluralize=True)
'camelCases'
>>> to_camel('best_directors', singularize=True)
'bestDirector'
>>> to_camel("ScenarioInstance_priceForecast")
'scenarioInstancePriceForecast'
Source code in cognite/pygen/utils/text.py
to_pascal(string, pluralize=False, singularize=False)
Convert string to PascalCaseName.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string
|
str
|
The string to convert. |
required |
pluralize
|
bool
|
Whether to pluralize the last word. |
False
|
singularize
|
bool
|
Whether to singularize the last word. |
False
|
Returns: PascalCase of the input string.
Examples:
>>> to_pascal("a_b")
'AB'
>>> to_pascal('camel_case', pluralize=True)
'CamelCases'
>>> to_pascal('best_directors', singularize=True)
'BestDirector'
>>> to_pascal("BestLeadingActress", singularize=True)
'BestLeadingActress'
>>> to_pascal("priceScenarios", pluralize=True)
'PriceScenarios'
>>> to_pascal("reserveScenarios", pluralize=True)
'ReserveScenarios'
>>> to_pascal("ScenarioInstance_priceForecast")
'ScenarioInstancePriceForecast'
Source code in cognite/pygen/utils/text.py
to_snake(string, pluralize=False, singularize=False)
Convert input string to snake_case
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string
|
str
|
The string to convert. |
required |
pluralize
|
bool
|
Whether to pluralize the last word. |
False
|
singularize
|
bool
|
Whether to singularize the last word. |
False
|
Returns: snake_case of the input string.
Examples:
>>> to_snake("aB")
'a_b'
>>> to_snake('CamelCase')
'camel_case'
>>> to_snake('camelCamelCase')
'camel_camel_case'
>>> to_snake('Camel2Camel2Case')
'camel_2_camel_2_case'
>>> to_snake('getHTTPResponseCode')
'get_http_response_code'
>>> to_snake('get200HTTPResponseCode')
'get_200_http_response_code'
>>> to_snake('getHTTP200ResponseCode')
'get_http_200_response_code'
>>> to_snake('HTTPResponseCode')
'http_response_code'
>>> to_snake('ResponseHTTP')
'response_http'
>>> to_snake('ResponseHTTP2')
'response_http_2'
>>> to_snake('Fun?!awesome')
'fun_awesome'
>>> to_snake('Fun?!Awesome')
'fun_awesome'
>>> to_snake('10CoolDudes')
'10_cool_dudes'
>>> to_snake('20coolDudes')
'20_cool_dudes'
>>> to_snake('BestDirector', pluralize=True)
'best_directors'
>>> to_snake('BestDirectors', singularize=True)
'best_director'
>>> to_snake('BestLeadingActress', pluralize=True)
'best_leading_actresses'
>>> to_snake('APM_Activity', pluralize=True)
'apm_activities'
>>> to_snake('APM_Activities', singularize=True)
'apm_activity'
>>> to_snake('APM_Operation', pluralize=True)
'apm_operations'
>>> to_snake('APM_Asset', pluralize=True)
'apm_assets'
>>> to_snake('APM_Material', pluralize=True)
'apm_materials'
Source code in cognite/pygen/utils/text.py
to_words(string, pluralize=False, singularize=False)
Convert input string to words
Parameters:
Name | Type | Description | Default |
---|---|---|---|
string
|
str
|
The string to convert. |
required |
pluralize
|
bool
|
Whether to pluralize the last word. |
False
|
singularize
|
bool
|
Whether to singularize the last word. |
False
|
Returns: words of the input string.
Examples:
>>> to_words("aB")
'a b'
>>> to_words('CamelCase')
'camel case'
>>> to_words('APM_Activity', pluralize=True)
'apm activities'
>>> to_words('APM_Activities', singularize=True)
'apm activity'