Browse Source

Add fields to SequenceLabelingProject

pull/1511/head
Hironsan 3 years ago
parent
commit
df75f6bcef
4 changed files with 93 additions and 0 deletions
  1. 65
      backend/api/migrations/0016_auto_20211018_0556.py
  2. 2
      backend/api/models.py
  3. 1
      backend/api/serializers.py
  4. 25
      backend/api/tests/api/test_project.py

65
backend/api/migrations/0016_auto_20211018_0556.py

@ -0,0 +1,65 @@
# Generated by Django 3.2.4 on 2021-10-18 05:56
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0015_examplestate'),
]
operations = [
migrations.AlterModelOptions(
name='comment',
options={'ordering': ['created_at']},
),
migrations.AlterModelOptions(
name='example',
options={'ordering': ['created_at']},
),
migrations.AlterModelOptions(
name='label',
options={'ordering': ['created_at']},
),
migrations.AddField(
model_name='sequencelabelingproject',
name='allow_overlapping',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='sequencelabelingproject',
name='grapheme_mode',
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='autolabelingconfig',
name='label_mapping',
field=models.JSONField(blank=True, default=dict),
),
migrations.AlterField(
model_name='comment',
name='created_at',
field=models.DateTimeField(auto_now_add=True, db_index=True),
),
migrations.AlterField(
model_name='example',
name='created_at',
field=models.DateTimeField(auto_now_add=True, db_index=True),
),
migrations.AlterField(
model_name='example',
name='filename',
field=models.FileField(default='.', max_length=1024, upload_to=''),
),
migrations.AlterField(
model_name='label',
name='created_at',
field=models.DateTimeField(auto_now_add=True, db_index=True),
),
migrations.AlterField(
model_name='label',
name='text',
field=models.CharField(db_index=True, max_length=100),
),
]

2
backend/api/models.py

@ -56,6 +56,8 @@ class TextClassificationProject(Project):
class SequenceLabelingProject(Project): class SequenceLabelingProject(Project):
allow_overlapping = models.BooleanField(default=False)
grapheme_mode = models.BooleanField(default=False)
def get_annotation_class(self): def get_annotation_class(self):
return Span return Span

1
backend/api/serializers.py

@ -193,6 +193,7 @@ class SequenceLabelingProjectSerializer(ProjectSerializer):
class Meta(ProjectSerializer.Meta): class Meta(ProjectSerializer.Meta):
model = SequenceLabelingProject model = SequenceLabelingProject
fields = ProjectSerializer.Meta.fields + ('allow_overlapping', 'grapheme_mode')
class Seq2seqProjectSerializer(ProjectSerializer): class Seq2seqProjectSerializer(ProjectSerializer):

25
backend/api/tests/api/test_project.py

@ -52,6 +52,31 @@ class TestProjectCreate(CRUDMixin):
self.assert_create(expected=status.HTTP_403_FORBIDDEN) self.assert_create(expected=status.HTTP_403_FORBIDDEN)
class TestSequenceLabelingProjectCreation(CRUDMixin):
@classmethod
def setUpTestData(cls):
create_default_roles()
cls.user = make_user()
cls.url = reverse(viewname='project_list')
cls.data = {
'name': 'example',
'project_type': 'SequenceLabeling',
'description': 'example',
'guideline': 'example',
'allow_overlapping': True,
'grapheme_mode': True,
'resourcetype': 'SequenceLabelingProject'
}
def test_allows_staff_user_to_create_project(self):
self.user.is_staff = True
self.user.save()
response = self.assert_create(self.user, status.HTTP_201_CREATED)
self.assertEqual(response.data['allow_overlapping'], self.data['allow_overlapping'])
self.assertEqual(response.data['grapheme_mode'], self.data['grapheme_mode'])
class TestProjectDetailAPI(CRUDMixin): class TestProjectDetailAPI(CRUDMixin):
@classmethod @classmethod

Loading…
Cancel
Save