Browse Source
Merge pull request #1558 from doccano/fix/#1466
Sort exported labels
pull/1562/head
Hiroki Nakayama
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
12 additions and
1 deletions
-
backend/api/tests/download/test_writer.py
-
backend/api/views/download/writer.py
|
|
@ -32,6 +32,16 @@ class TestCSVWriter(unittest.TestCase): |
|
|
|
} |
|
|
|
self.assertEqual(line, expected) |
|
|
|
|
|
|
|
def test_label_order(self): |
|
|
|
writer = CsvWriter('.') |
|
|
|
record1 = Record(id=0, data='', label=['labelA', 'labelB'], user='', metadata={}) |
|
|
|
record2 = Record(id=0, data='', label=['labelB', 'labelA'], user='', metadata={}) |
|
|
|
line1 = writer.create_line(record1) |
|
|
|
line2 = writer.create_line(record2) |
|
|
|
expected = 'labelA#labelB' |
|
|
|
self.assertEqual(line1['label'], expected) |
|
|
|
self.assertEqual(line2['label'], expected) |
|
|
|
|
|
|
|
@patch('os.remove') |
|
|
|
@patch('zipfile.ZipFile') |
|
|
|
@patch('csv.DictWriter.writerow') |
|
|
|
|
|
@ -84,7 +84,7 @@ class CsvWriter(BaseWriter): |
|
|
|
return { |
|
|
|
'id': record.id, |
|
|
|
'data': record.data, |
|
|
|
'label': '#'.join(record.label), |
|
|
|
'label': '#'.join(sorted(record.label)), |
|
|
|
**record.metadata |
|
|
|
} |
|
|
|
|
|
|
@ -144,6 +144,7 @@ class FastTextWriter(LineWriter): |
|
|
|
|
|
|
|
def create_line(self, record): |
|
|
|
line = [f'__label__{label}' for label in record.label] |
|
|
|
line.sort() |
|
|
|
line.append(record.data) |
|
|
|
line = ' '.join(line) |
|
|
|
return line |