Browse Source

Apply black to fix codes

pull/1897/head
Hironsan 2 years ago
parent
commit
add5d4c71a
2 changed files with 27 additions and 35 deletions
  1. 10
      backend/data_export/pipeline/factories.py
  2. 52
      backend/data_export/tests/test_task.py

10
backend/data_export/pipeline/factories.py

@ -90,24 +90,24 @@ def create_formatter(project: Project, file_format: str) -> List[Formatter]:
else [
TupledSpanFormatter(Spans.column),
ListedCategoryFormatter(Comments.column),
RenameFormatter(**mapper_sequence_labeling)
RenameFormatter(**mapper_sequence_labeling),
]
},
SEQ2SEQ: {
CSV.name: [
JoinedCategoryFormatter(Texts.column),
JoinedCategoryFormatter(Comments.column),
RenameFormatter(**mapper_seq2seq)
RenameFormatter(**mapper_seq2seq),
],
JSON.name: [
ListedCategoryFormatter(Texts.column),
ListedCategoryFormatter(Comments.column),
RenameFormatter(**mapper_seq2seq)
RenameFormatter(**mapper_seq2seq),
],
JSONL.name: [
ListedCategoryFormatter(Texts.column),
ListedCategoryFormatter(Comments.column),
RenameFormatter(**mapper_seq2seq)
RenameFormatter(**mapper_seq2seq),
],
},
IMAGE_CLASSIFICATION: {
@ -121,7 +121,7 @@ def create_formatter(project: Project, file_format: str) -> List[Formatter]:
JSONL.name: [
ListedCategoryFormatter(Texts.column),
ListedCategoryFormatter(Comments.column),
RenameFormatter(**mapper_speech2text)
RenameFormatter(**mapper_speech2text),
],
},
INTENT_DETECTION_AND_SLOT_FILLING: {

52
backend/data_export/tests/test_task.py

@ -97,7 +97,7 @@ class TestExportCategory(TestExport):
{
**self.data1,
"label": sorted([self.category1.to_string(), self.category2.to_string()]),
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()])
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()]),
},
{**self.data2, "label": [], "Comments": []},
]
@ -121,7 +121,7 @@ class TestExportCategory(TestExport):
{
**self.data1,
"label": sorted([self.category1.to_string(), self.category2.to_string()]),
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()])
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()]),
}
]
self.assertEqual(dataset, expected_dataset)
@ -167,7 +167,7 @@ class TestExportSeq2seq(TestExport):
{
**self.data1,
"label": sorted([self.text1.text, self.text2.text]),
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()])
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()]),
},
{**self.data2, "label": [], "Comments": []},
]
@ -193,7 +193,7 @@ class TestExportSeq2seq(TestExport):
{
**self.data1,
"label": sorted([self.text1.text, self.text2.text]),
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()])
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()]),
}
]
self.assertEqual(dataset, expected_dataset)
@ -224,7 +224,7 @@ class TestExportIntentDetectionAndSlotFilling(TestExport):
**self.data1,
"entities": [list(self.span.to_tuple())],
"cats": [self.category1.to_string()],
"Comments": [self.comment1.to_string()]
"Comments": [self.comment1.to_string()],
},
{**self.data2, "entities": [], "cats": [], "Comments": []},
],
@ -233,7 +233,7 @@ class TestExportIntentDetectionAndSlotFilling(TestExport):
**self.data1,
"entities": [],
"cats": [self.category2.to_string()],
"Comments": [self.comment2.to_string()]
"Comments": [self.comment2.to_string()],
},
{**self.data2, "entities": [], "cats": [], "Comments": []},
],
@ -253,7 +253,7 @@ class TestExportIntentDetectionAndSlotFilling(TestExport):
**self.data1,
"entities": [list(self.span.to_tuple())],
"cats": sorted([self.category1.to_string(), self.category2.to_string()]),
"Comments": [self.comment1.to_string(), self.comment2.to_string()]
"Comments": [self.comment1.to_string(), self.comment2.to_string()],
},
{**self.data2, "entities": [], "cats": [], "Comments": []},
]
@ -268,7 +268,7 @@ class TestExportIntentDetectionAndSlotFilling(TestExport):
**self.data1,
"entities": [list(self.span.to_tuple())],
"cats": [self.category1.to_string()],
"Comments": [self.comment1.to_string()]
"Comments": [self.comment1.to_string()],
},
],
self.project.annotator.username: [],
@ -285,7 +285,7 @@ class TestExportIntentDetectionAndSlotFilling(TestExport):
**self.data1,
"entities": [list(self.span.to_tuple())],
"cats": sorted([self.category1.to_string(), self.category2.to_string()]),
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()])
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()]),
},
]
self.assertEqual(dataset, expected_dataset)
@ -335,7 +335,7 @@ class TestExportSequenceLabeling(TestExport):
{
**self.data1,
"label": [list(self.span1.to_tuple()), list(self.span2.to_tuple())],
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()])
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()]),
},
{**self.data2, "label": [], "Comments": []},
]
@ -361,7 +361,7 @@ class TestExportSequenceLabeling(TestExport):
{
**self.data1,
"label": [list(self.span1.to_tuple()), list(self.span2.to_tuple())],
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()])
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()]),
},
]
self.assertEqual(dataset, expected_dataset)
@ -407,7 +407,7 @@ class TestExportSpeechToText(TestExport):
{
**self.data1,
"label": sorted([self.text1.text, self.text2.text]),
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()])
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()]),
},
{**self.data2, "label": [], "Comments": []},
]
@ -433,7 +433,7 @@ class TestExportSpeechToText(TestExport):
{
**self.data1,
"label": sorted([self.text1.text, self.text2.text]),
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()])
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()]),
}
]
self.assertEqual(dataset, expected_dataset)
@ -457,11 +457,7 @@ class TestExportImageClassification(TestExport):
datasets = self.export_dataset()
expected_datasets = {
self.project.admin.username: [
{
**self.data1,
"label": [self.category1.to_string()],
"Comments": [self.comment1.to_string()]
},
{**self.data1, "label": [self.category1.to_string()], "Comments": [self.comment1.to_string()]},
{**self.data2, "label": [], "Comments": []},
],
self.project.approver.username: [
@ -469,11 +465,7 @@ class TestExportImageClassification(TestExport):
{**self.data2, "label": [], "Comments": []},
],
self.project.annotator.username: [
{
**self.data1,
"label": [self.category2.to_string()],
"Comments": [self.comment2.to_string()]
},
{**self.data1, "label": [self.category2.to_string()], "Comments": [self.comment2.to_string()]},
{**self.data2, "label": [], "Comments": []},
],
}
@ -487,7 +479,7 @@ class TestExportImageClassification(TestExport):
{
**self.data1,
"label": sorted([self.category1.to_string(), self.category2.to_string()]),
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()])
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()]),
},
{**self.data2, "label": [], "Comments": []},
]
@ -511,7 +503,7 @@ class TestExportImageClassification(TestExport):
{
**self.data1,
"label": sorted([self.category1.to_string(), self.category2.to_string()]),
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()])
"Comments": sorted([self.comment1.to_string(), self.comment2.to_string()]),
}
]
self.assertEqual(dataset, expected_dataset)
@ -761,7 +753,7 @@ class TestExportRelation(TestExport):
**self.data1,
"entities": [self.span1.to_dict(), self.span2.to_dict()],
"relations": [self.relation.to_dict()],
"Comments": [self.comment1.to_dict()]
"Comments": [self.comment1.to_dict()],
},
{**self.data2, "entities": [], "relations": [], "Comments": []},
],
@ -770,7 +762,7 @@ class TestExportRelation(TestExport):
**self.data1,
"entities": [self.span3.to_dict()],
"relations": [],
"Comments": [self.comment2.to_dict()]
"Comments": [self.comment2.to_dict()],
},
{**self.data2, "entities": [], "relations": [], "Comments": []},
],
@ -790,7 +782,7 @@ class TestExportRelation(TestExport):
**self.data1,
"entities": [self.span1.to_dict(), self.span2.to_dict(), self.span3.to_dict()],
"relations": [self.relation.to_dict()],
"Comments": [self.comment1.to_dict(), self.comment2.to_dict()]
"Comments": [self.comment1.to_dict(), self.comment2.to_dict()],
},
{**self.data2, "entities": [], "relations": [], "Comments": []},
]
@ -805,7 +797,7 @@ class TestExportRelation(TestExport):
**self.data1,
"entities": [self.span1.to_dict(), self.span2.to_dict()],
"relations": [self.relation.to_dict()],
"Comments": [self.comment1.to_dict()]
"Comments": [self.comment1.to_dict()],
},
],
self.project.annotator.username: [],
@ -822,7 +814,7 @@ class TestExportRelation(TestExport):
**self.data1,
"entities": [self.span1.to_dict(), self.span2.to_dict(), self.span3.to_dict()],
"relations": [self.relation.to_dict()],
"Comments": [self.comment1.to_dict(), self.comment2.to_dict()]
"Comments": [self.comment1.to_dict(), self.comment2.to_dict()],
}
]
self.assertEqual(dataset, expected_dataset)
Loading…
Cancel
Save