-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathannotator.py
More file actions
78 lines (58 loc) · 1.97 KB
/
annotator.py
File metadata and controls
78 lines (58 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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
"""
Defines data models for annotation requests and results.
Contains Pydantic models for structuring input, output, and explanations
in the annotation process. Ensures type safety and consistent data handling.
"""
from typing import List, Optional
from pydantic import BaseModel, field_validator
from .common import AnnotatorMetadata, EntityTypes, PatternRecognizer
class AnnotatorRequest(BaseModel):
"""
Represents an annotation request.
Contains text to annotate, language, and optional parameters
to customize the annotation process.
"""
text: str
language: str
correlation_id: Optional[str]
score_threshold: Optional[float]
entities: Optional[List[EntityTypes]]
return_decision_process: Optional[bool]
ad_hoc_recognizers: Optional[List[PatternRecognizer]]
context: Optional[List[str]]
class AnnotationResult(BaseModel):
"""
Represents the result of an annotation.
Includes position, score, entity type, and optional metadata.
"""
start: int
end: int
score: Optional[float]
entity_type: str
recognition_metadata: Optional[AnnotatorMetadata]
@field_validator("entity_type")
@classmethod
def validate_entity_type(cls, v):
if v not in EntityTypes.__members__:
return "UNKNOWN"
return v
class AnalysisExplanation(BaseModel):
"""
Provides detailed explanation of an annotation analysis.
Includes information about the recognizer, patterns, scores,
and context improvements.
"""
recognizer: str
pattern_name: Optional[str]
pattern: Optional[str]
original_score: float
score: float
textual_explanation: Optional[str]
score_context_improvement: float
supportive_context_word: str
validation_result: Optional[float]
class AnnotationResultWithAnaysisExplanation(AnnotationResult):
"""
Extends AnnotationResult with detailed analysis explanation.
"""
analysis_explanation: Optional[AnalysisExplanation]