Terminology mapper
Provide the main terminology-mapping orchestration utilities for the package.
This module defines the high-level mapping workflow that converts source concepts into standardized concepts using a configurable pipeline composed of translation, retrieval, reranking, and selection stages. It also includes a rate-limiting helper and utilities for loading mapping tasks from structured configuration objects.
The main entry point is TerminologyMapper, which can read OMOP-like source
concept files, process them in batches, and write the mapped output to disk.
TerminologyMapper
Coordinate end-to-end terminology mapping through a configurable pipeline.
This class orchestrates the full mapping workflow for source concepts, including optional translation, candidate retrieval, reranking, final selection, batching, rate limiting, and output generation. It is designed to work with OMOP-style source concept files and pluggable pipeline components.
Instances can be created directly by passing configured components or built
from a structured TerminologyMappingTask configuration object.
Source code in aatm\terminology_mapper.py
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 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 131 132 133 134 135 136 137 138 139 140 141 142 143 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 200 201 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 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 263 264 265 266 267 268 269 270 271 272 273 274 275 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 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 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 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 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 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 | |
__init__(input_file=None, output_dir=Path('output'), translator=None, retriever=None, selector=None, reranker=None, batch_size=None, rate_limit=None, column_mapping=None, limit_to=None, *args, **kwargs)
Initialize the terminology mapper and its pipeline components.
This constructor sets up the terminology-mapping pipeline, defaulting to built-in translator, retriever, selector, and reranker behaviors when custom components are not provided. It also prepares output paths, stores batching and rate-limiting settings, and defines the expected input schema for source concept files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_file
|
Optional[str | Path]
|
Optional path to the source concept file to map. |
None
|
output_dir
|
str | Path
|
Directory where mapping outputs will be written. |
Path('output')
|
translator
|
Optional[BaseTranslator | str]
|
Optional translator component used before retrieval. Expects a BaseTranslator or the translator id in the registry. |
None
|
retriever
|
Optional[BaseRetriever | str]
|
Optional retriever component used to fetch candidate concepts. Expects a BaseRetriever or the retriever id in the registry. |
None
|
selector
|
Optional[BaseSelector | str]
|
Optional selector component used to choose the final mapped concept. Expects a BaseSelector or the selector id in the registry. |
None
|
reranker
|
Optional[BaseReranker | str]
|
Optional reranker component used to reorder retrieved candidates before selection. Expects a BaseReranker or the reranker id in the registry. |
None
|
batch_size
|
Optional[int]
|
Number of source concepts to process per batch. |
None
|
rate_limit
|
Optional[int]
|
Optional maximum number of items to process per minute. |
None
|
column_mapping
|
Optional[dict]
|
Optional mapping from input column names to the expected OMOP-style column names. |
None
|
limit_to
|
Optional[int]
|
Optional maximum number of input rows to process. |
None
|
*args
|
Any
|
Additional positional arguments reserved for compatibility. |
()
|
**kwargs
|
Any
|
Additional keyword arguments reserved for compatibility. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None. |
Source code in aatm\terminology_mapper.py
91 92 93 94 95 96 97 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 131 132 133 134 135 136 137 138 139 140 141 142 143 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 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 | |
from_task_config(task_config)
classmethod
Create a terminology mapper from a task configuration object.
This factory method resolves the configured translator, retriever,
selector, and reranker from their registries and initializes a
TerminologyMapper with the remaining task parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_config
|
TerminologyMappingTask
|
Structured task configuration describing the mapping pipeline and runtime settings. |
required |
Returns:
| Type | Description |
|---|---|
TerminologyMapper
|
A configured |
Source code in aatm\terminology_mapper.py
map(expressions=None, file_path=None, limit_to=None, output_dir=None, return_as='df', save_to_disk=True)
Map source concepts from a file to standardized concepts.
This method loads source concepts from a supported input file or from a list of strings or SourceConcept objects, processes them in batches through the pipeline, and returns the mapped results as a DataFrame. The resulting mappings are also written to a CSV file in the output directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expressions
|
Optional[List[str | SourceConcept]]
|
Optional list of expressions to map. Expects a list of strings or SourceConcept objects. |
None
|
file_path
|
str | Path
|
Optional path to the source concept file. If not provided, the mapper's configured input file is used. |
None
|
limit_to
|
int
|
Optional maximum number of rows to process from the source file. |
None
|
output_dir
|
str | Path
|
Optional output directory override for this mapping operation. |
None
|
return_as
|
Literal['df', 'mapped_source_concepts']
|
Return type. Options: "df" or "mapped_source_concepts". |
'df'
|
save_to_disk
|
bool
|
Whether to save the results to disk. |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
A pandas DataFrame containing the mapped source concepts. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no file path is available or the file type is not supported. |
Source code in aatm\terminology_mapper.py
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 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 | |
amap(file_path=None, limit_to=None, return_confidence_scores=True, output_dir=None)
async
Asynchronously map source concepts from a file to standardized concepts.
This method is the asynchronous counterpart to map(). It processes
source concepts in batches through the configured pipeline using async
calls where supported, then writes the mapped results to a CSV file and
returns them as a DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str | Path
|
Optional path to the source concept file. |
None
|
limit_to
|
int
|
Optional maximum number of rows to process from the source file. |
None
|
return_confidence_scores
|
bool
|
Whether to include confidence scores in the returned output DataFrame. |
True
|
output_dir
|
str | Path
|
Optional output directory override for this mapping operation. |
None
|
Returns:
| Type | Description |
|---|---|
Tuple[DataFrame, List[float]] | DataFrame
|
A pandas DataFrame containing the mapped source concepts. The |
Tuple[DataFrame, List[float]] | DataFrame
|
current annotation allows for a tuple including confidence scores, |
Tuple[DataFrame, List[float]] | DataFrame
|
but the present implementation returns only the DataFrame. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no file path is provided or the file type is not supported. |
Source code in aatm\terminology_mapper.py
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 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 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | |
map_csv_to_source_concepts(file_path, limit_to=None)
Load source concepts from a CSV file and convert them to model objects.
This method reads a CSV file, optionally limits the number of rows,
applies any configured column renaming, validates that the required
OMOP-style columns are present, drops rows with missing source concept
descriptions, and converts the remaining rows into SourceConcept
objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
Path
|
Path to the CSV file containing source concepts. |
required |
limit_to
|
int
|
Optional maximum number of rows to load from the file. |
None
|
Returns:
| Type | Description |
|---|---|
List[SourceConcept]
|
A list of |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the input file does not contain the required columns after optional column remapping. |
Source code in aatm\terminology_mapper.py
__call__(expression)
Invoke the mapper as a callable object.
This method delegates to map() so that mapper instances can be used
like callable pipeline components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expression
|
str
|
Input expression or file reference to map. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The result of calling |
Notes
The current type annotation suggests a string input and string
output, but the underlying map() method expects file-based
input and returns a DataFrame.
Source code in aatm\terminology_mapper.py
__repr__()
Return the official string representation of the mapper.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the |
__str__()
Return a human-readable string representation of the mapper.
Returns:
| Type | Description |
|---|---|
str
|
A string representation of the |
rate_limit(n_docs, next_allowed_time, rate_limit)
Apply a document-based rate limit and return the next allowed time.
This helper delays execution when necessary to ensure that processing does not exceed the configured throughput in documents per minute. It uses a monotonic clock to avoid issues caused by system clock adjustments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n_docs
|
int
|
Number of documents in the current batch. |
required |
next_allowed_time
|
float
|
Monotonic timestamp representing the next permitted processing time. |
required |
rate_limit
|
int
|
Maximum number of documents allowed per minute. |
required |
Returns:
| Type | Description |
|---|---|
None
|
The updated monotonic timestamp indicating when the next batch may be processed. |
Notes
The return annotation in the current implementation is None, but
the function actually returns the updated next allowed time.