Skip to content

Commit 392806c

Browse files
committed
refactor to move two new fields into LBV1ObjectBase
1 parent ef5c450 commit 392806c

File tree

1 file changed

+27
-30
lines changed

1 file changed

+27
-30
lines changed

labelbox/data/serialization/labelbox_v1/objects.py

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class LBV1ObjectBase(LBV1Feature):
2222
instanceURI: Optional[str] = None
2323
classifications: List[Union[LBV1Text, LBV1Radio, LBV1Dropdown,
2424
LBV1Checklist]] = []
25+
page: Optional[int] = None
26+
unit: Optional[str] = None
2527

2628
def dict(self, *args, **kwargs) -> Dict[str, Any]:
2729
res = super().dict(*args, **kwargs)
@@ -259,40 +261,35 @@ def from_common(cls, text_entity: TextEntity,
259261
**extra)
260262

261263

262-
class LBV1DocumentRectangle(LBV1Rectangle):
263-
unit: str
264-
page: int
265-
266-
267264
class LBV1Objects(BaseModel):
268-
objects: List[Union[LBV1DocumentRectangle, LBV1Line, LBV1Point, LBV1Polygon,
269-
LBV1Rectangle, LBV1TextEntity, LBV1Mask, LBV1TIPoint,
270-
LBV1TILine, LBV1TIPolygon, LBV1TIRectangle,]]
265+
objects: List[Union[LBV1Line, LBV1Point, LBV1Polygon, LBV1Rectangle,
266+
LBV1TextEntity, LBV1Mask, LBV1TIPoint, LBV1TILine,
267+
LBV1TIPolygon, LBV1TIRectangle,]]
271268

272269
def to_common(self) -> List[ObjectAnnotation]:
273270
objects = [
274-
ObjectAnnotation(
275-
value=obj.to_common(),
276-
classifications=[
277-
ClassificationAnnotation(value=cls.to_common(),
278-
feature_schema_id=cls.schema_id,
279-
name=cls.title,
280-
extra={
281-
'feature_id': cls.feature_id,
282-
'title': cls.title,
283-
'value': cls.value
284-
}) for cls in obj.classifications
285-
],
286-
name=obj.title,
287-
feature_schema_id=obj.schema_id,
288-
extra={
289-
'instanceURI': obj.instanceURI,
290-
'color': obj.color,
291-
'feature_id': obj.feature_id,
292-
'value': obj.value,
293-
'page': obj.page if hasattr(obj, 'page') else None,
294-
'unit': obj.unit if hasattr(obj, 'unit') else None,
295-
}) for obj in self.objects
271+
ObjectAnnotation(value=obj.to_common(),
272+
classifications=[
273+
ClassificationAnnotation(
274+
value=cls.to_common(),
275+
feature_schema_id=cls.schema_id,
276+
name=cls.title,
277+
extra={
278+
'feature_id': cls.feature_id,
279+
'title': cls.title,
280+
'value': cls.value
281+
}) for cls in obj.classifications
282+
],
283+
name=obj.title,
284+
feature_schema_id=obj.schema_id,
285+
extra={
286+
'instanceURI': obj.instanceURI,
287+
'color': obj.color,
288+
'feature_id': obj.feature_id,
289+
'value': obj.value,
290+
'page': obj.page,
291+
'unit': obj.unit,
292+
}) for obj in self.objects
296293
]
297294
return objects
298295

0 commit comments

Comments
 (0)