Browse Source

Merge pull request #1116 from SwiftPredator/Enhancement/DynamicFilename

Enhancement/dynamic filename + changed json1 naming to jsonl
pull/1156/head
Hiroki Nakayama 3 years ago
committed by GitHub
parent
commit
91c6a6f5ea
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 17 deletions
  1. 4
      app/api/tests/test_api.py
  2. 10
      app/api/views.py
  3. 6
      app/server/static/components/download_sequence_labeling.vue
  4. 10
      frontend/components/organisms/documents/DocumentExportForm.vue
  5. 1
      frontend/i18n/en/projects/dataset.js
  6. 2
      frontend/store/documents.js
  7. 11
      frontend/store/projects.js

4
app/api/tests/test_api.py

@ -1518,9 +1518,9 @@ class TestDownloader(APITestCase):
format='json',
expected_status=status.HTTP_200_OK)
def test_can_download_labelling_json1(self):
def test_can_download_labelling_jsonl(self):
self.download_test_helper(url=self.labeling_url,
format='json1',
format='jsonl',
expected_status=status.HTTP_200_OK)
def test_can_download_plain_text(self):

10
app/api/views.py

@ -366,10 +366,10 @@ class TextDownloadAPI(APIView):
project = get_object_or_404(Project, pk=self.kwargs['project_id'])
documents = project.documents.all()
painter = self.select_painter(format)
# json1 format prints text labels while json format prints annotations with label ids
# json1 format - "labels": [[0, 15, "PERSON"], ..]
# json format - "annotations": [{"label": 5, "start_offset": 0, "end_offset": 2, "user": 1},..]
if format == "json1":
# jsonl-textlabel format prints text labels while jsonl format prints annotations with label ids
# jsonl-textlabel format - "labels": [[0, 15, "PERSON"], ..]
# jsonl format - "annotations": [{"label": 5, "start_offset": 0, "end_offset": 2, "user": 1},..]
if format == 'jsonl':
labels = project.labels.all()
data = JSONPainter.paint_labels(documents, labels)
else:
@ -379,7 +379,7 @@ class TextDownloadAPI(APIView):
def select_painter(self, format):
if format == 'csv':
return CSVPainter()
elif format == 'json' or format == "json1":
elif format == 'jsonl' or format == 'json':
return JSONPainter()
else:
raise ValidationError('format {} is invalid.'.format(format))

6
app/server/static/components/download_sequence_labeling.vue

@ -16,8 +16,8 @@ block select-format-area
input(
type="radio"
name="format"
value="json1"
v-bind:checked="format == 'json1'"
value="jsonl"
v-bind:checked="format == 'jsonl'"
v-model="format"
)
| JSON(Text-Labels)
@ -28,7 +28,7 @@ block example-format-area
include ./examples/download_sequence_labeling.jsonl
| ...
pre.code-block(v-show="format == 'json1'")
pre.code-block(v-show="format == 'jsonl'")
code.json
include ./examples/download_sequence_labeling.json1l
| ...

10
frontend/components/organisms/documents/DocumentExportForm.vue

@ -14,6 +14,7 @@
>
<h2>{{ $t('dataset.importDataMessage1') }}</h2>
<v-radio-group
ref="format"
v-model="selectedFormat"
:rules="fileFormatRules($t('rules.fileFormatRules'))"
>
@ -34,6 +35,8 @@
{{ example }}<br>
</span>
</v-sheet>
<h2>{{ $t('dataset.exportDataMessage2') }}</h2>
<v-text-field v-model="selectedFileName" placeholder="Name the file" />
</v-form>
</template>
</base-card>
@ -64,6 +67,7 @@ export default {
valid: false,
file: null,
selectedFormat: null,
selectedFileName: 'project_' + this.$route.params.id + '_dataset',
fileFormatRules,
uploadFileRules
}
@ -87,13 +91,15 @@ export default {
return this.$refs.form.validate()
},
reset() {
this.$refs.form.reset()
this.$refs.format.reset()
},
download() {
if (this.validate()) {
this.exportDocument({
projectId: this.$route.params.id,
format: this.selectedFormat.type
fileName: this.selectedFileName,
format: this.selectedFormat.type,
suffix: this.selectedFormat.suffix
})
this.reset()
this.cancel()

1
frontend/i18n/en/projects/dataset.js

@ -13,6 +13,7 @@ export default {
importDataPlaceholder: 'File input',
exportDataTitle: 'Export Data',
exportDataMessage: 'Select a file format',
exportDataMessage2: 'Select a file name',
deleteDocumentsTitle: 'Delete Document',
deleteDocumentsMessage: 'Are you sure you want to delete these documents from this project?',
pageText: '{0}-{1} of {2}'

2
frontend/store/documents.js

@ -126,7 +126,7 @@ export const actions = {
const url = window.URL.createObjectURL(new Blob([response.data]))
const link = document.createElement('a')
link.href = url
link.setAttribute('download', 'file.' + data.format)
link.setAttribute('download', data.fileName + '.' + data.suffix)
document.body.appendChild(link)
link.click()
})

11
frontend/store/projects.js

@ -167,15 +167,18 @@ export const getters = {
getExportFormat(state) {
const csv = {
type: 'csv',
text: 'CSV'
text: 'CSV',
suffix: 'csv'
}
const json = {
type: 'json',
text: 'JSONL'
text: 'JSONL',
suffix: 'jsonl'
}
const jsonl = {
type: 'json1',
text: 'JSONL(Text label)'
type: 'jsonl',
text: 'JSONL(Text label)',
suffix: 'jsonl'
}
if (state.current.project_type === 'DocumentClassification') {
json.examples = [

Loading…
Cancel
Save