medcat.storage.serialisables
Classes:
-
AbstractManualSerialisable– -
AbstractSerialisable–The abstract serialisable base class.
-
ManualSerialisable– -
Serialisable–The base serialisable protocol.
-
SerialisingStrategy–Describes the strategy for serialising.
Functions:
-
get_all_serialisable_members–Gets all serialisable members of an object.
-
name_all_serialisable_elements–Gets all serialisable elements from a list or tuple.
AbstractManualSerialisable
Methods:
get_init_attrs
classmethod
Source code in medcat-v2/medcat/storage/serialisables.py
212 213 214 | |
get_strategy
get_strategy() -> SerialisingStrategy
Source code in medcat-v2/medcat/storage/serialisables.py
209 210 | |
ignore_attrs
classmethod
Source code in medcat-v2/medcat/storage/serialisables.py
216 217 218 | |
AbstractSerialisable
The abstract serialisable base class.
This defines some common defaults.
Methods:
get_init_attrs
classmethod
Source code in medcat-v2/medcat/storage/serialisables.py
148 149 150 | |
get_strategy
get_strategy() -> SerialisingStrategy
Source code in medcat-v2/medcat/storage/serialisables.py
145 146 | |
ignore_attrs
classmethod
Source code in medcat-v2/medcat/storage/serialisables.py
152 153 154 | |
ManualSerialisable
Bases: Serialisable, Protocol
Methods:
-
deserialise_from–Deserialise from a specifc path.
-
serialise_to–Serialise to a folder.
deserialise_from
classmethod
deserialise_from(folder_path: str, **init_kwargs) -> ManualSerialisable
Deserialise from a specifc path.
The init keyword arguments are generally: - cnf: The config relevant to the components - tokenizer (BaseTokenizer): The base tokenizer for the model - cdb (CDB): The CDB for the model - vocab (Vocab): The Vocab for the model - model_load_path (Optional[str]): The model load path, but not the component load path
Parameters:
-
(folder_pathstr) –The path to deserialsie form.
Returns:
-
ManualSerialisable(ManualSerialisable) –The deserialised object.
Source code in medcat-v2/medcat/storage/serialisables.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
serialise_to
serialise_to(folder_path: str) -> None
Serialise to a folder.
Parameters:
-
(folder_pathstr) –The folder to serialise to.
Source code in medcat-v2/medcat/storage/serialisables.py
177 178 179 180 181 182 183 | |
Serialisable
Bases: Protocol
The base serialisable protocol.
Methods:
-
get_init_attrs–Get the names of the arguments needed for init upon deserialisation.
-
get_strategy–Get the serialisation strategy.
-
ignore_attrs–Get the names of attributes not to serialise.
-
include_properties–
get_init_attrs
classmethod
Get the names of the arguments needed for init upon deserialisation.
Returns:
Source code in medcat-v2/medcat/storage/serialisables.py
116 117 118 119 120 121 122 123 | |
get_strategy
get_strategy() -> SerialisingStrategy
Get the serialisation strategy.
Returns:
-
SerialisingStrategy(SerialisingStrategy) –The strategy.
Source code in medcat-v2/medcat/storage/serialisables.py
108 109 110 111 112 113 114 | |
ignore_attrs
classmethod
Get the names of attributes not to serialise.
Returns:
Source code in medcat-v2/medcat/storage/serialisables.py
125 126 127 128 129 130 131 132 | |
SerialisingStrategy
Bases: Enum
Describes the strategy for serialising.
Methods:
-
get_dict–Gets the appropriate parts of the dict of the object.
-
get_parts–Gets the matching serialisable parts of the object.
Attributes:
-
DICT_ONLY–Only include the object's .dict
-
MANUAL–Use manual serialisation defined by the object itself.
-
SERIALISABLES_AND_DICT–Serialise attributes that are Serialisable as well as
-
SERIALISABLE_ONLY–Only serialise attributes that are of Serialisable type
MANUAL
class-attribute
instance-attribute
MANUAL = auto()
Use manual serialisation defined by the object itself.
In this case, most of the logic defined within here will
likely be ignored.
SERIALISABLES_AND_DICT
class-attribute
instance-attribute
SERIALISABLES_AND_DICT = auto()
Serialise attributes that are Serialisable as well as the rest of .dict
SERIALISABLE_ONLY
class-attribute
instance-attribute
SERIALISABLE_ONLY = auto()
Only serialise attributes that are of Serialisable type
get_dict
get_dict(obj: Serialisable) -> dict[str, Any]
Gets the appropriate parts of the dict of the object.
I.e this filters out parts that shouldn't be included.
Parameters:
-
(objSerialisable) –The serialisable object.
Returns:
Source code in medcat-v2/medcat/storage/serialisables.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
get_parts
get_parts(obj: Serialisable) -> list[tuple[Serialisable, str]]
Gets the matching serialisable parts of the object.
This includes only serialisable parts, and only if specified by the strategy.
Returns:
-
list[tuple[Serialisable, str]]–list[tuple[Serialisable, str]]: The serialisable parts with names.
Source code in medcat-v2/medcat/storage/serialisables.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |
get_all_serialisable_members
get_all_serialisable_members(object: Serialisable) -> tuple[list[tuple[Serialisable, str]], dict[str, Any]]
Gets all serialisable members of an object.
This looks for public and protected members, but not private ones. It should also be able to return parts of lists and tuples. It also provides the name of each serialisable object.
Parameters:
-
(objectAny) –The target object.
Returns:
-
tuple[list[tuple[Serialisable, str]], dict[str, Any]]–tuple[list[tuple[Serialisable, str]], dict[str, Any]]: list of serialisable objects along with their names
Source code in medcat-v2/medcat/storage/serialisables.py
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
name_all_serialisable_elements
name_all_serialisable_elements(target_list: Union[list, tuple], name_start: str = '', all_or_nothing: bool = True) -> list[tuple[Serialisable, str]]
Gets all serialisable elements from a list or tuple.
There's two strategies for finding the parts:
1) If all_or_nothing == True either all the elements
in the list must be Serialisable or None of them.
2) If all_or_nothing == False some elements may be
serialisable while others may not be.
Parameters:
-
(target_listUnion[list, tuple]) –The list/tuple of objects to look in.
-
(name_startstr, default:'') –The start of the name. Defaults to ''.
-
(all_or_nothingbool, default:True) –Whether to disallow lists/tuple where only some elements are serialisable. Defaults to True.
Raises:
-
ValueError–If
all_or_nothingis specified and not all elements are serialisable.
Returns:
-
list[tuple[Serialisable, str]]–list[tuple[Serialisable, str]]: The serialisable parts along with name.
Source code in medcat-v2/medcat/storage/serialisables.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |