11from typing import List , Union , Optional
22
3- from pydantic import BaseModel , validator
3+ from pydantic import BaseModel , validator , Field
44
55from ...annotation_types .annotation import AnnotationType , ClassificationAnnotation , VideoClassificationAnnotation
66from ...annotation_types .classification .classification import ClassificationAnswer , Dropdown , Text , Checklist , Radio
77from .base import NDAnnotation
88
99
1010class NDFeature (BaseModel ):
11- schemaId : str # = Field(..., alias = 'schemaId')
11+ schema_id : str = Field (..., alias = 'schemaId' )
1212
13- @validator ('schemaId ' , pre = True , always = True )
13+ @validator ('schema_id ' , pre = True , always = True )
1414 def validate_id (cls , v ):
1515 if v is None :
1616 raise ValueError (
1717 "Schema ids are not set. Use `LabelGenerator.assign_schema_ids`, `LabelCollection.assign_schema_ids`, or `Label.assign_schema_ids`."
1818 )
1919 return v
2020
21+ class Config :
22+ allow_population_by_field_name = True
23+
2124
2225class FrameLocation (BaseModel ):
2326 end : int
@@ -45,38 +48,39 @@ def to_common(self) -> Text:
4548 @classmethod
4649 def from_common (cls , annotation ) -> "NDTextSubclass" :
4750 return cls (answer = annotation .value .answer ,
48- schemaId = annotation .schema_id )
51+ schema_id = annotation .schema_id )
4952
5053
5154class NDChecklistSubclass (NDFeature ):
5255 answer : List [NDFeature ]
5356
5457 def to_common (self ) -> Checklist :
5558 return Checklist (answer = [
56- ClassificationAnswer (schema_id = answer .schemaId )
59+ ClassificationAnswer (schema_id = answer .schema_id )
5760 for answer in self .answer
5861 ])
5962
6063 @classmethod
6164 def from_common (cls , annotation ) -> "NDChecklistSubclass" :
6265 return cls (answer = [
63- NDFeature (schemaId = answer .schema_id )
66+ NDFeature (schema_id = answer .schema_id )
6467 for answer in annotation .value .answer
6568 ],
66- schemaId = annotation .schema_id )
69+ schema_id = annotation .schema_id )
6770
6871
6972class NDRadioSubclass (NDFeature ):
7073 answer : NDFeature
7174
7275 def to_common (self ) -> Radio :
7376 return Radio (answer = ClassificationAnswer (
74- schema_id = self .answer .schemaId ))
77+ schema_id = self .answer .schema_id ))
7578
7679 @classmethod
7780 def from_common (cls , annotation ) -> "NDRadioSubclass" :
78- return cls (answer = NDFeature (schemaId = annotation .value .answer .schema_id ),
79- schemaId = annotation .schema_id )
81+ return cls (
82+ answer = NDFeature (schema_id = annotation .value .answer .schema_id ),
83+ schema_id = annotation .schema_id )
8084
8185
8286### ====== End of subclasses
@@ -89,7 +93,7 @@ def from_common(cls, annotation, data) -> "NDText":
8993 return cls (
9094 answer = annotation .value .answer ,
9195 dataRow = {'id' : data .uid },
92- schemaId = annotation .schema_id ,
96+ schema_id = annotation .schema_id ,
9397 uuid = annotation .extra .get ('uuid' ),
9498 )
9599
@@ -99,11 +103,11 @@ class NDChecklist(NDAnnotation, NDChecklistSubclass, VideoSupported):
99103 @classmethod
100104 def from_common (cls , annotation , data ) -> "NDChecklist" :
101105 return cls (answer = [
102- NDFeature (schemaId = answer .schema_id )
106+ NDFeature (schema_id = answer .schema_id )
103107 for answer in annotation .value .answer
104108 ],
105109 dataRow = {'id' : data .uid },
106- schemaId = annotation .schema_id ,
110+ schema_id = annotation .schema_id ,
107111 uuid = annotation .extra .get ('uuid' ),
108112 frames = annotation .extra .get ('frames' ))
109113
@@ -112,11 +116,12 @@ class NDRadio(NDAnnotation, NDRadioSubclass, VideoSupported):
112116
113117 @classmethod
114118 def from_common (cls , annotation , data ) -> "NDRadio" :
115- return cls (answer = NDFeature (schemaId = annotation .value .answer .schema_id ),
116- dataRow = {'id' : data .uid },
117- schemaId = annotation .schema_id ,
118- uuid = annotation .extra .get ('uuid' ),
119- frames = annotation .extra .get ('frames' ))
119+ return cls (
120+ answer = NDFeature (schema_id = annotation .value .answer .schema_id ),
121+ dataRow = {'id' : data .uid },
122+ schema_id = annotation .schema_id ,
123+ uuid = annotation .extra .get ('uuid' ),
124+ frames = annotation .extra .get ('frames' ))
120125
121126
122127class NDSubclassification :
@@ -135,7 +140,7 @@ def from_common(
135140 @staticmethod
136141 def to_common (annotation : AnnotationType ) -> ClassificationAnnotation :
137142 return ClassificationAnnotation (value = annotation .to_common (),
138- schema_id = annotation .schemaId )
143+ schema_id = annotation .schema_id )
139144
140145 @staticmethod
141146 def lookup_subclassification (annotation : AnnotationType ):
@@ -155,7 +160,7 @@ def to_common(
155160 annotation : AnnotationType
156161 ) -> Union [ClassificationAnnotation , VideoClassificationAnnotation ]:
157162 common = ClassificationAnnotation (value = annotation .to_common (),
158- schema_id = annotation .schemaId ,
163+ schema_id = annotation .schema_id ,
159164 extra = {'uuid' : annotation .uuid })
160165 if getattr (annotation , 'frames' , None ) is None :
161166 return [common ]
0 commit comments