tommy.model.synonyms_model
Classes
- class tommy.model.synonyms_model.SynonymsModel(derive_from: SynonymsModel = None)[source]
Bases:
object
A class representing the dictionary of synonyms.
The class acts as a wrapper around a dictionary of synoyms, providing basic map-like functionality. This model can be used to map source words to target words (synonyms).
- __init__(derive_from: SynonymsModel = None) None [source]
Initializes the synonyms model.
- classmethod from_dict(synonyms_dict: dict[str, str]) SynonymsModel [source]
Create a SynonymsModel instance from a dictionary representation.
- Parameters:
synonyms_dict – Dictionary representation of the synonyms model
- Returns:
SynonymsModel instance
- get(key: str, default: str = None) str [source]
Gets the synonym for a given source word. Returns a default value when the source word is not found.
- Parameters:
key – The source word
default – The default value to return
if the source word is not found, defaults to None :return: The synonym associated with the source word
- replace(synonyms: dict[str, str]) None [source]
Replace the synonyms with the provided mapping.
- Parameters:
synonyms – A dictionary where the keys represent source words
and the values represent target words. :return: None
- property synonyms: dict[str, str]