savant_rs.utils.symbol_mapper

class savant_rs.utils.symbol_mapper.RegistrationPolicy

Defines how to act when the key is already registered.

Override

The key will be registered and the previous value will be overwritten.

ErrorIfNonUnique

The key will not be registered and a error will be triggered.

ErrorIfNonUnique = RegistrationPolicy.ErrorIfNonUnique
Override = RegistrationPolicy.Override
savant_rs.utils.symbol_mapper.build_model_object_key(model_name, object_label)

The function allows building a model object key from model name and object label.

Parameters:
  • model_name (str) – The name of the model.

  • object_label (str) – The label of the object.

Returns:

The model object key.

Return type:

str

savant_rs.utils.symbol_mapper.clear_symbol_maps()

The function clears mapping database.

savant_rs.utils.symbol_mapper.dump_registry()

The function dumps the registry in the form of model or object label, model_id and optional object id.

GIL management: the function is GIL-free.

Returns:

The list of strings in the form of “model_name[.object_label] model_id Option[object_id]”.

Return type:

list[str]

savant_rs.utils.symbol_mapper.get_model_id(model_name)

The function is used to fetch designated model id by a model name.

Parameters:

model_name (str) – The name of the model to fetch id for.

Returns:

Id of the model (int)

Return type:

int

Raises:

ValueError – if the model is not registered

savant_rs.utils.symbol_mapper.get_model_name(model_id)

The function allows the fetch a model name by its id.

Parameters:

model_id (int) – The id of the model to fetch name for.

Returns:

  • str – Name of the model

  • None – If the model is not registered

savant_rs.utils.symbol_mapper.get_object_id(model_name, object_label)

The function is used to fetch designated object id by a model name and object label.

Parameters:
  • model_name (str) – The name of the model to fetch id for.

  • object_label (str) – The label of the object to fetch id for.

Returns:

Id of the model (int) and id of the object (int)

Return type:

(int, int)

Raises:

ValueError – if the object is not registered

savant_rs.utils.symbol_mapper.get_object_ids(model_name, object_labels)

The function allows getting the object ids by their labels (bulk operation).

Parameters:
  • model_name (str) – The name of the model to fetch objects for.

  • object_labels (list[str]) – The labels of the objects to fetch ids for.

Return type:

List of tuples (object_label, object_id), if object_id is None, then the object is not registered.

savant_rs.utils.symbol_mapper.get_object_label(model_id, object_id)

The function allows getting the object label by its id.

Parameters:
  • model_id (int) – The id of the model to fetch name for.

  • object_id (int) – The id of the object to fetch label for.

Returns:

  • str – Label of the object

  • None – If the object is not registered

savant_rs.utils.symbol_mapper.get_object_labels(model_id, object_ids)

The function allows getting the object labels by their ids (bulk operation).

Parameters:
  • model_id (int) – The id of the model to fetch objects for.

  • object_ids (list[int]) – The ids of the objects to fetch labels for.

Returns:

List of tuples (object_id, object_label), if object_label is None, then the object is not registered.

Return type:

list[(int, str)]

savant_rs.utils.symbol_mapper.is_model_registered(model_name)

The function checks if the model is registered.

Parameters:

model_name (str) – The name of the model.

Returns:

True if the model is registered, False otherwise.

Return type:

bool

savant_rs.utils.symbol_mapper.is_object_registered(model_name, object_label)

The function checks if the object is registered.

Parameters:
  • model_name (str) – The name of the model.

  • object_label (str) – The label of the object.

Returns:

True if the object is registered, False otherwise.

Return type:

bool

savant_rs.utils.symbol_mapper.parse_compound_key(key)

The function allows parsing a model object key into model name and object label.

Parameters:

key (str) – The model object key.

Returns:

The model name and object label.

Return type:

(str, str)

Raises:

ValueError – If the key is not a valid key in format “model.key”.

savant_rs.utils.symbol_mapper.register_model_objects(model_name, elements, policy)

The function is used to register a new model and its object classes.

Parameters:
  • model_name (str) – The name of the model to register.

  • elements (dict[int, str]) – The dictionary of objects in the form id:label to register.

  • policy (RegistrationPolicy) – The policy to use when registering objects.

Returns:

Id of the model

Return type:

int

Raises:

ValueError – if there are objects with the same IDs or labels are already registered.

savant_rs.utils.symbol_mapper.validate_base_key(key)

The function allows validating a model or object key.

Parameters:

key (str) – The model or object key.

Returns:

The key.

Return type:

str

Raises:

ValueError – If the key is not a valid key in format “wordwithoutdots”.