@@ -223,9 +223,27 @@ class NDVideoText(BaseModel):
223223 {"name": "...", "answer": [{"value": "text", "frames": [{"start": 1, "end": 5}]}], ...}
224224 """
225225
226- name : str
226+ name : Optional [str ] = None
227+ schema_id : Optional [str ] = Field (default = None , alias = "schemaId" )
227228 answer : List [NDVideoTextAnswer ]
228- dataRow : Dict [str , str ]
229+ data_row : DataRow = Field (alias = "dataRow" )
230+
231+ model_config = ConfigDict (populate_by_name = True )
232+
233+ @model_validator (mode = "after" )
234+ def must_set_one (self ):
235+ if not self .name and not self .schema_id :
236+ raise ValueError ("Schema id or name are not set. Set either one." )
237+ return self
238+
239+ @model_serializer (mode = "wrap" )
240+ def serialize_model (self , handler ):
241+ res = handler (self )
242+ if "name" in res and res ["name" ] is None :
243+ res .pop ("name" )
244+ if "schemaId" in res and res ["schemaId" ] is None :
245+ res .pop ("schemaId" )
246+ return res
229247
230248 @classmethod
231249 def from_video_text_group (
@@ -235,14 +253,10 @@ def from_video_text_group(
235253 data : "GenericDataRowData" ,
236254 ) -> "NDVideoText" :
237255 first = annotation_group [0 ]
238- data_row = {}
239- if data .global_key :
240- data_row ["globalKey" ] = data .global_key
241- elif data .uid :
242- data_row ["id" ] = data .uid
243256 return cls (
244257 name = first .name ,
245- dataRow = data_row ,
258+ schema_id = first .feature_schema_id ,
259+ data_row = DataRow (id = data .uid , global_key = data .global_key ),
246260 answer = [
247261 NDVideoTextAnswer (value = text_val , frames = ranges )
248262 for text_val , ranges in frame_ranges_by_text .items ()
0 commit comments