parent_selector
Stated parent selection for new SNOMED CT clinical concepts.
The RF2 exporter writes new concepts as sufficiently defined, so the classifier can infer fully defined supertypes from the attributes but never primitive ones. The stated parent therefore has to be a primitive concept, ideally the proximal primitive parent.
Allowed parents are the primitive SNOMED descendants of root_concept_id (Clinical finding); the
root itself is the fallback.
Algorithm, per source term
- Neighbours: the
num_neighboursmost similar standard SNOMED concepts (embedding search) withsimilarity >= min_similarity. Withexclude_source_descendantsthe source concept and its descendants are dropped first, because they would not exist for a genuinely new concept. - Candidates: the primitive ancestors of each neighbour (the neighbour itself excluded).
- Support: the similarity-weighted share of neighbours below each candidate.
- Selection: candidates with
support >= min_support, minus any candidate that is an ancestor of another qualifying candidate, deepest first (min_levels_of_separationfrom the root), capped atmax_parents. When neighbours agree this is their proximal primitive parent; when they disagree it is an intermediate primitive. - Fallback: the root when no candidate qualifies.
Usage::
with psycopg.connect(conn_str) as conn:
stated_parents, details = build_stated_parents_map(
raw_results, conn, schema, config.hierarchy.parent_selection
)
# stated_parents: {source_concept_id (or source_key): [parent_sctid, ...]}
PrimitiveAncestry
dataclass
Strict primitive ancestors per concept, restricted to the allowed parent set.
Source code in src/ariadne/hierarchy/parent_selector.py
76 77 78 79 80 81 82 83 84 | |
build_stated_parents_map(raw_results, conn, schema, settings, *, neighbours=None)
Select stated parents for every entry of the hierarchy pipeline results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_results
|
list[dict]
|
Result dicts from |
required |
conn
|
Connection
|
Open psycopg connection to the vocabulary database. |
required |
schema
|
str
|
OHDSI Vocabularies schema name. |
required |
settings
|
ParentSelectionConfig
|
|
required |
neighbours
|
dict[str, list[Neighbour]] | None
|
Pre-computed |
None
|
Returns:
| Type | Description |
|---|---|
dict[int | str, list[str]]
|
|
DataFrame
|
expected by |
tuple[dict[int | str, list[str]], DataFrame]
|
with its support, depth and whether it is the fallback. |
Source code in src/ariadne/hierarchy/parent_selector.py
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 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | |
fetch_descendants(ancestor_ids, candidate_ids, conn, schema)
Return {ancestor_id: {candidate_id, ...}} for candidates that descend from (or equal) each ancestor.
Source code in src/ariadne/hierarchy/parent_selector.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 | |
fetch_primitive_ancestry(concept_ids, conn, schema, settings)
Fetch the strict primitive ancestors of concept_ids and, recursively, of those ancestors.
The ancestors of the ancestors are needed to tell which candidate parents subsume each other.
Source code in src/ariadne/hierarchy/parent_selector.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
most_specific(concept_ids, ancestry)
Drop every concept that is an ancestor of another concept in the set.
Source code in src/ariadne/hierarchy/parent_selector.py
92 93 94 95 | |
proximal_primitive_parents(concept_id, ancestry)
Proximal primitive parents of an existing concept, deepest first.
Source code in src/ariadne/hierarchy/parent_selector.py
133 134 135 136 | |
retrieve_neighbours(terms, settings)
Return the candidate_pool_size most similar standard SNOMED concepts per term.
Results are cached in settings.neighbour_cache_file; only uncached terms are searched.
Source code in src/ariadne/hierarchy/parent_selector.py
276 277 278 279 280 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 | |
select_primitive_parents(neighbours, ancestry, *, min_support, max_parents)
Pick the deepest primitive ancestors shared by enough of the neighbours.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
neighbours
|
Sequence[Neighbour]
|
Usable neighbours (already filtered for exclusions and similarity). |
required |
ancestry
|
PrimitiveAncestry
|
Primitive ancestors of the neighbours and of every candidate parent. |
required |
min_support
|
float
|
Minimum similarity-weighted share of neighbours below a candidate. |
required |
max_parents
|
int
|
Maximum number of parents returned. |
required |
Returns:
| Type | Description |
|---|---|
list[ParentCandidate]
|
Parents ordered deepest first, then by support. Empty when nothing qualifies. |
Source code in src/ariadne/hierarchy/parent_selector.py
98 99 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 | |