Skip to content

Commit 075e0eb

Browse files
authored
CU-869a9q6rm: Include MetaCAT model cards in overall model card (#120)
* CU-869a9q6rm: Include MetaCAT model cards in overall model card * CU-869a9q6rm: Ensure meta cat model cards are allowed as dicts * CU-869a9q6rm: Make sure to overload MetaCAT model card method. This is to be certain on the type of the output
1 parent e572bdd commit 075e0eb

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

medcat-v2/medcat/cat.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -812,13 +812,11 @@ def get_model_card(self, as_dict: bool = False) -> Union[str, ModelCard]:
812812
Returns:
813813
Union[str, ModelCard]: The model card.
814814
"""
815-
meta_cat_categories = [
816-
cnf.general.category_name # type: ignore
817-
for cnf in self.config.components.addons
818-
if cnf.comp_name == 'meta_cat' and
819-
# NOTE: not the best way to check this,
820-
# but I don't want to import the addon config
821-
type(cnf).__name__ == 'ConfigMetaCAT']
815+
from medcat.components.addons.meta_cat import MetaCATAddon
816+
met_cat_model_cards = [
817+
mc.mc.get_model_card(True) for mc in
818+
self.get_addons_of_type(MetaCATAddon)
819+
]
822820
cdb_info = self.cdb.get_basic_info()
823821
model_card: ModelCard = {
824822
'Model ID': self.config.meta.hash,
@@ -827,7 +825,7 @@ def get_model_card(self, as_dict: bool = False) -> Union[str, ModelCard]:
827825
'Description': self.config.meta.description,
828826
'Source Ontology': self.config.meta.ontology,
829827
'Location': self.config.meta.location,
830-
'MetaCAT models': meta_cat_categories,
828+
'MetaCAT models': met_cat_model_cards,
831829
'Basic CDB Stats': cdb_info,
832830
'Performance': {}, # TODO
833831
'Important Parameters (Partial view, '

medcat-v2/medcat/components/addons/meta_cat/meta_cat.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from multiprocessing import Lock
66
from datetime import datetime
77
from typing import Iterable, Optional, cast, Union, Any, TypedDict, Callable
8+
from typing import overload, Literal
89

910
from medcat.utils.hasher import Hasher
1011

@@ -861,6 +862,14 @@ def __call__(self, doc: MutableDocument) -> MutableDocument:
861862
self._set_meta_anns(doc, id2category_value)
862863
return doc
863864

865+
@overload
866+
def get_model_card(self, as_dict: Literal[True]) -> dict:
867+
pass
868+
869+
@overload
870+
def get_model_card(self, as_dict: Literal[False]) -> str:
871+
pass
872+
864873
def get_model_card(self, as_dict: bool = False) -> Union[str, dict]:
865874
"""A minimal model card.
866875

medcat-v2/medcat/data/model_card.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
'Description': str,
2424
'Source Ontology': list[str],
2525
'Location': str,
26-
'MetaCAT models': list[str],
26+
'MetaCAT models': list[dict],
2727
'Basic CDB Stats': CDBInfo,
2828
'Performance': dict[str, Any],
2929
('Important Parameters '

0 commit comments

Comments
 (0)