Browse Source

Add TextLabel API

pull/1592/head
Hironsan 3 years ago
parent
commit
a2de176303
3 changed files with 68 additions and 4 deletions
  1. 47
      backend/api/tests/api/test_annotation.py
  2. 12
      backend/api/urls.py
  3. 13
      backend/api/views/tasks/text.py

47
backend/api/tests/api/test_annotation.py

@ -1,8 +1,8 @@
from rest_framework import status
from rest_framework.reverse import reverse
from ...models import (DOCUMENT_CLASSIFICATION, SEQUENCE_LABELING, Category,
Span)
from ...models import (DOCUMENT_CLASSIFICATION, SEQ2SEQ, SEQUENCE_LABELING,
Category, Span, TextLabel)
from .utils import (CRUDMixin, make_annotation, make_doc, make_label,
make_user, prepare_project)
@ -58,6 +58,12 @@ class TestSpanList(TestAnnotationList):
make_annotation(cls.task, doc=doc, user=member, start_offset=0, end_offset=1)
class TestTextList(TestAnnotationList):
model = TextLabel
task = SEQ2SEQ
view_name = 'text_list'
class TestSharedAnnotationList(CRUDMixin):
model = Category
task = DOCUMENT_CLASSIFICATION
@ -92,7 +98,7 @@ class TestSharedCategoryList(TestSharedAnnotationList):
view_name = 'category_list'
class TestSharedSpanList(TestSharedCategoryList):
class TestSharedSpanList(TestSharedAnnotationList):
model = Span
task = SEQUENCE_LABELING
view_name = 'span_list'
@ -110,6 +116,12 @@ class TestSharedSpanList(TestSharedCategoryList):
cls.start_offset += 1
class TestSharedTextList(TestSharedAnnotationList):
model = TextLabel
task = SEQ2SEQ
view_name = 'text_list'
class TestAnnotationCreation(CRUDMixin):
task = DOCUMENT_CLASSIFICATION
view_name = 'annotation_list'
@ -149,6 +161,14 @@ class TestSpanCreation(TestAnnotationCreation):
return {'label': label.id, 'start_offset': 0, 'end_offset': 1}
class TestTextLabelCreation(TestAnnotationCreation):
task = SEQ2SEQ
view_name = 'text_list'
def create_data(self):
return {'text': 'example'}
class TestAnnotationDetail(CRUDMixin):
task = SEQUENCE_LABELING
view_name = 'annotation_detail'
@ -218,6 +238,18 @@ class TestSpanDetail(TestAnnotationDetail):
view_name = 'span_detail'
class TestTextDetail(TestAnnotationDetail):
task = SEQ2SEQ
view_name = 'text_detail'
def setUp(self):
super().setUp()
self.data = {'text': 'changed'}
def create_annotation_data(self, doc):
return make_annotation(task=self.task, doc=doc, user=self.project.users[0])
class TestSharedAnnotationDetail(CRUDMixin):
task = DOCUMENT_CLASSIFICATION
view_name = 'annotation_detail'
@ -255,3 +287,12 @@ class TestSharedSpanDetail(TestSharedAnnotationDetail):
def make_annotation(self, doc, member):
return make_annotation(self.task, doc=doc, user=member, start_offset=0, end_offset=1)
class TestSharedTextDetail(TestSharedAnnotationDetail):
task = SEQ2SEQ
view_name = 'text_detail'
def setUp(self):
super().setUp()
self.data = {'text': 'changed'}

12
backend/api/urls.py

@ -4,7 +4,7 @@ from .views import (annotation, annotation_relations, auto_labeling, comment,
example, example_state, export_dataset, health,
import_dataset, import_export, label, project,
relation_types, role, statistics, tag, task, user)
from .views.tasks import category, span
from .views.tasks import category, span, text
urlpatterns_project = [
path(
@ -133,6 +133,16 @@ urlpatterns_project = [
view=span.SpanDetailAPI.as_view(),
name='span_detail'
),
path(
route='examples/<int:example_id>/texts',
view=text.TextLabelListAPI.as_view(),
name='text_list'
),
path(
route='examples/<int:example_id>/texts/<int:annotation_id>',
view=text.TextLabelDetailAPI.as_view(),
name='text_detail'
),
path(
route='tags',
view=tag.TagList.as_view(),

13
backend/api/views/tasks/text.py

@ -0,0 +1,13 @@
from ...models import TextLabel
from ...serializers import TextLabelSerializer
from .base import BaseDetailAPI, BaseListAPI
class TextLabelListAPI(BaseListAPI):
annotation_class = TextLabel
serializer_class = TextLabelSerializer
class TextLabelDetailAPI(BaseDetailAPI):
queryset = TextLabel.objects.all()
serializer_class = TextLabelSerializer
Loading…
Cancel
Save