diff --git a/backend/api/migrations/0017_alter_example_id.py b/backend/api/migrations/0017_alter_example_id.py deleted file mode 100644 index a9e6a6ea..00000000 --- a/backend/api/migrations/0017_alter_example_id.py +++ /dev/null @@ -1,19 +0,0 @@ -# Generated by Django 3.2.8 on 2021-11-02 05:47 - -from django.db import migrations, models -import uuid - - -class Migration(migrations.Migration): - - dependencies = [ - ('api', '0016_auto_20211018_0556'), - ] - - operations = [ - migrations.AlterField( - model_name='example', - name='id', - field=models.UUIDField(db_index=True, default=uuid.uuid4, editable=False, primary_key=True, serialize=False), - ), - ] diff --git a/backend/api/models.py b/backend/api/models.py index 1677164a..7b1660e6 100644 --- a/backend/api/models.py +++ b/backend/api/models.py @@ -150,7 +150,7 @@ class Label(models.Model): class Example(models.Model): - id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, db_index=True) + uuid = models.UUIDField(default=uuid.uuid4, editable=False, db_index=True, unique=True) meta = models.JSONField(default=dict) filename = models.FileField(default='.', max_length=1024) project = models.ForeignKey( diff --git a/backend/api/tasks.py b/backend/api/tasks.py index 26d197a0..5038e254 100644 --- a/backend/api/tasks.py +++ b/backend/api/tasks.py @@ -63,12 +63,12 @@ class DataFactory: def create_data(self, examples, project): uuids = sorted(uuid.uuid4() for _ in range(len(examples))) dataset = [ - self.data_class(id=uid, project=project, **example.data) + self.data_class(uuid=uid, project=project, **example.data) for uid, example in zip(uuids, examples) ] - data = self.data_class.objects.bulk_create(dataset) - data.sort(key=lambda example: example.id) - return data + self.data_class.objects.bulk_create(dataset) + data = self.data_class.objects.in_bulk(uuids, field_name='uuid') + return [data[uid] for uid in uuids] def create_annotation(self, examples, ids, user, project): mapping = {label.text: label.id for label in project.labels.all()} diff --git a/backend/api/urls.py b/backend/api/urls.py index 2356a5af..6493e657 100644 --- a/backend/api/urls.py +++ b/backend/api/urls.py @@ -51,7 +51,7 @@ urlpatterns_project = [ name='example_list' ), path( - route='examples/', + route='examples/', view=example.ExampleDetail.as_view(), name='example_detail' ), @@ -92,23 +92,23 @@ urlpatterns_project = [ name='doc_list' ), path( - route='docs/', + route='docs/', view=example.DocumentDetail.as_view(), name='doc_detail' ), path( - route='approval/', + route='approval/', view=annotation.ApprovalAPI.as_view(), name='approve_labels' ), # Todo: change. path( - route='docs//annotations', + route='docs//annotations', view=annotation.AnnotationList.as_view(), name='annotation_list' ), path( - route='docs//annotations/', + route='docs//annotations/', view=annotation.AnnotationDetail.as_view(), name='annotation_detail' ), @@ -123,7 +123,7 @@ urlpatterns_project = [ name='tag_detail' ), path( - route='examples//comments', + route='examples//comments', view=comment.CommentListDoc.as_view(), name='comment_list_doc' ), @@ -133,12 +133,12 @@ urlpatterns_project = [ name='comment_list_project' ), path( - route='examples//comments/', + route='examples//comments/', view=comment.CommentDetail.as_view(), name='comment_detail' ), path( - route='examples//states', + route='examples//states', view=example_state.ExampleStateList.as_view(), name='example_state_list' ), @@ -178,7 +178,7 @@ urlpatterns_project = [ name='auto_labeling_config_test' ), path( - route='examples//auto-labeling', + route='examples//auto-labeling', view=auto_labeling.AutoLabelingAnnotation.as_view(), name='auto_labeling_annotation' ), diff --git a/backend/api/views/download/writer.py b/backend/api/views/download/writer.py index c42bfa7a..dd0e88b4 100644 --- a/backend/api/views/download/writer.py +++ b/backend/api/views/download/writer.py @@ -82,7 +82,7 @@ class CsvWriter(BaseWriter): def create_line(self, record) -> Dict: return { - 'id': str(record.id), + 'id': record.id, 'data': record.data, 'label': '#'.join(record.label), **record.metadata @@ -120,7 +120,7 @@ class JSONWriter(BaseWriter): def create_line(self, record) -> Dict: return { - 'id': str(record.id), + 'id': record.id, 'data': record.data, 'label': record.label, **record.metadata @@ -132,7 +132,7 @@ class JSONLWriter(LineWriter): def create_line(self, record): return json.dumps({ - 'id': str(record.id), + 'id': record.id, 'data': record.data, 'label': record.label, **record.metadata diff --git a/frontend/components/tasks/toolbar/ToolbarLaptop.vue b/frontend/components/tasks/toolbar/ToolbarLaptop.vue index c312861c..ebd76775 100644 --- a/frontend/components/tasks/toolbar/ToolbarLaptop.vue +++ b/frontend/components/tasks/toolbar/ToolbarLaptop.vue @@ -104,7 +104,7 @@ export default Vue.extend({ props: { docId: { - type: String, + type: Number, required: true }, enableAutoLabeling: { diff --git a/frontend/components/tasks/toolbar/forms/FormComment.vue b/frontend/components/tasks/toolbar/forms/FormComment.vue index ddb9a30e..53925a50 100644 --- a/frontend/components/tasks/toolbar/forms/FormComment.vue +++ b/frontend/components/tasks/toolbar/forms/FormComment.vue @@ -36,7 +36,7 @@ export default Vue.extend({ props: { docId: { - type: String, + type: Number, required: true } }, diff --git a/frontend/composables/useTeacherList.ts b/frontend/composables/useTeacherList.ts index f44fd020..aae1b88b 100644 --- a/frontend/composables/useTeacherList.ts +++ b/frontend/composables/useTeacherList.ts @@ -7,14 +7,14 @@ export const useTeacherList = (service: any) => { const getTeacherList = async( projectId: string, - exampleId: string + exampleId: number ) => { state.teacherList = await service.list(projectId, exampleId) } const removeTeacher = async( projectId: string, - exampleId: string, + exampleId: number, teacherId: number ) => { await service.delete(projectId, exampleId, teacherId) @@ -23,7 +23,7 @@ export const useTeacherList = (service: any) => { const annotateLabel = async( projectId: string, - exampleId: string, + exampleId: number, labelId: number ) => { await service.create(projectId, exampleId, labelId) @@ -32,7 +32,7 @@ export const useTeacherList = (service: any) => { const clearTeacherList = async( projectId: string, - exampleId: string + exampleId: number ) => { await service.clear(projectId, exampleId) await getTeacherList(projectId, exampleId) @@ -40,7 +40,7 @@ export const useTeacherList = (service: any) => { const autoLabel = async( projectId: string, - exampleId: string + exampleId: number ) => { await service.autoLabel(projectId, exampleId) await getTeacherList(projectId, exampleId) @@ -48,7 +48,7 @@ export const useTeacherList = (service: any) => { const annotateOrRemoveLabel = async( projectId: string, - exampleId: string, + exampleId: number, srcKey: string ) => { const labelId = parseInt(srcKey, 10) diff --git a/frontend/domain/models/comment/comment.ts b/frontend/domain/models/comment/comment.ts index 936b95cf..88a647b7 100644 --- a/frontend/domain/models/comment/comment.ts +++ b/frontend/domain/models/comment/comment.ts @@ -41,14 +41,14 @@ export class CommentItem { public id: number, public user: number, public username: string, - public example: string, + public example: number, public text: string, public createdAt: string ) {} static valueOf( { id, user, username, example, text, created_at }: - { id: number, user: number, username: string, example: string, + { id: number, user: number, username: string, example: number, text: string, created_at: string } ): CommentItem { return new CommentItem(id, user, username, example, text, created_at) diff --git a/frontend/domain/models/comment/commentRepository.ts b/frontend/domain/models/comment/commentRepository.ts index 17baf94d..b2078450 100644 --- a/frontend/domain/models/comment/commentRepository.ts +++ b/frontend/domain/models/comment/commentRepository.ts @@ -4,7 +4,7 @@ export interface CommentItemResponse { id: number, user: number, username: string, - example: string, + example: number, text: string, created_at: string } @@ -12,13 +12,13 @@ export interface CommentItemResponse { export interface CommentRepository { listAll(projectId: string, q: string): Promise - list(projectId: string, docId: string): Promise + list(projectId: string, docId: number): Promise - create(projectId: string, docId: string, text: string): Promise + create(projectId: string, docId: number, text: string): Promise - update(projectId: string, docId: string, item: CommentItem): Promise + update(projectId: string, docId: number, item: CommentItem): Promise - delete(projectId: string, docId: string, commentId: number): Promise + delete(projectId: string, docId: number, commentId: number): Promise deleteBulk(projectId: string, items: number[]): Promise } diff --git a/frontend/domain/models/example/example.ts b/frontend/domain/models/example/example.ts index 39c525e3..1084ce39 100644 --- a/frontend/domain/models/example/example.ts +++ b/frontend/domain/models/example/example.ts @@ -43,7 +43,7 @@ export class ExampleItemList { export class ExampleItem { constructor( - public id: string, + public id: number, public text: string, public meta: object, public annotationApprover: boolean | null, @@ -55,7 +55,7 @@ export class ExampleItem { static valueOf( { id, text, meta, annotation_approver, comment_count, filename, is_confirmed }: { - id: string, + id: number, text: string, meta: object, annotation_approver: boolean | null, diff --git a/frontend/domain/models/example/exampleRepository.ts b/frontend/domain/models/example/exampleRepository.ts index 5fbd11bc..c4d564ee 100644 --- a/frontend/domain/models/example/exampleRepository.ts +++ b/frontend/domain/models/example/exampleRepository.ts @@ -9,13 +9,13 @@ export interface ExampleRepository { update(projectId: string, item: ExampleItem): Promise - bulkDelete(projectId: string, ids: string[]): Promise + bulkDelete(projectId: string, ids: number[]): Promise deleteAll(projectId: string): Promise - findById(projectId: string, exampleId: string): Promise + findById(projectId: string, exampleId: number): Promise - approve(projectId: string, docId: string, approved: boolean): Promise + approve(projectId: string, docId: number, approved: boolean): Promise - confirm(projectId: string, exampleId: string): Promise + confirm(projectId: string, exampleId: number): Promise } diff --git a/frontend/domain/models/tasks/annotationRepository.ts b/frontend/domain/models/tasks/annotationRepository.ts index 59ee453f..f603b63b 100644 --- a/frontend/domain/models/tasks/annotationRepository.ts +++ b/frontend/domain/models/tasks/annotationRepository.ts @@ -8,34 +8,34 @@ export abstract class AnnotationRepository { readonly request = ApiService ) {} - public async list(projectId: string, docId: string): Promise { + public async list(projectId: string, docId: number): Promise { const url = this.baseUrl(projectId, docId) const response = await this.request.get(url) const items: T[] = response.data return items.map(item => this.model.valueOf(item)) } - public async create(projectId: string, docId: string, item: T): Promise { + public async create(projectId: string, docId: number, item: T): Promise { const url = this.baseUrl(projectId, docId) await this.request.post(url, item.toObject()) } - public async delete(projectId: string, docId: string, annotationId: number): Promise { + public async delete(projectId: string, docId: number, annotationId: number): Promise { const url = this.baseUrl(projectId, docId) + `/${annotationId}` await this.request.delete(url) } - public async clear(projectId: string, docId: string): Promise { + public async clear(projectId: string, docId: number): Promise { const url = this.baseUrl(projectId, docId) await this.request.delete(url) } - public async autoLabel(projectId: string, docId: string): Promise { + public async autoLabel(projectId: string, docId: number): Promise { const url = `/projects/${projectId}/examples/${docId}/auto-labeling` await this.request.post(url, {}) } - protected baseUrl(projectId: string, docId: string): string { + protected baseUrl(projectId: string, docId: number): string { return `/projects/${projectId}/examples/${docId}/annotations` } } diff --git a/frontend/repositories/comment/apiCommentRepository.ts b/frontend/repositories/comment/apiCommentRepository.ts index 4f05daaf..8cd28c59 100644 --- a/frontend/repositories/comment/apiCommentRepository.ts +++ b/frontend/repositories/comment/apiCommentRepository.ts @@ -14,28 +14,28 @@ export class APICommentRepository implements CommentRepository { return items.map(item => CommentItem.valueOf(item)) } - async list(projectId: string, exampleId: string): Promise { + async list(projectId: string, exampleId: number): Promise { const url = `/projects/${projectId}/examples/${exampleId}/comments` const response = await this.request.get(url) const items: CommentItemResponse[] = response.data return items.map(item => CommentItem.valueOf(item)) } - async create(projectId: string, exampleId: string, text: string): Promise { + async create(projectId: string, exampleId: number, text: string): Promise { const url = `/projects/${projectId}/examples/${exampleId}/comments` const response = await this.request.post(url, { projectId, exampleId, text }) const responseItem: CommentItemResponse = response.data return CommentItem.valueOf(responseItem) } - async update(projectId: string, exampleId: string, item: CommentItem): Promise { + async update(projectId: string, exampleId: number, item: CommentItem): Promise { const url = `/projects/${projectId}/examples/${exampleId}/comments/${item.id}` const response = await this.request.put(url, item.toObject()) const responseItem: CommentItemResponse = response.data return CommentItem.valueOf(responseItem) } - async delete(projectId: string, exampleId: string, commentId: number): Promise { + async delete(projectId: string, exampleId: number, commentId: number): Promise { const url = `/projects/${projectId}/examples/${exampleId}/comments/${commentId}` const response = await this.request.delete(url) } diff --git a/frontend/repositories/example/apiDocumentRepository.ts b/frontend/repositories/example/apiDocumentRepository.ts index edc27fe3..3596c66b 100644 --- a/frontend/repositories/example/apiDocumentRepository.ts +++ b/frontend/repositories/example/apiDocumentRepository.ts @@ -26,7 +26,7 @@ export class APIExampleRepository implements ExampleRepository { return ExampleItem.valueOf(response.data) } - async bulkDelete(projectId: string, ids: string[]): Promise { + async bulkDelete(projectId: string, ids: number[]): Promise { const url = `/projects/${projectId}/examples` await this.request.delete(url, { ids }) } @@ -36,18 +36,18 @@ export class APIExampleRepository implements ExampleRepository { await this.request.delete(url) } - async findById(projectId: string, exampleId: string): Promise { + async findById(projectId: string, exampleId: number): Promise { const url = `/projects/${projectId}/examples/${exampleId}` const response = await this.request.get(url) return ExampleItem.valueOf(response.data) } - async approve(projectId: string, exampleId: string, approved: boolean): Promise { + async approve(projectId: string, exampleId: number, approved: boolean): Promise { const url = `/projects/${projectId}/approval/${exampleId}` await this.request.post(url, { approved }) } - async confirm(projectId: string, exampleId: string): Promise { + async confirm(projectId: string, exampleId: number): Promise { const url = `/projects/${projectId}/examples/${exampleId}/states` await this.request.post(url, {}) } diff --git a/frontend/repositories/tasks/seq2seq/apiSeq2seq.ts b/frontend/repositories/tasks/seq2seq/apiSeq2seq.ts index a4e3811c..d1672c04 100644 --- a/frontend/repositories/tasks/seq2seq/apiSeq2seq.ts +++ b/frontend/repositories/tasks/seq2seq/apiSeq2seq.ts @@ -7,13 +7,13 @@ export class APISeq2seqRepository extends AnnotationRepository { super(Seq2seqLabel) } - public async update(projectId: string, docId: string, annotationId: number, text: string) { + public async update(projectId: string, docId: number, annotationId: number, text: string) { const url = this.baseUrl(projectId, docId) + `/${annotationId}` const payload = { text } await this.request.patch(url, payload) } - protected baseUrl(projectId: string, docId: string): string { + protected baseUrl(projectId: string, docId: number): string { return `/projects/${projectId}/docs/${docId}/annotations` } } diff --git a/frontend/repositories/tasks/sequenceLabeling/apiSequenceLabeling.ts b/frontend/repositories/tasks/sequenceLabeling/apiSequenceLabeling.ts index 0b8969cf..4d6b1a16 100644 --- a/frontend/repositories/tasks/sequenceLabeling/apiSequenceLabeling.ts +++ b/frontend/repositories/tasks/sequenceLabeling/apiSequenceLabeling.ts @@ -7,13 +7,13 @@ export class APISequenceLabelingRepository extends AnnotationRepository new CommentReadDTO(item)) } - public async list(projectId: string, docId: string): Promise { + public async list(projectId: string, docId: number): Promise { const items = await this.repository.list(projectId, docId) return items.map(item => new CommentReadDTO(item)) } - public create(projectId: string, docId: string, text: string): Promise { + public create(projectId: string, docId: number, text: string): Promise { return this.repository.create(projectId, docId, text) } - public update(projectId: string, docId: string, item: CommentReadDTO): Promise { + public update(projectId: string, docId: number, item: CommentReadDTO): Promise { const comment = new CommentItem( item.id, item.user, item.username, docId, item.text, item.createdAt ) return this.repository.update(projectId, docId, comment) } - public delete(projectId: string, docId: string, item: CommentReadDTO): Promise { + public delete(projectId: string, docId: number, item: CommentReadDTO): Promise { return this.repository.delete(projectId, docId, item.id) } diff --git a/frontend/services/application/comment/commentData.ts b/frontend/services/application/comment/commentData.ts index 264e90df..90d7623c 100644 --- a/frontend/services/application/comment/commentData.ts +++ b/frontend/services/application/comment/commentData.ts @@ -5,7 +5,7 @@ export class CommentReadDTO { id: number; user: number; username: string; - example: string; + example: number; text: string; createdAt: string; diff --git a/frontend/services/application/example/exampleApplicationService.ts b/frontend/services/application/example/exampleApplicationService.ts index 1dcb81d2..1959fec5 100644 --- a/frontend/services/application/example/exampleApplicationService.ts +++ b/frontend/services/application/example/exampleApplicationService.ts @@ -52,16 +52,16 @@ export class ExampleApplicationService { return this.repository.bulkDelete(projectId, ids) } - public async findById(projectId: string, exampleId: string): Promise { + public async findById(projectId: string, exampleId: number): Promise { const response = await this.repository.findById(projectId, exampleId) return new ExampleDTO(response) } - public async approve(projectId: string, docId: string, approved: boolean): Promise { + public async approve(projectId: string, docId: number, approved: boolean): Promise { await this.repository.approve(projectId, docId, approved) } - public async confirm(projectId: string, exampleId: string): Promise { + public async confirm(projectId: string, exampleId: number): Promise { await this.repository.confirm(projectId, exampleId) } diff --git a/frontend/services/application/example/exampleData.ts b/frontend/services/application/example/exampleData.ts index 92cebd09..d368bd05 100644 --- a/frontend/services/application/example/exampleData.ts +++ b/frontend/services/application/example/exampleData.ts @@ -2,7 +2,7 @@ import { ExampleItem, ExampleItemList } from '~/domain/models/example/example' export class ExampleDTO { - id: string; + id: number; text: string; meta: object; annotationApprover: boolean | null; diff --git a/frontend/services/application/tasks/annotationApplicationService.ts b/frontend/services/application/tasks/annotationApplicationService.ts index d4077137..29acd80b 100644 --- a/frontend/services/application/tasks/annotationApplicationService.ts +++ b/frontend/services/application/tasks/annotationApplicationService.ts @@ -7,15 +7,15 @@ export class AnnotationApplicationService { readonly repository: AnnotationRepository ) {} - public async delete(projectId: string, docId: string, annotationId: number): Promise { + public async delete(projectId: string, docId: number, annotationId: number): Promise { await this.repository.delete(projectId, docId, annotationId) } - public async clear(projectId: string, docId: string): Promise { + public async clear(projectId: string, docId: number): Promise { await this.repository.clear(projectId, docId) } - public async autoLabel(projectId: string, docId: string): Promise { + public async autoLabel(projectId: string, docId: number): Promise { await this.repository.autoLabel(projectId, docId) } } diff --git a/frontend/services/application/tasks/seq2seq/seq2seqApplicationService.ts b/frontend/services/application/tasks/seq2seq/seq2seqApplicationService.ts index be6e1517..b8db47e6 100644 --- a/frontend/services/application/tasks/seq2seq/seq2seqApplicationService.ts +++ b/frontend/services/application/tasks/seq2seq/seq2seqApplicationService.ts @@ -10,17 +10,17 @@ export class Seq2seqApplicationService extends AnnotationApplicationService { + public async list(projectId: string, docId: number): Promise { const items = await this.repository.list(projectId, docId) return items.map(item => new Seq2seqDTO(item)) } - public async create(projectId: string, docId: string, text: string): Promise { + public async create(projectId: string, docId: number, text: string): Promise { const item = new Seq2seqLabel(0, text, 0) await this.repository.create(projectId, docId, item) } - public async changeText(projectId: string, docId: string, annotationId: number, text: string): Promise { + public async changeText(projectId: string, docId: number, annotationId: number, text: string): Promise { await this.repository.update(projectId, docId, annotationId, text) } } diff --git a/frontend/services/application/tasks/sequenceLabeling/sequenceLabelingApplicationService.ts b/frontend/services/application/tasks/sequenceLabeling/sequenceLabelingApplicationService.ts index e61270c7..451e445d 100644 --- a/frontend/services/application/tasks/sequenceLabeling/sequenceLabelingApplicationService.ts +++ b/frontend/services/application/tasks/sequenceLabeling/sequenceLabelingApplicationService.ts @@ -13,17 +13,17 @@ export class SequenceLabelingApplicationService extends AnnotationApplicationSer super(new APISequenceLabelingRepository()) } - public async list(projectId: string, docId: string): Promise { + public async list(projectId: string, docId: number): Promise { const items = await this.repository.list(projectId, docId) return items.map(item => new SequenceLabelingDTO(item)) } - public async create(projectId: string, docId: string, labelId: number, startOffset: number, endOffset: number): Promise { + public async create(projectId: string, docId: number, labelId: number, startOffset: number, endOffset: number): Promise { const item = new SequenceLabelingLabel(0, labelId, 0, startOffset, endOffset) await this.repository.create(projectId, docId, item) } - public async changeLabel(projectId: string, docId: string, annotationId: number, labelId: number): Promise { + public async changeLabel(projectId: string, docId: number, annotationId: number, labelId: number): Promise { await this.repository.update(projectId, docId, annotationId, labelId) } diff --git a/frontend/services/application/tasks/textClassification/textClassificationApplicationService.ts b/frontend/services/application/tasks/textClassification/textClassificationApplicationService.ts index e5835903..067f53c3 100644 --- a/frontend/services/application/tasks/textClassification/textClassificationApplicationService.ts +++ b/frontend/services/application/tasks/textClassification/textClassificationApplicationService.ts @@ -4,12 +4,12 @@ import { TextClassificationItem } from '~/domain/models/tasks/textClassification export class TextClassificationApplicationService extends AnnotationApplicationService { - public async list(projectId: string, docId: string): Promise { + public async list(projectId: string, docId: number): Promise { const items = await this.repository.list(projectId, docId) return items.map(item => new TextClassificationDTO(item)) } - public async create(projectId: string, docId: string, labelId: number): Promise { + public async create(projectId: string, docId: number, labelId: number): Promise { const item = new TextClassificationItem(0, labelId, 0) await this.repository.create(projectId, docId, item) }