flexmeasures.utils.flexmeasures_inflection

FlexMeasures way of handling inflection

Functions

flexmeasures.utils.flexmeasures_inflection.atoi(text)

Utility method for the natural_keys method.

flexmeasures.utils.flexmeasures_inflection.capitalize(x: str, lower_case_remainder: bool = False) str

Capitalize string with control over whether to lower case the remainder.

flexmeasures.utils.flexmeasures_inflection.human_sorted(alist: list, attr: Any | None = None, reverse: bool = False)

Human sort a list (for example, a list of strings or dictionaries).

Parameters:
  • alist – List to be sorted.

  • attr – Optionally, pass a dictionary key or attribute name to sort by

  • reverse – If True, sorts descending.

Example: >>> alist = [“PV 10”, “CP1”, “PV 2”, “PV 1”, “CP 2”] >>> sorted(alist) [‘CP 2’, ‘CP1’, ‘PV 1’, ‘PV 10’, ‘PV 2’] >>> human_sorted(alist) [‘CP1’, ‘CP 2’, ‘PV 1’, ‘PV 2’, ‘PV 10’]

flexmeasures.utils.flexmeasures_inflection.humanize(word)
flexmeasures.utils.flexmeasures_inflection.join_words_into_a_list(words: list[str]) str
flexmeasures.utils.flexmeasures_inflection.natural_keys(text: str)

Support for human sorting.

alist.sort(key=natural_keys) sorts in human order.

https://stackoverflow.com/a/5967539/13775459

flexmeasures.utils.flexmeasures_inflection.parameterize(word)

Parameterize the word, so it can be used as a python or javascript variable name. For example: >>> word = “Acme® EV-Charger™” “acme_ev_chargertm”

flexmeasures.utils.flexmeasures_inflection.pluralize(word, count: str | int | None = None)
flexmeasures.utils.flexmeasures_inflection.titleize(word)

Acronym exceptions are not yet supported by the inflection package, even though Ruby on Rails, of which the package is a port, does.

In most cases it’s probably better to use our capitalize function instead of titleize, because it has less unintended side effects. For example:

>>> word = "two PV panels"
>>> titleize(word)
"Two Pv Panels"
>>> capitalize(word)
"Two PV panels"