sign_language_translator.languages.sign package

Submodules

Module contents

Module that contains Sign Languages as classes with rules to translate text tokens into sign language videos

class sign_language_translator.languages.sign.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.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.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.MappingRule[source][source]

Bases: ABC

Abstract base class for mapping rules.

abstract 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.

abstract is_applicable(token: str, tag: Any | None = None, context: Any | None = 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

abstract property priority: int[source]

Priority of the mapping rule.

Returns:

The priority of the mapping rule.

Return type:

int

class sign_language_translator.languages.sign.PakistanSignLanguage[source][source]

Bases: SignLanguage

A class representing the Pakistan Sign Language.

It provides methods for converting tokens to sign dictionaries and restructuring sentences.

STOPWORDS[source]

A set of stopwords in Pakistan Sign Language.

Type:

set

STOPWORDS = {'so', 'the'}[source]
static name() str[source][source]

Returns the name of the sign language.

restructure_sentence(sentence: Iterable[str], tags: Iterable[Any] | None = None, contexts: Iterable[Any] | None = None) Tuple[Iterable[str], Iterable[Any], Iterable[Any]][source][source]

Restructures a sentence by changing the grammar, removing stopwords, spaces & punctuation, and modifying token contents.

Parameters:
  • sentence (Iterable[str]) – Input sentence to be restructured.

  • tags (Iterable[Any], optional) – Additional tags associated with the sentence. Defaults to None.

  • contexts (Iterable[Any], optional) – Additional contexts associated with the sentence. Defaults to None.

Returns:

The restructured sentence, associated tags, and contexts.

Return type:

Tuple[Iterable[str], Iterable[Any], Iterable[Any]]

tokens_to_sign_dicts(tokens: Iterable[str], tags: Iterable[Any] | None = None, contexts: Iterable[Any] | None = None) List[Dict[str, List[List[str]] | List[float]]][source][source]

Converts tokens to signs based on rules and returns a list of sign dictionaries.

Parameters:
  • tokens (Iterable[str]) – Input tokens to be converted to signs.

  • tags (Iterable[Any], optional) – Additional tags associated with the tokens. Defaults to None.

  • contexts (Iterable[Any], optional) – Additional contexts associated with the tokens. Defaults to None.

Returns:

A list of sign dictionaries, where each dictionary contains

the ‘signs’ field mapping to a list of sign sequences and the ‘weights’ field mapping to the usage frequency of each sign sequence. e.g. “word” -> [{“signs”: [[sign_1, sign_2], [alternate_1]], “weights”: [10, 5]}, …]

Return type:

List[Dict[str, List[List[str]] | List[float]]]

class sign_language_translator.languages.sign.SignLanguage[source][source]

Bases: ABC

This abstract class defines the structure and methods required for mapping spoken language text to signs in sign languages using rule-based approaches.

Keys[source]

Enumerates all keys that are used in a sign dict.

Type:

enum.Enum

name()[source][source]

Returns the name of the sign language.

tokens_to_sign_dicts()[source][source]

Converts tokens to signs based on rules and returns a list of sign dictionaries.

restructure_sentence()[source][source]

Restructures a sentence by adjusting grammar, dropping meaningless words, and normalizing synonyms.

_make_equal_weight_sign_dict()[source][source]

Creates a sign dictionary with equal weights for the provided signs.

class SignDictKeys(value)[source][source]

Bases: Enum

Enumerates all keys that are used in a sign dict.

SIGNS[source]

key for the ‘signs’ field in the sign dict mapping to list of sequence of video names.

Type:

str

WEIGHTS[source]

key for the ‘weights’ field in the sign dict mapping to the usage frequency of a video sequence.

Type:

str

SIGNS = 'signs'[source]
WEIGHTS = 'weights'[source]
abstract static name() str[source][source]

Returns the name of the sign language.

abstract restructure_sentence(sentence: Iterable[str], tags: Iterable[Any] | None = None, contexts: Iterable[Any] | None = None) Tuple[Iterable[str], Iterable[Any], Iterable[Any]][source][source]

Restructures a sentence by changing the grammar, removing stopwords, spaces & punctuation, and modifying token contents.

Parameters:
  • sentence (Iterable[str]) – Input sentence to be restructured.

  • tags (Iterable[Any], optional) – Additional tags associated with the sentence. Defaults to None.

  • contexts (Iterable[Any], optional) – Additional contexts associated with the sentence. Defaults to None.

Returns:

The restructured sentence, associated tags, and contexts.

Return type:

Tuple[Iterable[str], Iterable[Any], Iterable[Any]]

abstract tokens_to_sign_dicts(tokens: Iterable[str], tags: Iterable[Any] | None = None, contexts: Iterable[Any] | None = None) List[Dict[str, List[List[str]] | List[float]]][source][source]

Converts tokens to signs based on rules and returns a list of sign dictionaries.

Parameters:
  • tokens (Iterable[str]) – Input tokens to be converted to signs.

  • tags (Iterable[Any], optional) – Additional tags associated with the tokens. Defaults to None.

  • contexts (Iterable[Any], optional) – Additional contexts associated with the tokens. Defaults to None.

Returns:

A list of sign dictionaries, where each dictionary contains

the ‘signs’ field mapping to a list of sign sequences and the ‘weights’ field mapping to the usage frequency of each sign sequence. e.g. “word” -> [{“signs”: [[sign_1, sign_2], [alternate_1]], “weights”: [10, 5]}, …]

Return type:

List[Dict[str, List[List[str]] | List[float]]]