Browse Source

Merge branch 'master' into enhancement/deleteEntity

pull/1581/head
Hironsan 3 years ago
parent
commit
f268f8a46b
4 changed files with 19 additions and 6 deletions
  1. 2
      backend/api/models.py
  2. 12
      backend/api/tests/api/test_annotation.py
  3. 4
      backend/api/tests/api/utils.py
  4. 7
      backend/api/tests/test_models.py

2
backend/api/models.py

@ -287,7 +287,7 @@ class Span(Annotation):
if allow_overlapping:
super().validate_unique(exclude=exclude)
else:
if Span.objects.filter(example=self.example).filter(
if Span.objects.exclude(id=self.id).filter(example=self.example).filter(
models.Q(start_offset__gte=self.start_offset, start_offset__lt=self.end_offset) |
models.Q(end_offset__gt=self.start_offset, end_offset__lte=self.end_offset) |
models.Q(start_offset__lte=self.start_offset, end_offset__gte=self.end_offset)

12
backend/api/tests/api/test_annotation.py

@ -1,7 +1,7 @@
from rest_framework import status
from rest_framework.reverse import reverse
from ...models import DOCUMENT_CLASSIFICATION, Category
from ...models import DOCUMENT_CLASSIFICATION, SEQUENCE_LABELING, Category
from .utils import (CRUDMixin, make_annotation, make_doc, make_label,
make_user, prepare_project)
@ -79,11 +79,17 @@ class TestAnnotationCreation(CRUDMixin):
class TestAnnotationDetail(CRUDMixin):
def setUp(self):
self.project = prepare_project(task=DOCUMENT_CLASSIFICATION)
self.project = prepare_project(task=SEQUENCE_LABELING)
self.non_member = make_user()
doc = make_doc(self.project.item)
label = make_label(self.project.item)
annotation = make_annotation(task=DOCUMENT_CLASSIFICATION, doc=doc, user=self.project.users[0])
annotation = make_annotation(
task=SEQUENCE_LABELING,
doc=doc,
user=self.project.users[0],
start_offset=0,
end_offset=1
)
self.data = {'label': label.id}
self.url = reverse(viewname='annotation_detail', args=[self.project.item.id, doc.id, annotation.id])

4
backend/api/tests/api/utils.py

@ -109,14 +109,14 @@ def make_auto_labeling_config(project):
return mommy.make('AutoLabelingConfig', project=project)
def make_annotation(task, doc, user):
def make_annotation(task, doc, user, **kwargs):
annotation_model = {
DOCUMENT_CLASSIFICATION: 'Category',
SEQUENCE_LABELING: 'Span',
SEQ2SEQ: 'TextLabel',
SPEECH2TEXT: 'TextLabel'
}.get(task)
return mommy.make(annotation_model, example=doc, user=user)
return mommy.make(annotation_model, example=doc, user=user, **kwargs)
def prepare_project(task: str = 'Any', collaborative_annotation=False):

7
backend/api/tests/test_models.py

@ -150,6 +150,13 @@ class TestSequenceAnnotation(TestCase):
mommy.make('Span', example=example, start_offset=0, end_offset=5)
mommy.make('Span', example=example, start_offset=10, end_offset=15)
def test_update(self):
project = mommy.make('SequenceLabelingProject', allow_overlapping=False)
example = mommy.make('Example', project=project)
span = mommy.make('Span', example=example, start_offset=0, end_offset=5)
span.end_offset = 6
span.save()
class TestSeq2seqAnnotation(TestCase):

Loading…
Cancel
Save