Dictionary Factory
This module defines the DictionaryFactory
protocol and the DefaultDictionaryFactory
class.
It provides functionality for loading and accessing dictionaries for supported languages.
- DictionaryFactory: The Protocol class for all dictionary factories.
- DefaultDictionaryFactory: Default dictionary factory. It loads the dictionaries that are shipped with simplemma and caches them as configured.
Classes
DefaultDictionaryFactory
Bases: DictionaryFactory
Default Dictionary Factory.
This class is a concrete implementation of the DictionaryFactory
protocol.
It provides functionality for loading and caching dictionaries from disk that are included in Simplemma.
Source code in simplemma/strategies/dictionaries/dictionary_factory.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
Functions
__init__(cache_max_size=8)
Initialize the DefaultDictionaryFactory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cache_max_size |
int
|
The maximum size of the cache for loaded dictionaries.
Defaults to |
8
|
Source code in simplemma/strategies/dictionaries/dictionary_factory.py
110 111 112 113 114 115 116 117 118 119 120 |
|
get_dictionary(lang)
Get the dictionary for a specific language.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lang |
str
|
The language code. |
required |
Returns:
Type | Description |
---|---|
Mapping[str, str]
|
Mapping[str, str]: The dictionary for the specified language. |
Raises:
Type | Description |
---|---|
ValueError
|
If the specified language is not supported. |
Source code in simplemma/strategies/dictionaries/dictionary_factory.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
|
DictionaryFactory
Bases: Protocol
This protocol defines the interface for a dictionary factory, which is responsible for loading and providing access to dictionaries for different languages.
Note
This protocol should be implemented by concrete dictionary factories.
Concrete implementations of this protocol should provide a concrete implementation for the get_dictionary
method.
Source code in simplemma/strategies/dictionaries/dictionary_factory.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
Functions
get_dictionary(lang)
abstractmethod
Get the dictionary for a specific language.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lang |
str
|
The language code. |
required |
Returns:
Type | Description |
---|---|
Mapping[str, str]
|
Mapping[str, str]: The dictionary for the specified language. |
Raises:
Type | Description |
---|---|
ValueError
|
If the specified language is not supported. |
Source code in simplemma/strategies/dictionaries/dictionary_factory.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
MappingStrToByteString
Bases: Mapping[str, str]
Wrapper around ByString dict to make them behave like str dict.
Source code in simplemma/strategies/dictionaries/dictionary_factory.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|