Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
42b51a4e
Commit
42b51a4e
authored
3 years ago
by
ml bonhomme
Browse files
Options
Downloads
Patches
Plain Diff
orientation in bulk element transcriptions endpoint
parent
5fc53d1e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/documents/api/ml.py
+1
-0
1 addition, 0 deletions
arkindex/documents/api/ml.py
arkindex/documents/tests/test_bulk_element_transcriptions.py
+73
-10
73 additions, 10 deletions
arkindex/documents/tests/test_bulk_element_transcriptions.py
with
74 additions
and
10 deletions
arkindex/documents/api/ml.py
+
1
−
0
View file @
42b51a4e
...
...
@@ -266,6 +266,7 @@ class ElementTranscriptionsBulk(CreateAPIView):
worker_version
=
worker_version
,
text
=
annotation
[
'
text
'
],
confidence
=
annotation
[
'
confidence
'
],
orientation
=
annotation
[
'
orientation
'
]
)
annotation
[
'
id
'
]
=
transcription
.
id
transcriptions
.
append
(
transcription
)
...
...
This diff is collapsed.
Click to expand it.
arkindex/documents/tests/test_bulk_element_transcriptions.py
+
73
−
10
View file @
42b51a4e
...
...
@@ -6,7 +6,7 @@ from django.urls import reverse
from
rest_framework
import
status
from
arkindex.dataimport.models
import
WorkerVersion
from
arkindex.documents.models
import
Corpus
,
Element
,
Transcription
from
arkindex.documents.models
import
Corpus
,
Element
,
TextOrientation
,
Transcription
from
arkindex.project.tests
import
FixtureAPITestCase
...
...
@@ -39,8 +39,8 @@ class TestBulkElementTranscriptions(FixtureAPITestCase):
existing_element_ids
=
list
(
Element
.
objects
.
get_descending
(
self
.
page
.
id
).
values_list
(
'
id
'
,
flat
=
True
))
transcriptions
=
[
([[
13
,
37
],
[
133
,
37
],
[
133
,
137
],
[
13
,
137
],
[
13
,
37
]],
'
Hello world !
'
,
0.1337
),
([[
24
,
42
],
[
64
,
42
],
[
64
,
142
],
[
24
,
142
],
[
24
,
42
]],
'
I <3 JavaScript
'
,
0.42
),
([[
13
,
37
],
[
133
,
37
],
[
133
,
137
],
[
13
,
137
],
[
13
,
37
]],
'
Hello world !
'
,
0.1337
,
'
vertical-lr
'
),
([[
24
,
42
],
[
64
,
42
],
[
64
,
142
],
[
24
,
142
],
[
24
,
42
]],
'
I <3 JavaScript
'
,
0.42
,
'
horizontal-lr
'
),
]
data
=
{
'
element_type
'
:
'
text_line
'
,
...
...
@@ -48,8 +48,9 @@ class TestBulkElementTranscriptions(FixtureAPITestCase):
'
transcriptions
'
:
[{
'
polygon
'
:
poly
,
'
text
'
:
text
,
'
confidence
'
:
confidence
}
for
poly
,
text
,
confidence
in
transcriptions
]
'
confidence
'
:
confidence
,
'
orientation
'
:
orientation
}
for
poly
,
text
,
confidence
,
orientation
in
transcriptions
]
}
self
.
client
.
force_login
(
self
.
user
)
response
=
self
.
client
.
post
(
...
...
@@ -73,10 +74,10 @@ class TestBulkElementTranscriptions(FixtureAPITestCase):
]
)
self
.
assertCountEqual
(
created_elts
.
values_list
(
'
transcriptions__text
'
,
'
transcriptions__worker_version
'
),
created_elts
.
values_list
(
'
transcriptions__text
'
,
'
transcriptions__worker_version
'
,
'
transcriptions__orientation
'
),
[
(
'
Hello world !
'
,
self
.
worker_version
.
id
),
(
'
I <3 JavaScript
'
,
self
.
worker_version
.
id
)
(
'
Hello world !
'
,
self
.
worker_version
.
id
,
TextOrientation
.
VerticalLeftToRight
),
(
'
I <3 JavaScript
'
,
self
.
worker_version
.
id
,
TextOrientation
.
HorizontalLeftToRight
)
]
)
...
...
@@ -354,7 +355,7 @@ class TestBulkElementTranscriptions(FixtureAPITestCase):
second_elt
=
created_elts
.
get
(
transcriptions__text
=
'
stock
'
)
first_tr
=
Transcription
.
objects
.
get
(
text
=
"
stuck
"
)
second_tr
=
Transcription
.
objects
.
get
(
text
=
"
stock
"
)
th
r
id_td
=
Transcription
.
objects
.
get
(
text
=
"
stack
"
)
thi
r
d_td
=
Transcription
.
objects
.
get
(
text
=
"
stack
"
)
self
.
assertListEqual
(
response
.
json
(),
[{
'
id
'
:
str
(
first_tr
.
id
),
'
element_id
'
:
str
(
first_elt
.
id
),
...
...
@@ -364,7 +365,7 @@ class TestBulkElementTranscriptions(FixtureAPITestCase):
'
element_id
'
:
str
(
second_elt
.
id
),
'
created
'
:
True
},
{
'
id
'
:
str
(
th
r
id_td
.
id
),
'
id
'
:
str
(
thi
r
d_td
.
id
),
'
element_id
'
:
str
(
self
.
line
.
id
),
'
created
'
:
False
}])
...
...
@@ -432,3 +433,65 @@ class TestBulkElementTranscriptions(FixtureAPITestCase):
(
'
I <3 JavaScript
'
,
self
.
worker_version
.
id
)
]
)
def
test_bulk_transcriptions_default_orientation
(
self
):
"""
No text orientation set > default (horizontal-lr) value
"""
existing_element_ids
=
list
(
Element
.
objects
.
get_descending
(
self
.
page
.
id
).
values_list
(
'
id
'
,
flat
=
True
))
transcriptions
=
[
([[
13
,
37
],
[
133
,
37
],
[
133
,
137
],
[
13
,
137
],
[
13
,
37
]],
'
Hello world !
'
,
0.1337
),
([[
24
,
42
],
[
64
,
42
],
[
64
,
142
],
[
24
,
142
],
[
24
,
42
]],
'
I <3 JavaScript
'
,
0.42
),
]
data
=
{
'
element_type
'
:
'
text_line
'
,
'
worker_version
'
:
str
(
self
.
worker_version
.
id
),
'
transcriptions
'
:
[{
'
polygon
'
:
poly
,
'
text
'
:
text
,
'
confidence
'
:
confidence
,
}
for
poly
,
text
,
confidence
in
transcriptions
]
}
self
.
client
.
force_login
(
self
.
user
)
response
=
self
.
client
.
post
(
reverse
(
'
api:element-transcriptions-bulk
'
,
kwargs
=
{
'
pk
'
:
self
.
page
.
id
}),
format
=
'
json
'
,
data
=
data
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
created_elts
=
Element
.
objects
.
get_descending
(
self
.
page
.
id
).
exclude
(
id__in
=
existing_element_ids
)
self
.
assertCountEqual
(
created_elts
.
values_list
(
'
transcriptions__orientation
'
),
[(
TextOrientation
.
HorizontalLeftToRight
,),
(
TextOrientation
.
HorizontalLeftToRight
,)]
)
def
test_bulk_transcriptions_invalid_orientation
(
self
):
"""
Specifying an invalid text orientation throws an error
"""
transcriptions
=
[
([[
13
,
37
],
[
133
,
37
],
[
133
,
137
],
[
13
,
137
],
[
13
,
37
]],
'
Hello world !
'
,
0.1337
,
'
wiggly
'
),
([[
24
,
42
],
[
64
,
42
],
[
64
,
142
],
[
24
,
142
],
[
24
,
42
]],
'
I <3 JavaScript
'
,
0.42
,
'
timey-wimey
'
),
]
data
=
{
'
element_type
'
:
'
text_line
'
,
'
worker_version
'
:
str
(
self
.
worker_version
.
id
),
'
transcriptions
'
:
[{
'
polygon
'
:
poly
,
'
text
'
:
text
,
'
confidence
'
:
confidence
,
'
orientation
'
:
orientation
,
}
for
poly
,
text
,
confidence
,
orientation
in
transcriptions
]
}
self
.
client
.
force_login
(
self
.
user
)
response
=
self
.
client
.
post
(
reverse
(
'
api:element-transcriptions-bulk
'
,
kwargs
=
{
'
pk
'
:
self
.
page
.
id
}),
format
=
'
json
'
,
data
=
data
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
self
.
assertEqual
(
response
.
json
(),
{
'
transcriptions
'
:
[
{
'
orientation
'
:
[
'
Value is not of type TextOrientation
'
]},
{
'
orientation
'
:
[
'
Value is not of type TextOrientation
'
]}
]}
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment