Skip to content
Snippets Groups Projects
Commit 3b69ea20 authored by ml bonhomme's avatar ml bonhomme :bee:
Browse files

text orientation in bulk transcription creation endpoint

parent 9ff5dcdd
No related branches found
No related tags found
No related merge requests found
......@@ -399,6 +399,7 @@ class TranscriptionBulkItemSerializer(serializers.Serializer):
help_text='This field is deprecated; please use the `confidence` field instead.'
)
confidence = serializers.FloatField(min_value=0, max_value=1, required=False)
orientation = EnumField(TextOrientation, default=TextOrientation.HorizontalLeftToRight, required=False)
def validate(self, data):
# Element retrieval and checks is done in the BulkSerializer to avoid duplicate queries
......@@ -449,6 +450,7 @@ class TranscriptionBulkSerializer(serializers.Serializer):
worker_version=validated_data['worker_version'],
element_id=transcription['element_id'],
text=transcription['text'],
orientation=transcription['orientation'],
confidence=transcription['confidence'],
)
for transcription in validated_data['transcriptions']
......
......@@ -2,6 +2,7 @@ from django.urls import reverse
from rest_framework import status
from arkindex.dataimport.models import WorkerVersion
from arkindex.documents.models import TextOrientation
from arkindex.project.tests import FixtureAPITestCase
......@@ -94,18 +95,21 @@ class TestBulkTranscriptions(FixtureAPITestCase):
"id": str(first_tr),
"element_id": str(element1.id),
"text": "Sneasel",
"orientation": TextOrientation.HorizontalLeftToRight.value,
"confidence": 0.54,
},
{
"id": str(third_tr),
"element_id": str(element2.id),
"text": "Charizard",
"orientation": TextOrientation.HorizontalLeftToRight.value,
"confidence": 0.85,
},
{
"id": str(second_tr),
"element_id": str(element1.id),
"text": "Raticate",
"orientation": TextOrientation.HorizontalLeftToRight.value,
"confidence": 0.12,
},
]
......@@ -173,3 +177,78 @@ class TestBulkTranscriptions(FixtureAPITestCase):
'Either the score or confidence field should be defined.'
]}
]})
def test_bulk_transcriptions_orientation(self):
"""
A text orientation can be specified creating transcriptions in bulk
"""
self.client.force_login(self.user)
test_element = self.corpus.elements.get(name='Volume 2, page 1r')
self.assertFalse(test_element.transcriptions.exists())
response = self.client.post(reverse('api:transcription-bulk'), {
"worker_version": str(self.worker_version.id),
"transcriptions": [
{
"element_id": str(test_element.id),
"text": "All Hail The Glow Cloud",
"orientation": TextOrientation.HorizontalRightToLeft.value,
"confidence": 0.78
},
{
"element_id": str(test_element.id),
"text": "The Glow Cloud does not need to converse with us.",
"orientation": TextOrientation.VerticalRightToLeft.value,
"score": 0.33
},
],
}, format='json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
first_tr, second_tr = test_element.transcriptions.values_list('id', flat=True)
self.assertEqual(response.json(), {
"worker_version": str(self.worker_version.id),
"transcriptions": [
{
"id": str(first_tr),
"element_id": str(test_element.id),
"text": "All Hail The Glow Cloud",
"orientation": TextOrientation.HorizontalRightToLeft.value,
"confidence": 0.78,
},
{
"id": str(second_tr),
"element_id": str(test_element.id),
"text": "The Glow Cloud does not need to converse with us.",
"orientation": TextOrientation.VerticalRightToLeft.value,
"confidence": 0.33,
},
]
})
def test_bulk_transcriptions_invalid_orientation(self):
"""
An invalid text orientation value causes an error
"""
self.client.force_login(self.user)
test_element = self.corpus.elements.get(name='Volume 2, page 1r')
self.assertFalse(test_element.transcriptions.exists())
response = self.client.post(reverse('api:transcription-bulk'), {
"worker_version": str(self.worker_version.id),
"transcriptions": [
{
"element_id": str(test_element.id),
"text": "All Hail The Glow Cloud",
"orientation": "khoshek",
"confidence": 0.78
},
{
"element_id": str(test_element.id),
"text": "The Glow Cloud does not need to converse with us.",
"orientation": TextOrientation.VerticalRightToLeft.value,
"score": 0.33
},
],
}, format='json')
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
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