medcat.utils.regression.targeting
Classes:
-
FinalTarget–The final target.
-
OptionSet–The targeting option set.
-
PhraseChanger–The phrase changer.
-
ProblematicOptionSetException– -
TargetPlaceholder–A class describing the options for a specific placeholder.
-
TargetedPhraseChanger–The target phrase changer.
-
TranslationLayer–The translation layer for translating:
Attributes:
-
logger–
FinalTarget
Bases: BaseModel
The final target.
This involves the final phrase (which (potentially) has other placeholder replaced in it), the placeholder to be replaced, and the CUI and specific name being used.
Attributes:
-
cui(str) – -
final_phrase(str) – -
name(str) – -
placeholder(str) –
OptionSet
Bases: BaseModel
The targeting option set.
This describes all the target placeholders and concepts needed.
Methods:
-
estimate_num_of_subcases–Get the number of distinct subcases.
-
from_dict–Construct a OptionSet instance from a dict.
-
get_preprocessors_and_targets–Get the targeted phrase changers.
-
to_dict–Convert the OptionSet to a dict.
Attributes:
estimate_num_of_subcases
estimate_num_of_subcases() -> int
Get the number of distinct subcases.
This includes ones that can be calculated without the knowledge of the underlying CDB. I.e it doesn't care for the number of names involved per CUI but only takes into account what is described in the option set itself.
If any combination is allowed, then the answer is the combination of the number of target concepts per option. If any combination is not allowed, then the answer is simply the number of target concepts for an option (they should all have the same number).
Returns:
-
int(int) –Te number of subcases.
Source code in medcat-v2/medcat/utils/regression/targeting.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 | |
from_dict
classmethod
Construct a OptionSet instance from a dict.
The assumed structure is:
{
'placeholders': [
{
'placeholder':
The prefname-only key is optional.
Parameters:
Raises:
-
ProblematicOptionSetException–If incorrect number of CUIs when not allowing any combination
-
ProblematicOptionSetException–If placeholders not a list
-
ProblematicOptionSetException–If multiple placehodlers with same place holder
Returns:
-
OptionSet(OptionSet) –The resulting OptionSet
Source code in medcat-v2/medcat/utils/regression/targeting.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
get_preprocessors_and_targets
get_preprocessors_and_targets(translation: TranslationLayer) -> Iterator[TargetedPhraseChanger]
Get the targeted phrase changers.
Parameters:
-
(translationTranslationLayer) –The translaton layer.
Yields:
-
TargetedPhraseChanger–Iterator[TargetedPhraseChanger]: Thetarget phrase changers.
Source code in medcat-v2/medcat/utils/regression/targeting.py
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | |
to_dict
to_dict() -> dict
Convert the OptionSet to a dict.
Returns:
-
dict(dict) –The dict representation
Source code in medcat-v2/medcat/utils/regression/targeting.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
PhraseChanger
Bases: BaseModel
The phrase changer.
This is class used as a preprocessor for phrases with multiple placeholders. It allows swapping in the rest of the placeholders while leaving in the one that's being tested for.
Methods:
-
empty–Gets the empty phrase changer.
Attributes:
-
preprocess_placeholders(list[tuple[str, str]]) –
empty
classmethod
empty() -> PhraseChanger
Gets the empty phrase changer.
That is a phrase changer that makes no changes to the phrase.
Returns:
-
PhraseChanger(PhraseChanger) –The empty phrase changer.
Source code in medcat-v2/medcat/utils/regression/targeting.py
236 237 238 239 240 241 242 243 244 245 | |
ProblematicOptionSetException
ProblematicOptionSetException(*args: object)
Bases: ValueError
Source code in medcat-v2/medcat/utils/regression/targeting.py
487 488 | |
TargetPlaceholder
Bases: BaseModel
A class describing the options for a specific placeholder.
Attributes:
-
onlyprefnames(bool) – -
placeholder(str) – -
target_cuis(list[str]) –
TargetedPhraseChanger
Bases: BaseModel
The target phrase changer.
It includes the phrase changer (for preprocessing) along with the relevant concept and the placeholder it will replace.
Attributes:
-
changer(PhraseChanger) – -
cui(str) – -
onlyprefnames(bool) – -
placeholder(str) –
TranslationLayer
TranslationLayer(cui2info: dict[str, CUIInfo], name2info: dict[str, NameInfo], cui2children: dict[str, set[str]], separator: str, whitespace: str = ' ')
The translation layer for translating: - CUIs to names - names to CUIs - type_ids to CUIs - CUIs to chil CUIs
The idea is to decouple these translations from the CDB instance in case something changes there.
Parameters:
-
(cui2infodict[str, CUIInfo]) –The map from CUI to names
-
(name2infodict[str, NameInfo]) –The map from name to CUIs
-
(cui2type_idsdict[str, set[str]]) –The map from CUI to type_ids
-
(cui2childrendict[str, set[str]]) –The map from CUI to child CUIs
Methods:
-
from_CDB–Construct a TranslationLayer object from a context database (CDB).
-
get_children_of–Get the children of the specifeid CUI in the
-
get_direct_children–Get the direct children of a concept.
-
get_direct_parents–Get the direct parent(s) of a concept.
-
get_first_name–Get the preprocessed (potentially) arbitrarily first name
-
get_names_of–Get the preprocessed names of a CUI.
-
get_preferred_name–Get the preferred name of a concept.
Attributes:
-
cui2children– -
cui2info– -
name2info– -
separator– -
type_id2cuis(dict[str, set[str]]) – -
whitespace–
Source code in medcat-v2/medcat/utils/regression/targeting.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
separator
instance-attribute
separator = separator
whitespace
instance-attribute
whitespace = whitespace
from_CDB
classmethod
from_CDB(cdb: CDB) -> TranslationLayer
Construct a TranslationLayer object from a context database (CDB).
This translation layer will refer to the same dicts that the CDB refers to. While there is no obvious reason these should be modified, it's something to keep in mind.
Parameters:
-
(cdbCDB) –The CDB
Returns:
-
TranslationLayer(TranslationLayer) –The subsequent TranslationLayer
Source code in medcat-v2/medcat/utils/regression/targeting.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
get_children_of
Get the children of the specifeid CUI in the listed CUIs (if they exist).
Parameters:
-
(found_cuisIterable[str]) –The list of CUIs to look in
-
(cuistr) –The target parent CUI
-
(depthint, default:1) –The depth to carry out the search for
Returns:
Source code in medcat-v2/medcat/utils/regression/targeting.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
get_direct_children
Get the direct children of a concept.
This means only the children, but not grandchildren.
If the underlying CDB doesn't list children for this CUI, an empty list is returned.
Parameters:
-
(cuistr) –The concept in question.
Returns:
Source code in medcat-v2/medcat/utils/regression/targeting.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
get_direct_parents
cached
Get the direct parent(s) of a concept.
This method can be quite a CPU heavy one since it relies
on running through all the parent-children relationships since the child->parent(s) relationship isn't normally kept track of.
Parameters:
-
(cuistr) –description
Returns:
Source code in medcat-v2/medcat/utils/regression/targeting.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
get_first_name
Get the preprocessed (potentially) arbitrarily first name of the given concept.
If the concept does not exist, the CUI itself is returned.
PS: The "first" name may not be consistent across runs since it relies on set order.
Parameters:
-
(cuistr) –The concept ID.
Returns:
-
str(str) –The first name.
Source code in medcat-v2/medcat/utils/regression/targeting.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
get_names_of
Get the preprocessed names of a CUI.
This method preporcesses the names by replacing the separator
(generally ~) with the appropriate whitespace ().
If the concept is not in the underlying CDB, an empty list is returned.
Parameters:
-
(cuistr) –The concept in question.
-
(only_prefnamesbool) –Whether to only return a preferred name.
Returns:
Source code in medcat-v2/medcat/utils/regression/targeting.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 79 | |
get_preferred_name
Get the preferred name of a concept.
If no preferred name is found, the random 'first' name is selected.
Parameters:
-
(cuistr) –The concept ID.
Returns:
-
str(str) –The preferred name.
Source code in medcat-v2/medcat/utils/regression/targeting.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | |