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 (2)
......@@ -55,7 +55,7 @@ http://ark.localhost:8000/api/v1/oauth/providers/gitlab/callback/
https://ark.localhost/api/v1/oauth/providers/gitlab/callback/
```
Once the application is created, GitLab will provide you with an application ID and a secret. Use the `arkindex/config.yaml` file to set them:
Once the application is created, GitLab will provide you with an application ID and a secret. Use the `arkindex/config.yml` file to set them:
```yaml
gitlab:
......
......@@ -226,7 +226,7 @@ class EntityLinkCreate(CreateAPIView):
))
class TranscriptionEntityCreate(CreateAPIView):
"""
Link an existing Entity to a given transcription with its position
Link an existing Entity to a given transcription with its position.
"""
permission_classes = (IsVerified, )
serializer_class = TranscriptionEntitySerializer
......
# Generated by Django 3.2.6 on 2021-08-09 11:34
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('dataimport', '0034_worker_run_config'),
('documents', '0041_rotation'),
]
operations = [
migrations.AddField(
model_name='transcriptionentity',
name='confidence',
field=models.FloatField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0), django.core.validators.MaxValueValidator(1)]),
),
]
......@@ -531,6 +531,8 @@ class TranscriptionEntity(models.Model):
blank=True,
)
confidence = models.FloatField(validators=[MinValueValidator(0), MaxValueValidator(1)], null=True, blank=True)
class Meta:
unique_together = (
('transcription', 'entity', 'offset', 'length', 'worker_version'),
......
......@@ -212,10 +212,11 @@ class TranscriptionEntitySerializer(serializers.ModelSerializer):
default=None,
style={'base_template': 'input.html'},
)
confidence = serializers.FloatField(min_value=0, max_value=1, default=None)
class Meta:
model = TranscriptionEntity
fields = ('entity', 'offset', 'length', 'worker_version_id')
fields = ('entity', 'offset', 'length', 'worker_version_id', 'confidence')
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
......
......@@ -82,6 +82,12 @@ class TestEntitiesAPI(FixtureAPITestCase):
'offset': 4,
'length': len(self.entity.name)
}
self.tr_entities_confidence_sample = {
'entity': str(self.entity.id),
'offset': 4,
'length': len(self.entity.name),
'confidence': 1.0
}
self.tr_entities_version_sample = {
'entity': str(self.entity.id),
'offset': 4,
......@@ -421,6 +427,34 @@ class TestEntitiesAPI(FixtureAPITestCase):
'offset': transcription_entity.offset,
'length': transcription_entity.length,
'worker_version_id': None,
'confidence': None
}
)
def test_create_transcription_entity_with_confidence(self):
self.client.force_login(self.user)
response = self.client.post(
reverse('api:transcription-entity-create', kwargs={'pk': str(self.transcription.id)}),
data=self.tr_entities_confidence_sample,
format='json'
)
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
transcription_entity = TranscriptionEntity.objects.get(
transcription=self.transcription,
entity=self.entity,
offset=self.tr_entities_confidence_sample['offset'],
length=self.tr_entities_confidence_sample['length'],
confidence=self.tr_entities_confidence_sample['confidence']
)
self.assertIsNotNone(transcription_entity)
self.assertDictEqual(
response.json(),
{
'entity': str(transcription_entity.entity.id),
'offset': transcription_entity.offset,
'length': transcription_entity.length,
'worker_version_id': None,
'confidence': transcription_entity.confidence
}
)
......@@ -492,6 +526,42 @@ class TestEntitiesAPI(FixtureAPITestCase):
{'length': ['Ensure this value is greater than or equal to 1.']}
)
def test_create_transcription_entity_wrong_high_confidence(self):
self.client.force_login(self.user)
response = self.client.post(
reverse('api:transcription-entity-create', kwargs={'pk': str(self.transcription.id)}),
data={
'entity': str(self.entity.id),
'offset': 4,
'length': 1,
'confidence': 2.0
},
format='json'
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertDictEqual(
response.json(),
{'confidence': ['Ensure this value is less than or equal to 1.']}
)
def test_create_transcription_entity_wrong_low_confidence(self):
self.client.force_login(self.user)
response = self.client.post(
reverse('api:transcription-entity-create', kwargs={'pk': str(self.transcription.id)}),
data={
'entity': str(self.entity.id),
'offset': 4,
'length': 1,
'confidence': -0.5
},
format='json'
)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertDictEqual(
response.json(),
{'confidence': ['Ensure this value is greater than or equal to 0.']}
)
def test_create_transcription_entity_different_corpus(self):
self.client.force_login(self.user)
ent = Entity.objects.create(
......@@ -578,6 +648,7 @@ class TestEntitiesAPI(FixtureAPITestCase):
'length': self.transcriptionentity.length,
'offset': self.transcriptionentity.offset,
'worker_version_id': None,
'confidence': None
}]
)
......@@ -628,6 +699,7 @@ class TestEntitiesAPI(FixtureAPITestCase):
'length': 8,
'offset': 8,
'worker_version_id': None,
'confidence': None
}]
)
......@@ -748,6 +820,7 @@ class TestEntitiesAPI(FixtureAPITestCase):
'offset': t.offset,
'length': t.length,
'worker_version_id': None,
'confidence': None
} for t in TranscriptionEntity.objects.filter(transcription=self.transcription).order_by('offset')],
'metadata': [{
'entity': {
......