sign_language_translator.languages.sign.mapping_rules module

This module provides classes for mapping rules used in a mapping system.

The mapping system allows for mapping tokens to specific objects based on predefined rules. The module includes abstract base classes for mapping rules and several concrete implementations.

Classes: - MappingRule: Abstract base class for mapping rules. - LambdaMappingRule: Mapping rule defined by lambda functions. - DirectMappingRule: Mapping rule for supported words. - CharacterByCharacterMappingRule: Mapping rule for character-by-character mapping.

Each mapping rule class defines the behavior of the rule, including applicability checks and actions to be taken when the rule is applied.

class sign_language_translator.languages.sign.mapping_rules.CharacterByCharacterMappingRule(token_to_object: Dict[str, Any], allowed_tags: Set[Any], priority: int)[source][source]

Bases: MappingRule

Mapping rule which maps a token character-by-character.

Parameters:
  • token_to_object (Dict[str, Any]) – Dictionary mapping tokens to some objects.

  • allowed_tags (Set[Any]) – Set of allowed tags for the rule to be applicable.

  • priority (int) – Priority of the rule.

apply(token) List[Any][source][source]

Apply the mapping rule to the given token.

Parameters:

token (str) – The token to apply the mapping rule to.

Returns:

list of results of applying the mapping rule to each character in the token.

Return type:

List[Any]

is_applicable(token, tag=None, context=None) bool[source][source]

Check if the mapping rule is applicable for the given token, tag, and context.

Parameters:
  • token (str) – The token to be checked.

  • tag (Any, optional) – The tag associated with the token. Defaults to None.

  • context (Any, optional) – The context in which the token appears. Defaults to None.

Returns:

True if the mapping rule is applicable, False otherwise.

Return type:

bool

property priority[source]

Priority of the mapping rule.

Returns:

The priority of the mapping rule.

Return type:

int

class sign_language_translator.languages.sign.mapping_rules.DirectMappingRule(token_to_object: Dict[str, Any], priority: int)[source][source]

Bases: MappingRule

Mapping rule that directly maps keys to values.

Parameters:
  • token_to_object (Dict[str, Any]) – Dictionary mapping tokens to some objects.

  • priority (int) – Priority of the rule.

apply(token: str) Any[source][source]

Apply the mapping rule to the given token. (i.e. map the given token to something.)

Parameters:

token (str) – The token to apply the mapping rule to.

Returns:

The result of applying the mapping rule.

is_applicable(token, tag=None, context=None) bool[source][source]

Check if the mapping rule is applicable for the given token, tag, and context.

Parameters:
  • token (str) – The token to be checked.

  • tag (Any, optional) – The tag associated with the token. Defaults to None.

  • context (Any, optional) – The context in which the token appears. Defaults to None.

Returns:

True if the mapping rule is applicable, False otherwise.

Return type:

bool

property priority[source]

Priority of the mapping rule.

Returns:

The priority of the mapping rule.

Return type:

int

class sign_language_translator.languages.sign.mapping_rules.LambdaMappingRule(is_applicable_function: Callable[[str, Any, Any], bool], apply_function: Callable[[str], Any], priority: int)[source][source]

Bases: MappingRule

Mapping rule based on lambda functions.

Parameters:
  • is_applicable_function (Callable[[str, Any, Any], bool]) – Function to check if the rule is applicable to the given token, tag & context.

  • apply_function (Callable[[str], Any]) – Function to apply the rule to the token.

  • priority (int) – Priority of the rule.

apply(token) Any[source][source]

Apply the mapping rule to the given token. (i.e. map the given token to something.)

Parameters:

token (str) – The token to apply the mapping rule to.

Returns:

The result of applying the mapping rule.

is_applicable(token, tag=None, context=None) bool[source][source]

Check if the mapping rule is applicable for the given token, tag, and context.

Parameters:
  • token (str) – The token to be checked.

  • tag (Any, optional) – The tag associated with the token. Defaults to None.

  • context (Any, optional) – The context in which the token appears. Defaults to None.

Returns:

True if the mapping rule is applicable, False otherwise.

Return type:

bool

property priority[source]

Priority of the mapping rule.

Returns:

The priority of the mapping rule.

Return type:

int

class sign_language_translator.languages.sign.mapping_rules.MappingRule[source]

Bases: ABC

Abstract base class for mapping rules.

abstract apply(token: str) Any[source]

Apply the mapping rule to the given token. (i.e. map the given token to something.)

Parameters:

token (str) – The token to apply the mapping rule to.

Returns:

The result of applying the mapping rule.

abstract is_applicable(token: str, tag: Any | None = None, context: Any | None = None) bool[source]

Check if the mapping rule is applicable for the given token, tag, and context.

Parameters:
  • token (str) – The token to be checked.

  • tag (Any, optional) – The tag associated with the token. Defaults to None.

  • context (Any, optional) – The context in which the token appears. Defaults to None.

Returns:

True if the mapping rule is applicable, False otherwise.

Return type:

bool

abstract property priority: int

Priority of the mapping rule.

Returns:

The priority of the mapping rule.

Return type:

int