medcat2.components.types
Attributes
Classes
Abstract base class for generic types. |
|
The mutable parts of the document. |
|
The mutable part of an entity. |
|
The base tokenizer protocol. |
|
The abstract serialisable base class. |
|
Vocabulary used to store word embeddings for context similarity |
|
Generic enumeration. |
|
Base class for protocol classes. |
|
Base class for protocol classes. |
|
Base class for protocol classes. |
|
Base class for protocol classes. |
|
Base class for protocol classes. |
Functions
|
Register a new core component. |
|
Get the registry for a core component type. |
|
Get the component creator. |
|
Creat a core component. |
|
Get all registered components (name and class name for each). |
Module Contents
- class medcat2.components.types.Registry(type, lazy_defaults=None)
Bases:
Generic[P]Abstract base class for generic types.
A generic type is typically declared by inheriting from this class parameterized with one or more type variables. For example, a generic mapping type might be defined as:
class Mapping(Generic[KT, VT]): def __getitem__(self, key: KT) -> VT: ... # Etc.
This class can then be used as follows:
def lookup_name(mapping: Mapping[KT, VT], key: KT, default: VT) -> VT: try: return mapping[key] except KeyError: return default
- Parameters:
type (Type[P])
lazy_defaults (Optional[dict[str, tuple[str, str]]])
- __init__(type, lazy_defaults=None)
- Parameters:
type (Type[P])
lazy_defaults (Optional[dict[str, tuple[str, str]]])
- Return type:
None
- _components: dict[str, Callable[Ellipsis, P]]
- _type
- _lazy_defaults
- register(component_name, creator)
- Parameters:
component_name (str)
creator (Callable[Ellipsis, P])
- get_component(component_name)
Get the component that’s registered.
The component generally refers to the class, but may be another method that creates the object needed.
- Parameters:
component_name (str) – The name of the component.
- Raises:
MedCATRegistryException – If no component by requested name is registered.
- Returns:
Callable[…, P] – The creator for the registered component.
- Return type:
Callable[Ellipsis, P]
- _ensure_lazy_default(component_name)
- Parameters:
component_name (str)
- Return type:
None
- register_all_defaults()
Register all default (lazily-added) components.
- Return type:
None
- list_components()
List all available component names and class names.
- Returns:
list[tuple[str, str]] – The list of the names and class names for each registered componetn.
- Return type:
list[tuple[str, str]]
- unregister_component(component_name)
Unregister a component.
- Parameters:
component_name (str) – The component name.
- Raises:
MedCATRegistryException – If no component by the name specified had been registered.
- Returns:
Callable[…, P] – The creator of the component.
- Return type:
Callable[Ellipsis, P]
- unregister_all_components()
Unregister all components.
- Return type:
None
- __contains__(component_name)
- Parameters:
component_name (str)
- Return type:
bool
- __getitem__(component_name)
- Parameters:
component_name (str)
- Return type:
Callable[Ellipsis, P]
- __slots__ = ()
- _is_protocol = False
- classmethod __class_getitem__(params)
- classmethod __init_subclass__(*args, **kwargs)
- class medcat2.components.types.MutableDocument
Bases:
ProtocolThe mutable parts of the document.
Represents parts of the document that can / should be changed by the various components.
- property base: BaseDocument
The base document.
- Return type:
- property final_ents: list[MutableEntity]
The linked entities associated with the document.
This should be set by the linker.
- Return type:
list[MutableEntity]
- property all_ents: list[MutableEntity]
All entities recognised by NER.
This should be set by the NER component.
- Return type:
list[MutableEntity]
- __iter__()
- Return type:
Iterator[MutableToken]
- __getitem__(index: int) MutableToken
- __getitem__(index: slice) MutableEntity
- get_tokens(start_index, end_index)
Get the tokens that span the specified character indices.
- Parameters:
start_index (int) – The starting character index.
end_index (int) – The ending character index.
- Returns:
list[MutableToken] – The list of tokens.
- Return type:
list[MutableToken]
- set_addon_data(path, val)
Used to add arbitrary data to the entity.
This is generally used by addons to keep track of their data.
NB! The path used needs to be registered using the register_addon_path class method.
- Parameters:
path (str) – The data ID / path.
val (Any) – The value to be added.
- Return type:
None
- get_addon_data(path)
Get data added to the entity.
See add_data for details.
- Parameters:
path (str) – The data ID / path.
- Returns:
Any – The stored value.
- Return type:
Any
- classmethod register_addon_path(path, def_val=None, force=True)
Register a custom/arbitrary data path.
This can be used to store arbitrary data along with the entity for use in an addon (e.g MetaCAT).
PS: If using this, it is important to use paths namespaced to the component you’re using in order to avoid conflicts.
- Parameters:
path (str) – The path to be used. Should be prefixed by component name (e.g meta_cat_id for an ID tied to the meta_cat addon)
def_val (Any) – Default value. Defaults to None.
force (bool) – Whether to forcefully add the value. Defaults to True.
- Return type:
None
- __slots__ = ()
- _is_protocol = True
- _is_runtime_protocol = False
- classmethod __init_subclass__(*args, **kwargs)
- classmethod __class_getitem__(params)
- class medcat2.components.types.MutableEntity
Bases:
ProtocolThe mutable part of an entity.
This represent the changeable part of an entnity. That is, parts that should be changed by the various components.
- property base: BaseEntity
The base / static entity part.
- Return type:
- property detected_name: str
The detected name (if any) for this entity.
This should be set by the NER component.
- Return type:
str
- set_addon_data(path, val)
Used to add arbitrary data to the entity.
This is generally used by addons to keep track of their data.
NB! The path used needs to be registered using the register_addon_path class method.
- Parameters:
path (str) – The data ID / path.
val (Any) – The value to be added.
- Return type:
None
- get_addon_data(path)
Get data added to the entity.
See add_data for details.
- Parameters:
path (str) – The data ID / path.
- Returns:
Any – The stored value.
- Return type:
Any
- property link_candidates: list[str]
The candidates for the detected name (if any) for this entity.
This should be set by the NER component.
- Return type:
list[str]
- property context_similarity: float
The context similarity of the lnked entity.
This should be set by the linker component.
- Return type:
float
- property confidence: float
The confidence for the lnked entity.
NOTE: This seems to be unused!
- Return type:
float
- property cui: str
The CUI of the lnked entity.
This should be set by the linker component.
- Return type:
str
- property id: int
The ID of the entity within the document.
This counts all the entities recognised, not just ones that were successfully linked.
This should be set by the NER.
- Return type:
int
- classmethod register_addon_path(path, def_val=None, force=True)
Register a custom/arbitrary data path.
This can be used to store arbitrary data along with the entity for use in an addon (e.g MetaCAT).
PS: If using this, it is important to use paths namespaced to the component you’re using in order to avoid conflicts.
- Parameters:
path (str) – The path to be used. Should be prefixed by component name (e.g meta_cat_id for an ID tied to the meta_cat addon)
def_val (Any) – Default value. Defaults to None.
force (bool) – Whether to forcefully add the value. Defaults to True.
- Return type:
None
- __iter__()
- Return type:
Iterator[MutableToken]
- __len__()
- Return type:
int
- __slots__ = ()
- _is_protocol = True
- _is_runtime_protocol = False
- classmethod __init_subclass__(*args, **kwargs)
- classmethod __class_getitem__(params)
- class medcat2.components.types.BaseTokenizer
Bases:
ProtocolThe base tokenizer protocol.
- create_entity(doc, token_start_index, token_end_index, label)
Create an entity from a document.
- Parameters:
doc (MutableDocument) – The document to use.
token_start_index (int) – The token start index.
token_end_index (int) – The token end index.
label (str) – The label.
- Returns:
MutableEntity – The resulting entity.
- Return type:
- entity_from_tokens(tokens)
Get an entity from the list of tokens.
- Parameters:
tokens (list[MutableToken]) – List of tokens.
- Returns:
MutableEntity – The resulting entity.
- Return type:
- __call__(text)
- Parameters:
text (str)
- Return type:
- classmethod get_init_args(config)
- Parameters:
config (medcat2.config.Config)
- Return type:
list[Any]
- classmethod get_init_kwargs(config)
- Parameters:
config (medcat2.config.Config)
- Return type:
dict[str, Any]
- get_doc_class()
Get the document implementation class used by the tokenizer.
This can be used (e.g) to register addon paths.
- Returns:
Type[MutableDocument] – The document class.
- Return type:
- get_entity_class()
Get the entity implementation class used by the tokenizer.
- Returns:
Type[MutableEntity] – The entity class.
- Return type:
- __slots__ = ()
- _is_protocol = True
- _is_runtime_protocol = False
- classmethod __init_subclass__(*args, **kwargs)
- classmethod __class_getitem__(params)
- class medcat2.components.types.CDB(config)
Bases:
medcat2.storage.serialisables.AbstractSerialisableThe abstract serialisable base class.
This defines some common defaults.
- Parameters:
config (medcat2.config.Config)
- __init__(config)
- Parameters:
config (medcat2.config.Config)
- Return type:
None
- config
- cui2info: dict[str, medcat2.cdb.concepts.CUIInfo]
- name2info: dict[str, medcat2.cdb.concepts.NameInfo]
- type_id2info: dict[str, medcat2.cdb.concepts.TypeInfo]
- token_counts: dict[str, int]
- addl_info: dict[str, Any]
- _subnames: set[str]
- is_dirty = False
- has_changed_names = False
- classmethod get_init_attrs()
- Return type:
list[str]
- _reset_subnames()
- has_subname(name)
Whether the CDB has the specified subname.
- Parameters:
name (str) – The subname to check.
- Returns:
bool – Whether the subname is present in this CDB.
- Return type:
bool
- get_name(cui)
Returns preferred name if it exists, otherwise it will return the longest name assigned to the concept.
- Parameters:
cui (str) – Concept ID or unique identifier in this database.
- Returns:
str – The name of the concept.
- Return type:
str
- weighted_average_function(step)
Get the weighted average for steop.
- Parameters:
step (int) – The steop.
- Returns:
float – The weighted average.
- Return type:
float
- add_types(types)
Add type info to CDB.
- Parameters:
types (Iterable[tuple[str, str]]) – The raw type info.
- Return type:
None
- add_names(cui, names, name_status=ST.AUTOMATIC, full_build=False)
Adds a name to an existing concept.
- Parameters:
cui (str) – Concept ID or unique identifier in this database, all concepts that have the same CUI will be merged internally.
names (dict[str, NameDescriptor]) –
Names for this concept, or the value that if found in free text can be linked to this concept. Names is an dict like: `{name: {‘tokens’: tokens, ‘snames’: snames,
’raw_name’: raw_name}, …}`
Names should be generated by helper function ‘medcat.preprocessing.cleaners.prepare_name’
name_status (str) – One of P, N, A. Defaults to ‘A’.
full_build (bool) – If True the dictionary self.addl_info will also be populated, contains a lot of extra information about concepts, but can be very memory consuming. This is not necessary for normal functioning of MedCAT (Default value False).
- Return type:
None
- _add_concept_names(cui, names, name_status)
- Parameters:
cui (str)
names (dict[str, medcat2.preprocessors.cleaners.NameDescriptor])
name_status (str)
- Return type:
None
- _add_full_build(cui, names, ontologies, description, type_ids)
- Parameters:
cui (str)
names (dict[str, medcat2.preprocessors.cleaners.NameDescriptor])
ontologies (set[str])
description (str)
type_ids (set[str])
- Return type:
None
- _add_concept(cui, names, ontologies, name_status, type_ids, description, full_build=False)
Add a concept to internal Concept Database (CDB). Depending on what you are providing this will add a large number of properties for each concept.
- Parameters:
cui (str) – Concept ID or unique identifier in this database, all concepts that have the same CUI will be merged internally.
names (dict[str, NameDescriptor]) –
Names for this concept, or the value that if found in free text can be linked to this concept. Names is a dict like: `{name: {‘tokens’: tokens, ‘snames’: snames,
’raw_name’: raw_name}, …}`
Names should be generated by helper function ‘medcat.preprocessing.cleaners.prepare_name’
ontologies (set[str]) – ontologies in which the concept exists (e.g. SNOMEDCT, HPO)
name_status (str) – One of P, N, A
type_ids (set[str]) – Semantic type identifier (have a look at TUIs in UMLS or SNOMED-CT)
description (str) – Description of this concept.
full_build (bool) – If True the dictionary self.addl_info will also be populated, contains a lot of extra information about concepts, but can be very memory consuming. This is not necessary for normal functioning of MedCAT (Default Value False).
- Return type:
None
- reset_training()
Will remove all training efforts - in other words all embeddings that are learnt for concepts in the current CDB. Please note that this does not remove synonyms (names) that were potentially added during supervised/online learning.
- Return type:
None
- filter_by_cui(cuis_to_keep)
Subset the core CDB fields (dictionaries/maps).
Note that this will potenitally keep a bit more CUIs then in cuis_to_keep. It will first find all names that link to the cuis_to_keep and then find all CUIs that link to those names and keep all of them.
This also will not remove any data from cdb.addl_info - as this field can contain data of unknown structure.
- Parameters:
cuis_to_keep (Collection[str]) – CUIs that will be kept, the rest will be removed (not completely, look above).
- Raises:
Exception – If no snames and subsetting is not possible.
- Return type:
None
- remove_cui(cui)
This function takes a CUI and removes it the CDB.
It also removes the CUI from name specific per_cui_status maps as well as well as removes all the names that do not correspond to any CUIs after the removal of this one.
- Parameters:
cui (str) – The CUI to remove.
- Return type:
None
- _remove_names(cui, names)
Remove names from an existing concept - effect is this name will never again be used to link to this concept. This will only remove the name from the linker (namely name2cuis and name2cuis2status), the name will still be present everywhere else. Why? Because it is bothersome to remove it from everywhere, but could also be useful to keep the removed names in e.g. cui2names.
- Parameters:
cui (str) – Concept ID or unique identifier in this database.
names (Iterable[str]) – Names to be removed (e.g list, set, or even a dict (in which case keys will be used)).
- Return type:
None
- __eq__(other)
- Parameters:
other (Any)
- Return type:
bool
- get_cui2count_train()
- Return type:
dict[str, int]
- get_name2count_train()
- Return type:
dict[str, int]
- get_hash()
- Return type:
str
- get_basic_info()
- Return type:
medcat2.data.model_card.CDBInfo
- get_strategy()
- Return type:
- classmethod ignore_attrs()
- Return type:
list[str]
- classmethod include_properties()
- Return type:
list[str]
- class medcat2.components.types.Vocab
Bases:
medcat2.storage.serialisables.AbstractSerialisableVocabulary used to store word embeddings for context similarity calculation. Also used by the spell checker - but not for fixing the spelling only for checking is something correct.
- Properties:
- vocab (dict[str, WordDescriptor]):
- Map from word to attributes, e.g. {‘house’:
{‘vector’: <np.array>, ‘count’: <int>, …}, …}
- index2word (dict[int, str]):
From word to an index - used for negative sampling
- vec_index2word (dict):
Same as index2word but only words that have vectors
- __init__()
- Return type:
None
- vocab: dict[str, WordDescriptor]
- index2word: dict[int, str]
- vec_index2word: dict[int, str]
- cum_probs: numpy.ndarray
- inc_or_add(word, cnt=1, vec=None)
Add a word or increase its count.
- Parameters:
word (str) – Word to be added
cnt (int) – By how much should the count be increased, or to what should it be set if a new word. (Default value = 1)
vec (Optional[np.ndarray]) – Word vector (Default value = None)
- Return type:
None
- remove_all_vectors()
Remove all stored vector representations.
- Return type:
None
- remove_words_below_cnt(cnt)
Remove all words with frequency below cnt.
- Parameters:
cnt (int) – Word count limit.
- Return type:
None
- _rebuild_index()
- inc_wc(word, cnt=1)
Incraese word count by cnt.
- Parameters:
word (str) – For which word to increase the count
cnt (int) – By how muhc to increase the count (Default value = 1)
- Return type:
None
- add_vec(word, vec)
Add vector to a word.
- Parameters:
word (str) – To which word to add the vector.
vec (np.ndarray) – The vector to add.
- Return type:
None
- reset_counts(cnt=1)
Reset the count for all word to cnt.
- Parameters:
cnt (int) – New count for all words in the vocab. (Default value = 1)
- Return type:
None
- update_counts(tokens)
Given a list of tokens update counts for words in the vocab.
- Parameters:
tokens (list[str]) – Usually a large block of text split into tokens/words.
- Return type:
None
- add_word(word, cnt=1, vec=None, replace=True)
Add a word to the vocabulary
- Parameters:
word (str) – The word to be added, it should be lemmatized and lowercased
cnt (int) – Count of this word in your dataset (Default value = 1)
vec (Optional[np.ndarray]) – The vector representation of the word (Default value = None)
replace (bool) – Will replace old vector representation (Default value = True)
- Return type:
None
- add_words(path, replace=True)
Adds words to the vocab from a file, the file is required to have the following format (vec being optional):
<word> <cnt>[ <vec_space_separated>]
- e.g. one line: the word house with 3 dimensional vectors
house 34444 0.3232 0.123213 1.231231
- Parameters:
path (str) – path to the file with words and vectors
replace (bool) – existing words in the vocabulary will be replaced. Defaults to True.
- Return type:
None
- init_cumsums()
Initialise cumulative sums.
This is in place of the unigram table. But similarly to it, this approach allows generating a list of indices that match the probabilistic distribution expected as per the word counts of each word.
- Return type:
None
- get_negative_samples(n=6, ignore_punct_and_num=False)
Get N negative samples.
- Parameters:
n (int) – How many words to return (Default value = 6)
ignore_punct_and_num (bool) – Whether to ignore punctuation and numbers. Defaults to False.
- Raises:
Exception – If no unigram table is present.
- Returns:
list[int] – Indices for words in this vocabulary.
- Return type:
list[int]
- get_vectors(indices)
- Parameters:
indices (list[int])
- Return type:
list[numpy.ndarray]
- __getitem__(word)
- Parameters:
word (str)
- Return type:
int
- vec(word)
- Parameters:
word (str)
- Return type:
Optional[numpy.ndarray]
- count(word)
- Parameters:
word (str)
- Return type:
int
- item(word)
- Parameters:
word (str)
- Return type:
WordDescriptor
- __contains__(word)
- Parameters:
word (str)
- Return type:
bool
- __eq__(other)
- Parameters:
other (Any)
- Return type:
bool
- get_strategy()
- Return type:
- classmethod get_init_attrs()
- Return type:
list[str]
- classmethod ignore_attrs()
- Return type:
list[str]
- classmethod include_properties()
- Return type:
list[str]
- class medcat2.components.types.CoreComponentType
Bases:
enum.EnumGeneric enumeration.
Derive from this class to define new enumerations.
- tagging
- token_normalizing
- ner
- linking
- __new__(value)
- _generate_next_value_(start, count, last_values)
Generate the next value when not given.
name: the name of the member start: the initial start value or None count: the number of existing members last_value: the last value assigned or None
- classmethod _missing_(value)
- __repr__()
- __str__()
- __dir__()
Returns all members and all public methods
- __format__(format_spec)
Returns format using actual value type unless __str__ has been overridden.
- __hash__()
- __reduce_ex__(proto)
- name()
The name of the Enum member.
- value()
The value of the Enum member.
- class medcat2.components.types.BaseComponent
Bases:
ProtocolBase class for protocol classes.
Protocol classes are defined as:
class Proto(Protocol): def meth(self) -> int: ...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:
class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check
See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:
class GenProto(Protocol[T]): def meth(self) -> T: ...
- property full_name: str | None
Name with the component type (e.g ner, linking, meta).
- Return type:
Optional[str]
- property name: str
The name of the component.
- Return type:
str
- is_core()
Whether the component is a core component or not.
- Returns:
bool – Whether this is a core component.
- Return type:
bool
- __call__(doc)
- Parameters:
- Return type:
- classmethod get_init_args(tokenizer, cdb, vocab, model_load_path)
Get the init arguments for the component.
- Parameters:
tokenizer (BaseTokenizer) – The tokenizer.
cdb (CDB) – The CDB.
vocab (Vocab) – The Vocab.
model_load_path (Optional[str]) – The model load path (or None).
- Returns:
list[Any] – The list of init arguments.
- Return type:
list[Any]
- classmethod get_init_kwargs(tokenizer, cdb, vocab, model_load_path)
Get init keyword arguments for the component.
- Parameters:
tokenizer (BaseTokenizer) – The tokenizer.
cdb (CDB) – The CDB.
vocab (Vocab) – The Vocab.
model_load_path (Optional[str]) – The model load path (or None).
- Returns:
dict[str, Any] – The keywrod arguments.
- Return type:
dict[str, Any]
- __slots__ = ()
- _is_protocol = True
- _is_runtime_protocol = False
- classmethod __init_subclass__(*args, **kwargs)
- classmethod __class_getitem__(params)
- class medcat2.components.types.CoreComponent
Bases:
BaseComponent,ProtocolBase class for protocol classes.
Protocol classes are defined as:
class Proto(Protocol): def meth(self) -> int: ...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:
class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check
See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:
class GenProto(Protocol[T]): def meth(self) -> T: ...
- get_type()
- Return type:
- property full_name: str | None
Name with the component type (e.g ner, linking, meta).
- Return type:
Optional[str]
- property name: str
The name of the component.
- Return type:
str
- is_core()
Whether the component is a core component or not.
- Returns:
bool – Whether this is a core component.
- Return type:
bool
- __call__(doc)
- Parameters:
- Return type:
- classmethod get_init_args(tokenizer, cdb, vocab, model_load_path)
Get the init arguments for the component.
- Parameters:
tokenizer (BaseTokenizer) – The tokenizer.
cdb (CDB) – The CDB.
vocab (Vocab) – The Vocab.
model_load_path (Optional[str]) – The model load path (or None).
- Returns:
list[Any] – The list of init arguments.
- Return type:
list[Any]
- classmethod get_init_kwargs(tokenizer, cdb, vocab, model_load_path)
Get init keyword arguments for the component.
- Parameters:
tokenizer (BaseTokenizer) – The tokenizer.
cdb (CDB) – The CDB.
vocab (Vocab) – The Vocab.
model_load_path (Optional[str]) – The model load path (or None).
- Returns:
dict[str, Any] – The keywrod arguments.
- Return type:
dict[str, Any]
- __slots__ = ()
- _is_protocol = True
- _is_runtime_protocol = False
- classmethod __init_subclass__(*args, **kwargs)
- classmethod __class_getitem__(params)
- class medcat2.components.types.AbstractCoreComponent
Bases:
CoreComponentBase class for protocol classes.
Protocol classes are defined as:
class Proto(Protocol): def meth(self) -> int: ...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:
class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check
See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:
class GenProto(Protocol[T]): def meth(self) -> T: ...
- NAME_PREFIX = 'core_'
- property full_name: str
Name with the component type (e.g ner, linking, meta).
- Return type:
str
- is_core()
Whether the component is a core component or not.
- Returns:
bool – Whether this is a core component.
- Return type:
bool
- get_type()
- Return type:
- property name: str
The name of the component.
- Return type:
str
- __call__(doc)
- Parameters:
- Return type:
- classmethod get_init_args(tokenizer, cdb, vocab, model_load_path)
Get the init arguments for the component.
- Parameters:
tokenizer (BaseTokenizer) – The tokenizer.
cdb (CDB) – The CDB.
vocab (Vocab) – The Vocab.
model_load_path (Optional[str]) – The model load path (or None).
- Returns:
list[Any] – The list of init arguments.
- Return type:
list[Any]
- classmethod get_init_kwargs(tokenizer, cdb, vocab, model_load_path)
Get init keyword arguments for the component.
- Parameters:
tokenizer (BaseTokenizer) – The tokenizer.
cdb (CDB) – The CDB.
vocab (Vocab) – The Vocab.
model_load_path (Optional[str]) – The model load path (or None).
- Returns:
dict[str, Any] – The keywrod arguments.
- Return type:
dict[str, Any]
- __slots__ = ()
- _is_protocol = True
- _is_runtime_protocol = False
- classmethod __init_subclass__(*args, **kwargs)
- classmethod __class_getitem__(params)
- class medcat2.components.types.HashableComponet
Bases:
ProtocolBase class for protocol classes.
Protocol classes are defined as:
class Proto(Protocol): def meth(self) -> int: ...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:
class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check
See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:
class GenProto(Protocol[T]): def meth(self) -> T: ...
- get_hash()
- Return type:
str
- __slots__ = ()
- _is_protocol = True
- _is_runtime_protocol = False
- classmethod __init_subclass__(*args, **kwargs)
- classmethod __class_getitem__(params)
- class medcat2.components.types.TrainableComponent
Bases:
ProtocolBase class for protocol classes.
Protocol classes are defined as:
class Proto(Protocol): def meth(self) -> int: ...
Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing), for example:
class C: def meth(self) -> int: return 0 def func(x: Proto) -> int: return x.meth() func(C()) # Passes static type check
See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:
class GenProto(Protocol[T]): def meth(self) -> T: ...
- train(cui, entity, doc, negative=False, names=[])
Train the component.
This should only apply to the linker.
- Parameters:
cui (str) – The CUI to train.
entity (BaseEntity) – The entity we’re at.
doc (BaseDocument) – The document within which we’re working.
negative (bool) – Whether or not the example is negative. Defaults to False.
names (list[str]/dict) – Optionally used to update the status of a name-cui pair in the CDB.
- Return type:
None
- __slots__ = ()
- _is_protocol = True
- _is_runtime_protocol = False
- classmethod __init_subclass__(*args, **kwargs)
- classmethod __class_getitem__(params)
- medcat2.components.types._DEFAULT_TAGGERS: dict[str, tuple[str, str]]
- medcat2.components.types._DEFAULT_NORMALIZERS: dict[str, tuple[str, str]]
- medcat2.components.types._DEFAULT_NER: dict[str, tuple[str, str]]
- medcat2.components.types._DEFAULT_LINKING: dict[str, tuple[str, str]]
- medcat2.components.types._CORE_REGISTRIES: dict[CoreComponentType, medcat2.utils.registry.Registry[CoreComponent]]
- medcat2.components.types.register_core_component(comp_type, comp_name, comp_clazz)
Register a new core component.
- Parameters:
comp_type (CoreComponentType) – The component type.
comp_name (str) – The component name.
comp_clazz (Callable[..., CoreComponent]) – The component creator.
- Return type:
None
- medcat2.components.types.get_core_registry(comp_type)
Get the registry for a core component type.
- Parameters:
comp_type (CoreComponentType) – The core component type.
- Returns:
Registry[CoreComponent] – The corresponding registry.
- Return type:
- medcat2.components.types.get_component_creator(comp_type, comp_name)
Get the component creator.
- Parameters:
comp_type (CoreComponentType) – The core component type.
comp_name (str) – The component name.
- Returns:
Callable[…, CoreComponent] – The creator for the component.
- Return type:
Callable[Ellipsis, CoreComponent]
- medcat2.components.types.create_core_component(comp_type, comp_name, *args, **kwargs)
Creat a core component.
All *args and **kwrags are passed directly to the component creator.
- Parameters:
comp_type (CoreComponentType) – The component type.
comp_name (str) – The name of the component.
- Returns:
CoreComponent – The resulting / created component.
- Return type:
- medcat2.components.types.get_registered_components(comp_type)
Get all registered components (name and class name for each).
- Parameters:
comp_type (CoreComponentType) – The core component type.
- Returns:
list[tuple[str, str]] – The name and class name for each registered component.
- Return type:
list[tuple[str, str]]