1
+ from labelbox .data .annotation_types .classification .classification import VideoClassificationAnswer
1
2
from typing import List , Union
2
3
3
4
from pydantic .main import BaseModel
@@ -12,27 +13,44 @@ class LBV1ClassificationAnswer(LBV1Feature):
12
13
...
13
14
14
15
16
+ def get_classification_answer (
17
+ answer : LBV1ClassificationAnswer
18
+ ) -> Union [ClassificationAnswer , VideoClassificationAnswer ]:
19
+ kwargs = dict (feature_schema_id = answer .schema_id ,
20
+ name = answer .title ,
21
+ extra = {
22
+ 'feature_id' : answer .feature_id ,
23
+ 'value' : answer .value
24
+ })
25
+ if answer .keyframe is not None :
26
+ return VideoClassificationAnswer (keyframe = answer .keyframe , ** kwargs )
27
+ else :
28
+ return ClassificationAnswer (** kwargs )
29
+
30
+
31
+ def get_lbv1_classification_answer (answer : Union [ClassificationAnswer ,
32
+ VideoClassificationAnswer ]):
33
+ return LBV1ClassificationAnswer (
34
+ schema_id = answer .feature_schema_id ,
35
+ title = answer .name ,
36
+ value = answer .extra .get ('value' ),
37
+ feature_id = answer .extra .get ('feature_id' ),
38
+ keyframe = getattr (answer , 'keyframe' ,
39
+ None ) # Only applies to video clasifications
40
+ )
41
+
42
+
15
43
class LBV1Radio (LBV1Feature ):
16
44
answer : LBV1ClassificationAnswer
17
45
18
46
def to_common (self ) -> Radio :
19
- return Radio (answer = ClassificationAnswer (
20
- feature_schema_id = self .answer .schema_id ,
21
- name = self .answer .title ,
22
- extra = {
23
- 'feature_id' : self .answer .feature_id ,
24
- 'value' : self .answer .value
25
- }))
47
+ return Radio (answer = get_classification_answer (self .answer ))
26
48
27
49
@classmethod
28
50
def from_common (cls , radio : Radio , feature_schema_id : Cuid ,
29
51
** extra ) -> "LBV1Radio" :
30
52
return cls (schema_id = feature_schema_id ,
31
- answer = LBV1ClassificationAnswer (
32
- schema_id = radio .answer .feature_schema_id ,
33
- title = radio .answer .name ,
34
- value = radio .answer .extra .get ('value' ),
35
- feature_id = radio .answer .extra .get ('feature_id' )),
53
+ answer = get_lbv1_classification_answer (radio .answer ),
36
54
** extra )
37
55
38
56
@@ -41,24 +59,15 @@ class LBV1Checklist(LBV1Feature):
41
59
42
60
def to_common (self ) -> Checklist :
43
61
return Checklist (answer = [
44
- ClassificationAnswer (feature_schema_id = answer .schema_id ,
45
- name = answer .title ,
46
- extra = {
47
- 'feature_id' : answer .feature_id ,
48
- 'value' : answer .value
49
- }) for answer in self .answers
62
+ get_classification_answer (answer ) for answer in self .answers
50
63
])
51
64
52
65
@classmethod
53
66
def from_common (cls , checklist : Checklist , feature_schema_id : Cuid ,
54
67
** extra ) -> "LBV1Checklist" :
55
68
return cls (schema_id = feature_schema_id ,
56
69
answers = [
57
- LBV1ClassificationAnswer (
58
- schema_id = answer .feature_schema_id ,
59
- title = answer .name ,
60
- value = answer .extra .get ('value' ),
61
- feature_id = answer .extra .get ('feature_id' ))
70
+ get_lbv1_classification_answer (answer )
62
71
for answer in checklist .answer
63
72
],
64
73
** extra )
@@ -69,24 +78,15 @@ class LBV1Dropdown(LBV1Feature):
69
78
70
79
def to_common (self ) -> Dropdown :
71
80
return Dropdown (answer = [
72
- ClassificationAnswer (feature_schema_id = answer .schema_id ,
73
- name = answer .title ,
74
- extra = {
75
- 'feature_id' : answer .feature_id ,
76
- 'value' : answer .value
77
- }) for answer in self .answer
81
+ get_classification_answer (answer ) for answer in self .answer
78
82
])
79
83
80
84
@classmethod
81
85
def from_common (cls , dropdown : Dropdown , feature_schema_id : Cuid ,
82
86
** extra ) -> "LBV1Dropdown" :
83
87
return cls (schema_id = feature_schema_id ,
84
88
answer = [
85
- LBV1ClassificationAnswer (
86
- schema_id = answer .feature_schema_id ,
87
- title = answer .name ,
88
- value = answer .extra .get ('value' ),
89
- feature_id = answer .extra .get ('feature_id' ))
89
+ get_lbv1_classification_answer (answer )
90
90
for answer in dropdown .answer
91
91
],
92
92
** extra )
0 commit comments