FileAnnotator
dorsal.file.file_annotator.FileAnnotator
Orchestrates on-demand annotation of local files.
Acts as a bridge between high-level callers (like LocalFile) and the ModelRunner, handling single annotation tasks, validating manual data, and wrapping results into a standardized format.
annotate_file_using_model_and_validator
annotate_file_using_model_and_validator(
*,
file_path,
model_runner,
annotation_model_cls,
schema_id,
schema_version=None,
private,
options=None,
validation_model=None,
ignore_linter_errors=False
)
Runs a given annotation model class directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the local file. |
required |
model_runner
|
ModelRunner
|
An instance of the ModelRunner. |
required |
annotation_model_cls
|
Type[AnnotationModel]
|
The annotation model class to execute. |
required |
schema_id
|
str
|
The dataset ID for the resulting annotation. |
required |
options
|
dict | None
|
Optional keyword arguments for the model's main() method. |
None
|
validation_model
|
Type[BaseModel] | JsonSchemaValidator | None
|
Optional validator for the model's output. |
None
|
Returns:
| Type | Description |
|---|---|
Annotation | AnnotationGroup
|
An |
Raises:
| Type | Description |
|---|---|
AnnotationConfigurationError
|
If |
AnnotationExecutionError
|
If the model fails to run. |
Source code in venv/lib/python3.13/site-packages/dorsal/file/file_annotator.py
annotate_file_using_pipeline_step
annotate_file_using_pipeline_step(
*,
file_path,
model_runner,
pipeline_step,
schema_id=None,
schema_version=None,
private
)
Runs an annotation model defined by a single pipeline step.
Note: This ignores any dependency rules within the pipeline step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Absolute or relative path to the local file. |
required |
model_runner
|
ModelRunner
|
An instance of the ModelRunner. |
required |
pipeline_step
|
ModelRunnerPipelineStep | dict[str, Any]
|
A |
required |
schema_id
|
str | None
|
Optional. Overrides the |
None
|
Returns:
| Type | Description |
|---|---|
Annotation | AnnotationGroup
|
An |
Raises:
| Type | Description |
|---|---|
AnnotationConfigurationError
|
If the pipeline_step config is invalid. |
AnnotationImportError
|
If the specified model or validator cannot be imported. |
AnnotationExecutionError
|
If the model fails to run or its output is invalid. |
Source code in venv/lib/python3.13/site-packages/dorsal/file/file_annotator.py
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 | |
make_manual_annotation
make_manual_annotation(
*,
annotation,
schema_id,
schema_version=None,
source_id,
validator=None,
private,
ignore_linter_errors=False,
force=False
)
Creates a fully-formed Annotation object from a manual payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotation
|
BaseModel | dict[str, Any]
|
The annotation data (dict or Pydantic model). |
required |
schema_id
|
str
|
The validation schema for this annotation. |
required |
detail
|
A string describing the source of the manual annotation. |
required | |
validator
|
Type[BaseModel] | JsonSchemaValidator | None
|
An optional validator for the payload. |
None
|
Returns:
| Type | Description |
|---|---|
Annotation | AnnotationGroup
|
A constructed and validated |
Raises:
| Type | Description |
|---|---|
AnnotationConfigurationError
|
If config/types are invalid. |
AnnotationValidationError
|
If the payload fails validation. |
DataQualityError
|
If the payload fails post-validation data quality linting. |
Source code in venv/lib/python3.13/site-packages/dorsal/file/file_annotator.py
validate_manual_annotation
Validates a user-provided annotation payload against an optional validator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
annotation
|
BaseModel | dict[str, Any]
|
The annotation data payload (dict or Pydantic model). |
required |
validator
|
Type[BaseModel] | JsonSchemaValidator | None
|
The validator to use (Pydantic class or JsonSchemaValidator instance). |
required |
file_hash
|
(Deprecated) The primary hash of the file being annotated. No longer injected into the record. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The validated annotation as a dictionary. |
Raises:
| Type | Description |
|---|---|
AnnotationConfigurationError
|
If the annotation or validator type is unsupported. |
AnnotationValidationError
|
If the annotation fails validation. |
Source code in venv/lib/python3.13/site-packages/dorsal/file/file_annotator.py
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 | |