1212from labelbox .data .annotation_types .data .video import VideoData
1313
1414from ...annotation_types .data import ImageData , TextData , MaskData
15- from ...annotation_types .ner import TextEntity
15+ from ...annotation_types .ner import DocumentEntity , DocumentTextSelection , TextEntity
1616from ...annotation_types .types import Cuid
1717from ...annotation_types .geometry import Rectangle , Polygon , Line , Point , Mask
1818from ...annotation_types .annotation import ClassificationAnnotation , ObjectAnnotation , VideoObjectAnnotation
@@ -372,6 +372,34 @@ def from_common(cls,
372372 confidence = confidence )
373373
374374
375+
376+
377+ class NDDocumentEntity (NDBaseObject , ConfidenceMixin ):
378+ name : str
379+ text_selections : List [DocumentTextSelection ]
380+
381+
382+ def to_common (self ) -> DocumentEntity :
383+ return TextEntity (name = self .name , text_selections = self .text_selections )
384+
385+ @classmethod
386+ def from_common (cls ,
387+ document_entity : DocumentEntity ,
388+ classifications : List [ClassificationAnnotation ],
389+ name : str ,
390+ feature_schema_id : Cuid ,
391+ extra : Dict [str , Any ],
392+ data : Union [ImageData , TextData ],
393+ confidence : Optional [float ] = None ) -> "NDDocumentEntity" :
394+ return cls (text_selections = document_entity .text_selections ,
395+ dataRow = DataRow (id = data .uid ),
396+ name = name ,
397+ schema_id = feature_schema_id ,
398+ uuid = extra .get ('uuid' ),
399+ classifications = classifications ,
400+ confidence = confidence )
401+
402+
375403class NDObject :
376404
377405 @staticmethod
@@ -434,7 +462,8 @@ def lookup_object(
434462 Polygon : NDPolygon ,
435463 Rectangle : NDRectangle ,
436464 Mask : NDMask ,
437- TextEntity : NDTextEntity
465+ TextEntity : NDTextEntity ,
466+ DocumentEntity : NDDocumentEntity ,
438467 }.get (type (annotation .value ))
439468 if result is None :
440469 raise TypeError (
@@ -444,6 +473,6 @@ def lookup_object(
444473
445474
446475NDObjectType = Union [NDLine , NDPolygon , NDPoint , NDRectangle , NDMask ,
447- NDTextEntity ]
476+ NDTextEntity , NDDocumentEntity ]
448477
449478NDFrameObjectType = NDFrameRectangle , NDFramePoint , NDFrameLine
0 commit comments