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
efcd3266
Commit
efcd3266
authored
3 years ago
by
Erwan Rouchet
Browse files
Options
Downloads
Plain Diff
Merge branch 'no-class-name-manifests' into 'master'
remove classifications from canvas label in manifests Closes
#980
See merge request
!1646
parents
e2c27c74
0315ec2e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1646
remove classifications from canvas label in manifests
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex/documents/serializers/iiif/manifests.py
+3
-25
3 additions, 25 deletions
arkindex/documents/serializers/iiif/manifests.py
arkindex/documents/tests/test_manifest.py
+0
-22
0 additions, 22 deletions
arkindex/documents/tests/test_manifest.py
with
3 additions
and
47 deletions
arkindex/documents/serializers/iiif/manifests.py
+
3
−
25
View file @
efcd3266
from
django.conf
import
settings
from
django.db.models
import
CharField
,
F
,
OuterRef
,
Prefetch
,
Subquery
,
Value
from
django.db.models.functions
import
Ceil
,
Concat
from
django.db.models
import
Prefetch
from
rest_framework
import
serializers
from
arkindex.documents.models
import
Classification
,
Element
,
MetaData
,
MetaType
from
arkindex.documents.models
import
Element
,
MetaData
,
MetaType
from
arkindex.images.models
import
Image
from
arkindex.project.tools
import
bounding_box
,
build_absolute_url
...
...
@@ -73,9 +72,6 @@ class ElementCanvasManifestSerializer(serializers.BaseSerializer):
else
:
label
=
element
.
name
if
element
.
best_classification
:
label
=
'
{} ; {}
'
.
format
(
label
,
element
.
best_classification
)
_
,
_
,
width
,
height
=
bounding_box
(
element
.
polygon
)
return
{
...
...
@@ -164,23 +160,6 @@ class FolderManifestSerializer(serializers.Serializer):
def
get_canvases
(
self
,
element
):
assert
isinstance
(
element
,
Element
)
and
element
.
type
.
folder
# To get a single classification for each page in a element, we force Django to use a subquery;
# however this only allows fetching a single column. We circumvent this limit using some
# database functions to get both the MLClass name and the confidence at once.
# See https://docs.djangoproject.com/en/2.2/ref/models/database-functions/
# and https://docs.djangoproject.com/en/2.2/ref/models/expressions/#subquery-expressions
best_classification_subquery
=
Classification
\
.
objects
\
.
filter
(
element
=
OuterRef
(
'
pk
'
))
\
.
order_by
(
'
-confidence
'
)
\
.
values
(
label
=
Concat
(
'
ml_class__name
'
,
Value
(
'
(
'
),
Ceil
(
F
(
'
confidence
'
)
*
100
),
Value
(
'
%)
'
),
output_field
=
CharField
(),
))[:
1
]
folio_prefetch
=
Prefetch
(
'
metadatas
'
,
MetaData
.
objects
.
filter
(
name
=
'
folio
'
),
...
...
@@ -193,8 +172,7 @@ class FolderManifestSerializer(serializers.Serializer):
type__folder
=
False
,
image_id__isnull
=
False
,
polygon__isnull
=
False
,
).
annotate
(
best_classification
=
Subquery
(
best_classification_subquery
))
\
.
order_by
(
'
paths__ordering
'
)
\
).
order_by
(
'
paths__ordering
'
)
\
.
prefetch_related
(
'
image__server
'
,
folio_prefetch
)
def
get_structures
(
self
,
element
,
canvases
):
...
...
This diff is collapsed.
Click to expand it.
arkindex/documents/tests/test_manifest.py
+
0
−
22
View file @
efcd3266
...
...
@@ -4,7 +4,6 @@ from django.urls import reverse
from
rest_framework
import
status
from
tripoli
import
IIIFValidator
from
arkindex.dataimport.models
import
WorkerVersion
from
arkindex.documents.models
import
Element
,
MetaType
from
arkindex.project.tests
import
FixtureAPITestCase
...
...
@@ -126,27 +125,6 @@ class TestFolderManifestSerializer(FixtureAPITestCase):
iv
.
validate
(
manifest
)
self
.
assertTrue
(
iv
.
is_valid
)
def
test_with_classification
(
self
):
self
.
assertFalse
(
self
.
page
.
classifications
.
exists
())
worker_version
=
WorkerVersion
.
objects
.
first
()
text_class
=
self
.
corpus
.
ml_classes
.
create
(
name
=
'
text
'
)
cover_class
=
self
.
corpus
.
ml_classes
.
create
(
name
=
'
cover
'
)
self
.
page
.
classifications
.
create
(
ml_class
=
text_class
,
confidence
=
0.42
,
worker_version
=
worker_version
)
self
.
page
.
classifications
.
create
(
ml_class
=
cover_class
,
confidence
=
0.12
,
worker_version
=
worker_version
)
response
=
self
.
client
.
get
(
reverse
(
'
api:folder-manifest
'
,
kwargs
=
{
'
pk
'
:
self
.
vol
.
id
}))
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
manifest
=
response
.
json
()
self
.
assertListEqual
(
[
canvas
[
'
label
'
]
for
canvas
in
manifest
[
'
sequences
'
][
0
][
'
canvases
'
]],
[
'
1r ; text (42%)
'
,
'
1v
'
,
'
2r
'
,
]
)
@override_settings
(
ARKINDEX_FEATURES
=
{
'
search
'
:
False
})
def
test_search_disabled
(
self
):
response
=
self
.
client
.
get
(
reverse
(
'
api:folder-manifest
'
,
kwargs
=
{
'
pk
'
:
self
.
vol
.
id
}))
...
...
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