Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • arkindex/backend
1 result
Show changes
Commits on Source (4)
......@@ -110,8 +110,8 @@ class ElementAdmin(admin.ModelAdmin):
class TranscriptionAdmin(admin.ModelAdmin):
list_display = ('id', 'text', 'confidence', 'element', )
fields = ('id', 'text', 'confidence', 'element', )
list_display = ('id', 'text', 'confidence', 'orientation', 'element', )
fields = ('id', 'text', 'confidence', 'orientation', 'element', )
readonly_fields = ('id', )
raw_id_fields = ('element', )
......
# Generated by Django 3.2.6 on 2021-10-22 08:27
import enumfields.fields
from django.db import migrations
import arkindex.documents.models
class Migration(migrations.Migration):
dependencies = [
('documents', '0045_alter_element_rotation_angle'),
]
operations = [
migrations.AddField(
model_name='transcription',
name='orientation',
field=enumfields.fields.EnumField(default='horizontal-lr', enum=arkindex.documents.models.TextOrientation, max_length=50),
),
]
......@@ -486,6 +486,13 @@ class EntityLink(models.Model):
super().save(*args, **kwargs)
class TextOrientation(Enum):
HorizontalLeftToRight = 'horizontal-lr'
HorizontalRightToLeft = 'horizontal-rl'
VerticalRightToLeft = 'vertical-rl'
VerticalLeftToRight = 'vertical-lr'
class Transcription(models.Model):
"""
A transcription on:
......@@ -505,6 +512,7 @@ class Transcription(models.Model):
blank=True,
)
text = models.TextField()
orientation = EnumField(TextOrientation, default=TextOrientation.HorizontalLeftToRight, max_length=50)
confidence = models.FloatField(null=True, blank=True)
entities = models.ManyToManyField(
Entity,
......
......@@ -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),
......
......@@ -70,6 +70,7 @@ SELECT "documents_transcription"."id",
"documents_transcription"."element_id",
"documents_transcription"."worker_version_id",
"documents_transcription"."text",
"documents_transcription"."orientation",
"documents_transcription"."confidence"
FROM "documents_transcription"
WHERE "documents_transcription"."element_id" IN ('{page_id}'::uuid);
......