1
1
from typing import Any , Dict , List , Union , Optional
2
- import warnings
3
2
from labelbox .data .annotation_types .base_annotation import BaseAnnotation
4
3
5
4
from labelbox .data .mixins import ConfidenceMixin , CustomMetricsMixin
6
5
7
- try :
8
- from typing import Literal
9
- except :
10
- from typing_extensions import Literal
11
-
12
- from labelbox import pydantic_compat
6
+ from pydantic import BaseModel
13
7
from ..feature import FeatureSchema
14
8
15
9
16
- # TODO: Replace when pydantic adds support for unions that don't coerce types
17
- class _TempName (ConfidenceMixin , pydantic_compat .BaseModel ):
18
- name : str
19
-
20
- def dict (self , * args , ** kwargs ):
21
- res = super ().dict (* args , ** kwargs )
22
- res .pop ('name' )
23
- return res
24
-
25
-
26
10
class ClassificationAnswer (FeatureSchema , ConfidenceMixin , CustomMetricsMixin ):
27
11
"""
28
12
- Represents a classification option.
@@ -36,18 +20,10 @@ class ClassificationAnswer(FeatureSchema, ConfidenceMixin, CustomMetricsMixin):
36
20
"""
37
21
extra : Dict [str , Any ] = {}
38
22
keyframe : Optional [bool ] = None
39
- classifications : List ['ClassificationAnnotation' ] = []
23
+ classifications : Optional [ List ['ClassificationAnnotation' ]] = None
40
24
41
- def dict (self , * args , ** kwargs ) -> Dict [str , str ]:
42
- res = super ().dict (* args , ** kwargs )
43
- if res ['keyframe' ] is None :
44
- res .pop ('keyframe' )
45
- if res ['classifications' ] == []:
46
- res .pop ('classifications' )
47
- return res
48
25
49
-
50
- class Radio (ConfidenceMixin , CustomMetricsMixin , pydantic_compat .BaseModel ):
26
+ class Radio (ConfidenceMixin , CustomMetricsMixin , BaseModel ):
51
27
""" A classification with only one selected option allowed
52
28
53
29
>>> Radio(answer = ClassificationAnswer(name = "dog"))
@@ -56,17 +32,16 @@ class Radio(ConfidenceMixin, CustomMetricsMixin, pydantic_compat.BaseModel):
56
32
answer : ClassificationAnswer
57
33
58
34
59
- class Checklist (_TempName ):
35
+ class Checklist (ConfidenceMixin , BaseModel ):
60
36
""" A classification with many selected options allowed
61
37
62
38
>>> Checklist(answer = [ClassificationAnswer(name = "cloudy")])
63
39
64
40
"""
65
- name : Literal ["checklist" ] = "checklist"
66
41
answer : List [ClassificationAnswer ]
67
42
68
43
69
- class Text (ConfidenceMixin , CustomMetricsMixin , pydantic_compat . BaseModel ):
44
+ class Text (ConfidenceMixin , CustomMetricsMixin , BaseModel ):
70
45
""" Free form text
71
46
72
47
>>> Text(answer = "some text answer")
@@ -75,24 +50,6 @@ class Text(ConfidenceMixin, CustomMetricsMixin, pydantic_compat.BaseModel):
75
50
answer : str
76
51
77
52
78
- class Dropdown (_TempName ):
79
- """
80
- - A classification with many selected options allowed .
81
- - This is not currently compatible with MAL.
82
-
83
- Deprecation Notice: Dropdown classification is deprecated and will be
84
- removed in a future release. Dropdown will also
85
- no longer be able to be created in the Editor on 3/31/2022.
86
- """
87
- name : Literal ["dropdown" ] = "dropdown"
88
- answer : List [ClassificationAnswer ]
89
-
90
- def __init__ (self , ** data : Any ):
91
- super ().__init__ (** data )
92
- warnings .warn ("Dropdown classification is deprecated and will be "
93
- "removed in a future release" )
94
-
95
-
96
53
class ClassificationAnnotation (BaseAnnotation , ConfidenceMixin ,
97
54
CustomMetricsMixin ):
98
55
"""Classification annotations (non localized)
@@ -106,12 +63,9 @@ class ClassificationAnnotation(BaseAnnotation, ConfidenceMixin,
106
63
name (Optional[str])
107
64
classifications (Optional[List[ClassificationAnnotation]]): Optional sub classification of the annotation
108
65
feature_schema_id (Optional[Cuid])
109
- value (Union[Text, Checklist, Radio, Dropdown ])
66
+ value (Union[Text, Checklist, Radio])
110
67
extra (Dict[str, Any])
111
68
"""
112
69
113
- value : Union [Text , Checklist , Radio , Dropdown ]
70
+ value : Union [Text , Checklist , Radio ]
114
71
message_id : Optional [str ] = None
115
-
116
-
117
- ClassificationAnswer .update_forward_refs ()
0 commit comments