Skip to content

Commit 3527c81

Browse files
author
Val Brodsky
committed
PR improvements: some refactoring, better test verification
1 parent 2ce8be6 commit 3527c81

File tree

5 files changed

+20
-15
lines changed

5 files changed

+20
-15
lines changed

labelbox/data/annotation_types/ner/document_entity.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ def validate_page(cls, v):
1919

2020
class DocumentEntity(_CamelCaseMixin, BaseModel):
2121
""" Represents a text entity """
22-
name: str
2322
text_selections: List[DocumentTextSelection]

labelbox/data/serialization/ndjson/objects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,8 @@ def lookup_object(
505505
# NOTE: Deserialization of subclasses in pydantic is a known PIA, see here https://blog.devgenius.io/deserialize-child-classes-with-pydantic-that-gonna-work-784230e1cf83
506506
# I could implement the registry approach suggested there, but I found that if I list subclass (that has more attributes) before the parent class, it works
507507
# This is a bit of a hack, but it works for now
508-
NERTextType = Union[NDConversationEntity, NDTextEntity]
508+
NDEntityType = Union[NDConversationEntity, NDTextEntity]
509509
NDObjectType = Union[NDLine, NDPolygon, NDPoint, NDRectangle, NDMask,
510-
NERTextType, NDDocumentEntity]
510+
NDEntityType, NDDocumentEntity]
511511

512512
NDFrameObjectType = NDFrameRectangle, NDFramePoint, NDFrameLine

tests/data/annotation_types/test_ner.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,10 @@ def test_ner():
1111

1212

1313
def test_document_entity():
14-
document_entity = DocumentEntity(name="tool_name",
15-
text_selections=[
16-
DocumentTextSelection(
17-
token_ids=["1", "2"],
18-
group_id="1",
19-
page=1)
20-
])
21-
22-
assert document_entity.name == "tool_name"
14+
document_entity = DocumentEntity(text_selections=[
15+
DocumentTextSelection(token_ids=["1", "2"], group_id="1", page=1)
16+
])
17+
2318
assert document_entity.text_selections[0].token_ids == ["1", "2"]
2419
assert document_entity.text_selections[0].group_id == "1"
2520
assert document_entity.text_selections[0].page == 1

tests/integration/annotation_import/test_bulk_import_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ def test_pdf_document_entity(client, configured_project_without_data_rows,
311311
page=1)
312312

313313
entities_annotation_document_entity = DocumentEntity(
314-
name="named_entity", text_selections=[document_text_selection])
314+
text_selections=[document_text_selection])
315315
entities_annotation = ObjectAnnotation(
316316
name="named-entity", value=entities_annotation_document_entity)
317317

tests/integration/annotation_import/test_conversation_import.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
def test_conversation_entity(client, configured_project_without_data_rows,
1111
dataset_conversation_entity, rand_gen):
1212

13-
conversation_entity_annotation = ConversationEntity(name="named-entity",
14-
start=0,
13+
conversation_entity_annotation = ConversationEntity(start=0,
1514
end=8,
1615
message_id="4")
1716

@@ -41,3 +40,15 @@ def test_conversation_entity(client, configured_project_without_data_rows,
4140
import_annotations.wait_until_done()
4241

4342
assert import_annotations.errors == []
43+
44+
exported_labels = configured_project_without_data_rows.label_generator()
45+
for label in exported_labels:
46+
assert len(
47+
label.annotations) == 1 # we have created only 1 annotation above
48+
annotation = label.annotations[0]
49+
50+
assert type(annotation) is ConversationEntity
51+
assert annotation.name == "named-entity"
52+
assert annotation.value.message_id == "4"
53+
assert annotation.value.start == 0
54+
assert annotation.value.end == 8

0 commit comments

Comments
 (0)