1- from typing import Any , Dict , List , Optional , Union
1+ from typing import Any , Dict , List , Optional , Union , Type
22
33from pydantic import BaseModel , validator
44
5+ from .classification import LBV1Checklist , LBV1Classifications , LBV1Radio , LBV1Text , LBV1Dropdown
6+ from .feature import LBV1Feature
57from ...annotation_types .annotation import (ClassificationAnnotation ,
68 ObjectAnnotation )
79from ...annotation_types .data import MaskData
810from ...annotation_types .geometry import Line , Mask , Point , Polygon , Rectangle
911from ...annotation_types .ner import TextEntity
1012from ...annotation_types .types import Cuid
11- from .classification import LBV1Checklist , LBV1Classifications , LBV1Radio , LBV1Text , LBV1Dropdown
12- from .feature import LBV1Feature
1313
1414
1515class LBV1ObjectBase (LBV1Feature ):
@@ -65,10 +65,10 @@ def from_common(cls, rectangle: Rectangle,
6565 height = rectangle .end .y - rectangle .start .y ,
6666 width = rectangle .end .x - rectangle .start .x ,
6767 ),
68- schema_id = feature_schema_id ,
69- title = title ,
70- classifications = classifications ,
71- ** extra )
68+ schema_id = feature_schema_id ,
69+ title = title ,
70+ classifications = classifications ,
71+ ** extra )
7272
7373
7474class LBV1Polygon (LBV1ObjectBase ):
@@ -83,11 +83,12 @@ def from_common(cls, polygon: Polygon,
8383 feature_schema_id : Cuid , title : str ,
8484 extra : Dict [str , Any ]) -> "LBV1Polygon" :
8585 return cls (
86- polygon = [_Point (x = point .x , y = point .y ) for point in polygon .points ],
86+ polygon = [_Point (x = point .x , y = point .y ) for point in polygon .points [: - 1 ]], # drop closing point
8787 classifications = classifications ,
8888 schema_id = feature_schema_id ,
8989 title = title ,
90- ** extra )
90+ ** extra
91+ )
9192
9293
9394class LBV1Point (LBV1ObjectBase ):
@@ -138,7 +139,6 @@ def from_common(cls, mask: Mask,
138139 classifications : List [ClassificationAnnotation ],
139140 feature_schema_id : Cuid , title : str ,
140141 extra : Dict [str , Any ]) -> "LBV1Mask" :
141-
142142 if mask .mask .url is None :
143143 raise ValueError (
144144 "Mask does not have a url. Use `LabelGenerator.add_url_to_masks`, `LabelList.add_url_to_masks`, or `Label.add_url_to_masks`."
@@ -175,17 +175,12 @@ def from_common(cls, text_entity: TextEntity,
175175 classifications : List [ClassificationAnnotation ],
176176 feature_schema_id : Cuid , title : str ,
177177 extra : Dict [str , Any ]) -> "LBV1TextEntity" :
178-
179- return cls (data = {
180- 'location' : {
181- 'start' : text_entity .start ,
182- 'end' : text_entity .end
183- }
184- },
185- classifications = classifications ,
186- schema_id = feature_schema_id ,
187- title = title ,
188- ** extra )
178+ return cls (
179+ data = _Location (location = _TextPoint (start = text_entity .start , end = text_entity .end )),
180+ classifications = classifications ,
181+ schema_id = feature_schema_id ,
182+ title = title ,
183+ ** extra )
189184
190185
191186class LBV1Objects (BaseModel ):
@@ -222,7 +217,6 @@ def from_common(cls, annotations: List[ObjectAnnotation]) -> "LBV1Objects":
222217 objects = []
223218 for annotation in annotations :
224219 obj = cls .lookup_object (annotation )
225- subclasses = []
226220 subclasses = LBV1Classifications .from_common (
227221 annotation .classifications ).classifications
228222
@@ -237,9 +231,8 @@ def from_common(cls, annotations: List[ObjectAnnotation]) -> "LBV1Objects":
237231
238232 @staticmethod
239233 def lookup_object (
240- annotation : ObjectAnnotation
241- ) -> Union [LBV1Line , LBV1Point , LBV1Polygon , LBV1Rectangle , LBV1Mask ,
242- LBV1TextEntity ]:
234+ annotation : ObjectAnnotation
235+ ) -> Type [Union [LBV1Line , LBV1Point , LBV1Polygon , LBV1Rectangle , LBV1Mask , LBV1TextEntity ]]:
243236 result = {
244237 Line : LBV1Line ,
245238 Point : LBV1Point ,
0 commit comments