sign_language_translator.languages.sign package
Submodules
- sign_language_translator.languages.sign.mapping_rules module
- sign_language_translator.languages.sign.pakistan_sign_language module
- sign_language_translator.languages.sign.sign_language module
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:
MappingRuleMapping 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
- class sign_language_translator.languages.sign.DirectMappingRule(token_to_object: Dict[str, Any], priority: int)[source][source]
Bases:
MappingRuleMapping 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
- 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:
MappingRuleMapping 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
- class sign_language_translator.languages.sign.MappingRule[source][source]
Bases:
ABCAbstract 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
- class sign_language_translator.languages.sign.PakistanSignLanguage[source][source]
Bases:
SignLanguageA class representing the Pakistan Sign Language.
It provides methods for converting tokens to sign dictionaries and restructuring sentences.
- 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:
ABCThis abstract class defines the structure and methods required for mapping spoken language text to signs in sign languages using rule-based approaches.
- 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:
EnumEnumerates 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
- 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]]]