Skip to content

Commit 1ed861c

Browse files
author
Val Brodsky
committed
Formatting
1 parent 9d1138c commit 1ed861c

File tree

6 files changed

+56
-36
lines changed

6 files changed

+56
-36
lines changed

labelbox/data/annotation_types/ner/document_entity.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def validate_page(cls, v):
1414
raise ValueError("Page must be greater than 1")
1515
return v
1616

17+
1718
class DocumentEntity(BaseModel):
1819
""" Represents a text entity """
1920
name: str

labelbox/data/serialization/ndjson/objects.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,19 +372,17 @@ def from_common(cls,
372372
confidence=confidence)
373373

374374

375-
376-
377375
class NDDocumentEntity(NDBaseObject, ConfidenceMixin):
378376
name: str
379377
textSelections: List[DocumentTextSelection]
380378

381-
382379
def to_common(self) -> DocumentEntity:
383380
return TextEntity(name=self.name, textSelections=self.textSelections)
384381

385382
return obj.from_common(annotation.value, subclasses, annotation.name,
386383
annotation.feature_schema_id, annotation.extra,
387384
data, **optional_kwargs)
385+
388386
@classmethod
389387
def from_common(cls,
390388
document_entity: DocumentEntity,

tests/data/annotation_types/test_ner.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@ def test_ner():
88
assert text_entity.start == start
99
assert text_entity.end == end
1010

11+
1112
def test_document_entity():
12-
document_entity = DocumentEntity(name="tool_name", textSelections=[DocumentTextSelection(tokenIds=["1", "2"], groupId="1", page=1)])
13+
document_entity = DocumentEntity(name="tool_name",
14+
textSelections=[
15+
DocumentTextSelection(
16+
tokenIds=["1", "2"],
17+
groupId="1",
18+
page=1)
19+
])
1320

1421
assert document_entity.name == "tool_name"
1522
assert document_entity.textSelections[0].tokenIds == ["1", "2"]
1623
assert document_entity.textSelections[0].groupId == "1"
17-
assert document_entity.textSelections[0].page == 1
24+
assert document_entity.textSelections[0].page == 1

tests/integration/annotation_import/conftest.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,13 @@ def ontology():
114114
'options': []
115115
}]
116116
}
117-
named_entity = {'tool': 'named-entity', 'name': 'named-entity', 'required': False, 'color': '#A30059', 'classifications': [], }
117+
named_entity = {
118+
'tool': 'named-entity',
119+
'name': 'named-entity',
120+
'required': False,
121+
'color': '#A30059',
122+
'classifications': [],
123+
}
118124

119125
tools = [
120126
bbox_tool, polygon_tool, polyline_tool, point_tool, entity_tool,
@@ -160,6 +166,7 @@ def configured_project_pdf(client, ontology, rand_gen, pdf_url):
160166
project.delete()
161167
dataset.delete()
162168

169+
163170
@pytest.fixture
164171
def dataset_pdf_entity(client, rand_gen, pdf_entity_row_data):
165172
dataset = client.create_dataset(name=rand_gen(str))
@@ -169,8 +176,10 @@ def dataset_pdf_entity(client, rand_gen, pdf_entity_row_data):
169176
yield dataset, data_row_ids
170177
dataset.delete()
171178

179+
172180
@pytest.fixture
173-
def configured_project_pdf_entity(client, ontology, rand_gen, dataset_pdf_entity):
181+
def configured_project_pdf_entity(client, ontology, rand_gen,
182+
dataset_pdf_entity):
174183
project = client.create_project(name=rand_gen(str),
175184
queue_mode=QueueMode.Dataset)
176185

@@ -185,6 +194,7 @@ def configured_project_pdf_entity(client, ontology, rand_gen, dataset_pdf_entity
185194
yield project
186195
project.delete()
187196

197+
188198
@pytest.fixture
189199
def configured_project_without_data_rows(client, configured_project, rand_gen):
190200
project = client.create_project(name=rand_gen(str),

tests/integration/annotation_import/test_bulk_import_request.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -293,36 +293,36 @@ def test_pdf_mal_bbox(client, configured_project_pdf):
293293
assert import_annotations.errors == []
294294

295295

296-
def test_pdf_document_entity(client, configured_project_pdf_entity, dataset_pdf_entity):
296+
def test_pdf_document_entity(client, configured_project_pdf_entity,
297+
dataset_pdf_entity):
297298
# for content "Metal-insulator (MI) transitions have been one of the" in OCR JSON extract tests/assets/arxiv-pdf_data_99-word-token-pdfs_0801.3483-lb-textlayer.json
298-
document_text_selection = DocumentTextSelection(groupId= "2f4336f4-a07e-4e0a-a9e1-5629b03b719b",
299-
tokenIds=["3f984bf3-1d61-44f5-b59a-9658a2e3440f",
300-
"3bf00b56-ff12-4e52-8cc1-08dbddb3c3b8",
301-
"6e1c3420-d4b7-4c5a-8fd6-ead43bf73d80",
302-
"87a43d32-af76-4a1d-b262-5c5f4d5ace3a",
303-
"e8606e8a-dfd9-4c49-a635-ad5c879c75d0",
304-
"67c7c19e-4654-425d-bf17-2adb8cf02c30",
305-
"149c5e80-3e07-49a7-ab2d-29ddfe6a38fa",
306-
"b0e94071-2187-461e-8e76-96c58738a52c"],
307-
page=1)
308-
309-
entities_annotation_document_entity = DocumentEntity(name="named_entity",
310-
textSelections = [document_text_selection])
311-
entities_annotation = ObjectAnnotation(name="named-entity",
312-
value=entities_annotation_document_entity)
299+
document_text_selection = DocumentTextSelection(
300+
groupId="2f4336f4-a07e-4e0a-a9e1-5629b03b719b",
301+
tokenIds=[
302+
"3f984bf3-1d61-44f5-b59a-9658a2e3440f",
303+
"3bf00b56-ff12-4e52-8cc1-08dbddb3c3b8",
304+
"6e1c3420-d4b7-4c5a-8fd6-ead43bf73d80",
305+
"87a43d32-af76-4a1d-b262-5c5f4d5ace3a",
306+
"e8606e8a-dfd9-4c49-a635-ad5c879c75d0",
307+
"67c7c19e-4654-425d-bf17-2adb8cf02c30",
308+
"149c5e80-3e07-49a7-ab2d-29ddfe6a38fa",
309+
"b0e94071-2187-461e-8e76-96c58738a52c"
310+
],
311+
page=1)
312+
313+
entities_annotation_document_entity = DocumentEntity(
314+
name="named_entity", textSelections=[document_text_selection])
315+
entities_annotation = ObjectAnnotation(
316+
name="named-entity", value=entities_annotation_document_entity)
313317

314318
labels = []
315319
_, data_row_uids = dataset_pdf_entity
316320
for data_row_uid in data_row_uids:
317-
labels.append(Label(
318-
data= TextData(
319-
uid=data_row_uid),
320-
annotations = [
321-
entities_annotation,
322-
]
323-
)
324-
)
325-
321+
labels.append(
322+
Label(data=TextData(uid=data_row_uid),
323+
annotations=[
324+
entities_annotation,
325+
]))
326326

327327
import_annotations = MALPredictionImport.create_from_objects(
328328
client=client,
@@ -331,4 +331,4 @@ def test_pdf_document_entity(client, configured_project_pdf_entity, dataset_pdf_
331331
predictions=labels)
332332
import_annotations.wait_until_done()
333333

334-
assert import_annotations.errors == []
334+
assert import_annotations.errors == []

tests/integration/conftest.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,18 +175,22 @@ def image_url(client):
175175
def pdf_url(client):
176176
return client.upload_file('tests/assets/loremipsum.pdf')
177177

178+
178179
@pytest.fixture(scope="session")
179180
def pdf_entity_row_data(client):
180-
pdf_url = client.upload_file('tests/assets/arxiv-pdf_data_99-word-token-pdfs_0801.3483.pdf')
181-
text_layer_url = client.upload_file('tests/assets/arxiv-pdf_data_99-word-token-pdfs_0801.3483-lb-textlayer.json')
181+
pdf_url = client.upload_file(
182+
'tests/assets/arxiv-pdf_data_99-word-token-pdfs_0801.3483.pdf')
183+
text_layer_url = client.upload_file(
184+
'tests/assets/arxiv-pdf_data_99-word-token-pdfs_0801.3483-lb-textlayer.json'
185+
)
182186

183187
return {
184188
"row_data": {
185189
"pdf_url": pdf_url,
186190
"text_layer_url": text_layer_url
187191
},
188192
"global_key": str(uuid.uuid4())
189-
}
193+
}
190194

191195

192196
@pytest.fixture

0 commit comments

Comments
 (0)