AliasSpace

class aliases.space.AliasSpace(data, processor=None, name=None)

The alias space stores information on existing aliases

Parameters:
  • data (dict[str, list[str]]) – A dictionary where the keys are the preferred forms of strings and the values are lists of aliases

  • processor (Optional[StringProcessor]) – A string processor that can be used to make certain variants of your aliases also count as aliases. When a processed string equals the processed form of one of the registered aliases, it is also considered to be an alias

  • name (Optional[str]) – Optional name of this alias space

add_alias(alias, representative)

Add an alias to the space

Parameters:
  • alias (str) – Alias to register

  • representative (str) – Preferred form of the string

Return type:

None

create_mapper()

Creates a dictionary where the processed form of a registered alias maps to its representative

Return type:

dict[str, str]

dict(data=None, **kwargs)

Create an AliasAwareDict

Parameters:
  • data (dict[str, Any] | None) – input dictionary

  • kwargs – key, value pairs to add to the dictionary

Return type:

AliasAwareDict

get_representative(string, missing=<object object>, raise_missing=False)

Get the representative of a given string

Parameters:
  • string (str) – The raw input string

  • missing (Any) – Value to return when the string is not a registered alias. When this argument is not given, the raw input string will be returned back.

  • raise_missing (bool) – Whether an error must be raised when the input string is not a registered alias

Return type:

Any

map(strings, missing=<object object>, raise_missing=False, return_list=False)

Map an iterable of string to their representatives

Parameters:
  • strings (Iterable[str]) – Iterable of strings

  • missing (Any) – Value to return when the string is not a registered alias. When this argument is not given, the raw input string will be returned back.

  • raise_missing (bool) – Whether an error must be raised when the input string is not a registered alias

  • return_list (bool) – Whether to cast the output map to a list object

Return type:

map | list

str(data)

Create an AliasAwareString

Parameters:

data (Any) – input string

Return type:

AliasAwareString