Skip to content
Snippets Groups Projects
Commit d793a487 authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Merge branch 'create-text-orientation' into 'master'

Support text orientation in CreateTranscription

See merge request !1522
parents 0f00c46b 9e52b9d6
No related branches found
No related tags found
1 merge request!1522Support text orientation in CreateTranscription
......@@ -14,6 +14,7 @@ from arkindex.documents.models import (
Element,
ElementType,
MLClass,
TextOrientation,
Transcription,
)
from arkindex.documents.serializers.light import ElementZoneSerializer
......@@ -218,6 +219,7 @@ class TranscriptionSerializer(serializers.ModelSerializer):
read_only=True,
help_text='This field is deprecated; please use the `confidence` field instead.',
)
orientation = EnumField(TextOrientation)
class Meta:
model = Transcription
......@@ -227,6 +229,7 @@ class TranscriptionSerializer(serializers.ModelSerializer):
'text',
'score',
'confidence',
'orientation',
'worker_version_id',
)
......@@ -268,10 +271,11 @@ class TranscriptionCreateSerializer(serializers.ModelSerializer):
max_value=1,
required=False,
)
orientation = EnumField(TextOrientation, default=TextOrientation.HorizontalLeftToRight, required=False)
class Meta:
model = Transcription
fields = ('text', 'worker_version', 'score', 'confidence')
fields = ('text', 'worker_version', 'score', 'confidence', 'orientation')
def validate(self, data):
data = super().validate(data)
......
......@@ -5,7 +5,7 @@ from django.urls import reverse
from rest_framework import status
from arkindex.dataimport.models import WorkerVersion
from arkindex.documents.models import Corpus, Transcription
from arkindex.documents.models import Corpus, TextOrientation, Transcription
from arkindex.project.tests import FixtureAPITestCase
from arkindex.users.models import Role, User
......@@ -73,6 +73,7 @@ class TestTranscriptionCreate(FixtureAPITestCase):
'confidence': None,
'score': None,
'text': 'A perfect day in a perfect place',
'orientation': TextOrientation.HorizontalLeftToRight.value,
'worker_version_id': None,
})
......@@ -101,6 +102,41 @@ class TestTranscriptionCreate(FixtureAPITestCase):
2
)
def test_create_transcription_with_orientation(self):
"""
Check that a transcription is created with the specified orientation
"""
self.client.force_login(self.user)
response = self.client.post(
reverse('api:transcription-create', kwargs={'pk': self.line.id}),
format='json',
data={'text': 'A perfect day in a perfect place', 'orientation': 'vertical-lr'}
)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
tr = Transcription.objects.get(text='A perfect day in a perfect place')
self.assertDictEqual(response.json(), {
'id': str(tr.id),
'confidence': None,
'score': None,
'text': 'A perfect day in a perfect place',
'orientation': 'vertical-lr',
'worker_version_id': None,
})
new_ts = Transcription.objects.get(text='A perfect day in a perfect place')
self.assertEqual(new_ts.orientation, TextOrientation.VerticalLeftToRight)
def test_create_transcription_invalid_orientation(self):
"""
Specifying an invalid text-orientation causes an error
"""
self.client.force_login(self.user)
response = self.client.post(
reverse('api:transcription-create', kwargs={'pk': self.line.id}),
format='json',
data={'text': 'A perfect day in a perfect place', 'orientation': 'wiggly'}
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
@override_settings(ARKINDEX_FEATURES={'search': False})
def test_create_transcription_no_search(self):
self.client.force_login(self.user)
......@@ -151,6 +187,7 @@ class TestTranscriptionCreate(FixtureAPITestCase):
'confidence': .42,
'score': .42,
'text': 'NEKUDOTAYIM',
'orientation': TextOrientation.HorizontalLeftToRight.value,
'worker_version_id': str(self.worker_version.id),
})
......@@ -176,6 +213,7 @@ class TestTranscriptionCreate(FixtureAPITestCase):
'confidence': .42,
'score': .42,
'text': 'NEKUDOTAYIM',
'orientation': TextOrientation.HorizontalLeftToRight.value,
'worker_version_id': str(self.worker_version.id),
})
......
......@@ -3,7 +3,7 @@ from uuid import uuid4
from django.urls import reverse
from rest_framework import status
from arkindex.documents.models import Corpus, Element, EntityType, Transcription
from arkindex.documents.models import Corpus, Element, EntityType, TextOrientation, Transcription
from arkindex.project.tests import FixtureAPITestCase
from arkindex.users.models import Role, User
......@@ -53,6 +53,7 @@ class TestEditTranscription(FixtureAPITestCase):
'confidence': None,
'score': None,
'text': 'A manual transcription',
'orientation': TextOrientation.HorizontalLeftToRight.value,
'worker_version_id': None,
})
......@@ -144,6 +145,7 @@ class TestEditTranscription(FixtureAPITestCase):
'confidence': None,
'score': None,
'text': 'a knight was living lonely',
'orientation': TextOrientation.HorizontalLeftToRight.value,
'worker_version_id': None,
})
......
......@@ -2,7 +2,7 @@ from django.urls import reverse
from rest_framework import status
from arkindex.dataimport.models import WorkerVersion
from arkindex.documents.models import Corpus
from arkindex.documents.models import Corpus, TextOrientation
from arkindex.project.tests import FixtureAPITestCase
from arkindex.users.models import User
......@@ -52,6 +52,7 @@ class TestTranscriptions(FixtureAPITestCase):
'id': str(tr1.id),
'text': 'Lorem ipsum dolor sit amet',
'confidence': 1.0,
'orientation': TextOrientation.HorizontalLeftToRight.value,
'score': 1.0,
'worker_version_id': str(self.worker_version_1.id),
'element': None,
......@@ -60,6 +61,7 @@ class TestTranscriptions(FixtureAPITestCase):
'id': str(tr2.id),
'text': 'something',
'confidence': 0.369,
'orientation': TextOrientation.HorizontalLeftToRight.value,
'score': 0.369,
'worker_version_id': str(self.worker_version_2.id),
'element': None,
......@@ -129,6 +131,7 @@ class TestTranscriptions(FixtureAPITestCase):
'text': 'something',
'score': 0.369,
'confidence': 0.369,
'orientation': TextOrientation.HorizontalLeftToRight.value,
'worker_version_id': str(self.worker_version_2.id),
'element': {
'id': str(self.page.id),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment