Browse Source

Merge pull request #1116 from SwiftPredator/Enhancement/DynamicFilename

Enhancement/dynamic filename + changed json1 naming to jsonl
pull/1156/head
Hiroki Nakayama 4 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', format='json',
expected_status=status.HTTP_200_OK) 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, self.download_test_helper(url=self.labeling_url,
format='json1',
format='jsonl',
expected_status=status.HTTP_200_OK) expected_status=status.HTTP_200_OK)
def test_can_download_plain_text(self): 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']) project = get_object_or_404(Project, pk=self.kwargs['project_id'])
documents = project.documents.all() documents = project.documents.all()
painter = self.select_painter(format) 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() labels = project.labels.all()
data = JSONPainter.paint_labels(documents, labels) data = JSONPainter.paint_labels(documents, labels)
else: else:
@ -379,7 +379,7 @@ class TextDownloadAPI(APIView):
def select_painter(self, format): def select_painter(self, format):
if format == 'csv': if format == 'csv':
return CSVPainter() return CSVPainter()
elif format == 'json' or format == "json1":
elif format == 'jsonl' or format == 'json':
return JSONPainter() return JSONPainter()
else: else:
raise ValidationError('format {} is invalid.'.format(format)) 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( input(
type="radio" type="radio"
name="format" name="format"
value="json1"
v-bind:checked="format == 'json1'"
value="jsonl"
v-bind:checked="format == 'jsonl'"
v-model="format" v-model="format"
) )
| JSON(Text-Labels) | JSON(Text-Labels)
@ -28,7 +28,7 @@ block example-format-area
include ./examples/download_sequence_labeling.jsonl include ./examples/download_sequence_labeling.jsonl
| ... | ...
pre.code-block(v-show="format == 'json1'")
pre.code-block(v-show="format == 'jsonl'")
code.json code.json
include ./examples/download_sequence_labeling.json1l include ./examples/download_sequence_labeling.json1l
| ... | ...

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

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

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

@ -13,6 +13,7 @@ export default {
importDataPlaceholder: 'File input', importDataPlaceholder: 'File input',
exportDataTitle: 'Export Data', exportDataTitle: 'Export Data',
exportDataMessage: 'Select a file format', exportDataMessage: 'Select a file format',
exportDataMessage2: 'Select a file name',
deleteDocumentsTitle: 'Delete Document', deleteDocumentsTitle: 'Delete Document',
deleteDocumentsMessage: 'Are you sure you want to delete these documents from this project?', deleteDocumentsMessage: 'Are you sure you want to delete these documents from this project?',
pageText: '{0}-{1} of {2}' 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 url = window.URL.createObjectURL(new Blob([response.data]))
const link = document.createElement('a') const link = document.createElement('a')
link.href = url link.href = url
link.setAttribute('download', 'file.' + data.format)
link.setAttribute('download', data.fileName + '.' + data.suffix)
document.body.appendChild(link) document.body.appendChild(link)
link.click() link.click()
}) })

11
frontend/store/projects.js

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

Loading…
Cancel
Save