Arkindex Workers¶
arkindex_worker.worker ¶
Base classes to implement Arkindex workers.
Classes¶
ActivityState ¶
Bases: Enum
Processing state of an element.
Attributes¶
Queued
class-attribute
instance-attribute
¶
Queued = 'queued'
The element has not yet been processed by a worker.
Started
class-attribute
instance-attribute
¶
Started = 'started'
The element is being processed by a worker.
Processed
class-attribute
instance-attribute
¶
Processed = 'processed'
The element has been successfully processed by a worker.
Error
class-attribute
instance-attribute
¶
Error = 'error'
An error occurred while processing this element.
ElementsWorker ¶
ElementsWorker(
description: str = "Arkindex Elements Worker",
support_cache: bool = False,
)
Bases: BaseWorker
, ClassificationMixin
, CorpusMixin
, ElementMixin
, TranscriptionMixin
, WorkerVersionMixin
, EntityMixin
, MetaDataMixin
, ImageMixin
Base class for ML workers that operate on Arkindex elements.
This class inherits from numerous mixin classes found in other modules of
arkindex.worker
, which provide helpers to read and write to the Arkindex API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
description |
str
|
The worker’s description |
'Arkindex Elements Worker'
|
support_cache |
bool
|
Whether the worker supports cache |
False
|
Source code in arkindex_worker/worker/__init__.py
77 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 |
|
Attributes¶
entity_types
instance-attribute
¶
entity_types = {}
Known and available entity types in processed corpus
store_activity
property
¶
store_activity: bool
Whether or not WorkerActivity support has been enabled on the DataImport used to run this worker.
Functions¶
list_elements ¶
list_elements() -> Iterable[CachedElement] | list[str]
List the elements to be processed, either from the CLI arguments or the cache database when enabled.
Returns:
Type | Description |
---|---|
Iterable[CachedElement] | list[str]
|
An iterable of CachedElement when cache support is enabled, or a list of strings representing element IDs otherwise. |
Source code in arkindex_worker/worker/__init__.py
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 |
|
configure ¶
configure()
Setup the worker using CLI arguments and environment variables.
Source code in arkindex_worker/worker/__init__.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
|
run ¶
run()
Implements an Arkindex worker that goes through each element returned by list_elements. It calls process_element, catching exceptions, and handles saving WorkerActivity updates when enabled.
Source code in arkindex_worker/worker/__init__.py
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 |
|
process_element ¶
process_element(element: Element | CachedElement)
Override this method to implement your worker and process a single Arkindex element at once.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element |
Element | CachedElement
|
The element to process. Will be a CachedElement instance if cache support is enabled, and an Element instance otherwise. |
required |
Source code in arkindex_worker/worker/__init__.py
273 274 275 276 277 278 279 280 |
|
update_activity ¶
update_activity(
element_id: str | uuid.UUID, state: ActivityState
) -> bool
Update the WorkerActivity for this element and worker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
element_id |
str | UUID
|
ID of the element. |
required |
state |
ActivityState
|
New WorkerActivity state for this element. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if the update has been successful or WorkerActivity support is disabled. False if the update has failed due to a conflict; this worker might have already processed this element. |
Source code in arkindex_worker/worker/__init__.py
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 |
|
MissingDatasetArchive ¶
Bases: Exception
Exception raised when the compressed archive associated to a dataset isn’t found in its task artifacts.
DatasetWorker ¶
DatasetWorker(
description: str = "Arkindex Dataset Worker",
support_cache: bool = False,
)
Bases: BaseWorker
, DatasetMixin
, TaskMixin
Base class for ML workers that operate on Arkindex dataset sets.
This class inherits from numerous mixin classes found in other modules of
arkindex.worker
, which provide helpers to read and write to the Arkindex API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
description |
str
|
The worker’s description. |
'Arkindex Dataset Worker'
|
support_cache |
bool
|
Whether the worker supports cache. |
False
|
Source code in arkindex_worker/worker/__init__.py
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 |
|
Functions¶
configure ¶
configure()
Setup the worker using CLI arguments and environment variables.
Source code in arkindex_worker/worker/__init__.py
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
|
cleanup_downloaded_artifact ¶
cleanup_downloaded_artifact() -> None
Cleanup the downloaded dataset artifact if any
Source code in arkindex_worker/worker/__init__.py
415 416 417 418 419 420 421 422 |
|
download_dataset_artifact ¶
download_dataset_artifact(dataset: Dataset) -> None
Find and download the compressed archive artifact describing a dataset using the list_artifacts and download_artifact methods.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset |
Dataset
|
The dataset to retrieve the compressed archive artifact for. |
required |
Raises:
Type | Description |
---|---|
MissingDatasetArchive
|
When the dataset artifact is not found. |
Source code in arkindex_worker/worker/__init__.py
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 |
|
process_set ¶
process_set(set: Set)
Override this method to implement your worker and process a single Arkindex dataset set at once.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
set |
Set
|
The set to process. |
required |
Source code in arkindex_worker/worker/__init__.py
455 456 457 458 459 460 |
|
list_sets ¶
list_sets() -> Iterator[Set]
List the sets to be processed, either from the CLI arguments or using the list_process_sets method.
Returns:
Type | Description |
---|---|
Iterator[Set]
|
An iterator of |
Source code in arkindex_worker/worker/__init__.py
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 |
|
run ¶
run()
Implements an Arkindex worker that goes through each dataset set returned by list_sets.
It calls process_set, catching exceptions.
Source code in arkindex_worker/worker/__init__.py
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 |
|