mirror of https://github.com/doccano/doccano.git
Browse Source
Merge pull request #2197 from doccano/enhancement/frontend-seq2seq
Merge pull request #2197 from doccano/enhancement/frontend-seq2seq
[Enhancement] frontendpull/2194/head
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 293 additions and 423 deletions
Split View
Diff Options
-
77frontend/composables/useTextLabel.ts
-
4frontend/domain/models/tasks/textLabel.ts
-
240frontend/pages/projects/_id/image-captioning/index.vue
-
2frontend/pages/projects/_id/labels/import.vue
-
169frontend/pages/projects/_id/sequence-to-sequence/index.vue
-
182frontend/pages/projects/_id/speech-to-text/index.vue
-
3frontend/plugins/services.ts
-
26frontend/services/application/tasks/seq2seq/seq2seqApplicationService.ts
-
13frontend/services/application/tasks/seq2seq/seq2seqData.ts
@ -0,0 +1,77 @@ |
|||
import { reactive } from '@nuxtjs/composition-api' |
|||
import { TextLabel } from '~/domain/models/tasks/textLabel' |
|||
|
|||
export const useTextLabel = (repository: any, projectId: string) => { |
|||
const state = reactive({ |
|||
labels: [] as TextLabel[], |
|||
error: '' |
|||
}) |
|||
|
|||
const validateText = (text: string) => { |
|||
if (state.labels.some((label) => label.text === text)) { |
|||
state.error = 'The label already exists.' |
|||
return false |
|||
} |
|||
return true |
|||
} |
|||
|
|||
const add = async (exampleId: number, text: string) => { |
|||
const textLabel = TextLabel.create(text) |
|||
if (!validateText(textLabel.text)) { |
|||
return |
|||
} |
|||
try { |
|||
await repository.create(projectId, exampleId, textLabel) |
|||
await list(exampleId) |
|||
} catch (e: any) { |
|||
state.error = e.response.data.detail |
|||
} |
|||
} |
|||
|
|||
const list = async (exampleId: number) => { |
|||
state.labels = await repository.list(projectId, exampleId) |
|||
} |
|||
|
|||
const update = async (exampleId: number, labelId: number, text: string) => { |
|||
if (!validateText(text)) { |
|||
return |
|||
} |
|||
const label = state.labels.find((label) => label.id === labelId)! |
|||
label.updateText(text) |
|||
try { |
|||
await repository.update(projectId, exampleId, labelId, label) |
|||
await list(exampleId) |
|||
} catch (e: any) { |
|||
state.error = e.response.data.detail |
|||
} |
|||
} |
|||
|
|||
const remove = async (exampleId: number, labelId: number) => { |
|||
await repository.delete(projectId, exampleId, labelId) |
|||
state.labels = state.labels.filter((label) => label.id !== labelId) |
|||
} |
|||
|
|||
const clear = async (exampleId: number) => { |
|||
await repository.clear(projectId, exampleId) |
|||
state.labels = [] |
|||
} |
|||
|
|||
const autoLabel = async (exampleId: number) => { |
|||
try { |
|||
await repository.autoLabel(projectId, exampleId) |
|||
await list(exampleId) |
|||
} catch (e: any) { |
|||
state.error = e.response.data.detail |
|||
} |
|||
} |
|||
|
|||
return { |
|||
state, |
|||
add, |
|||
list, |
|||
update, |
|||
remove, |
|||
clear, |
|||
autoLabel |
|||
} |
|||
} |
@ -1,26 +0,0 @@ |
|||
import { AnnotationApplicationService } from '../annotationApplicationService' |
|||
import { Seq2seqDTO } from './seq2seqData' |
|||
import { TextLabel } from '@/domain/models/tasks/textLabel' |
|||
|
|||
export class Seq2seqApplicationService extends AnnotationApplicationService<TextLabel> { |
|||
public async list(projectId: string, exampleId: number): Promise<Seq2seqDTO[]> { |
|||
const items = await this.repository.list(projectId, exampleId) |
|||
return items.map((item) => new Seq2seqDTO(item)) |
|||
} |
|||
|
|||
public async create(projectId: string, exampleId: number, text: string): Promise<void> { |
|||
const item = new TextLabel(0, text, 0) |
|||
await this.repository.create(projectId, exampleId, item) |
|||
} |
|||
|
|||
public async changeText( |
|||
projectId: string, |
|||
exampleId: number, |
|||
labelId: number, |
|||
text: string |
|||
): Promise<void> { |
|||
const textLabel = await this.repository.find(projectId, exampleId, labelId) |
|||
textLabel.updateText(text) |
|||
await this.repository.update(projectId, exampleId, labelId, textLabel) |
|||
} |
|||
} |
@ -1,13 +0,0 @@ |
|||
import { TextLabel } from '@/domain/models/tasks/textLabel' |
|||
|
|||
export class Seq2seqDTO { |
|||
id: number |
|||
text: string |
|||
user: number |
|||
|
|||
constructor(item: TextLabel) { |
|||
this.id = item.id |
|||
this.text = item.text |
|||
this.user = item.user |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save