Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Workers
Base Worker
Commits
ec3ffa89
Commit
ec3ffa89
authored
1 year ago
by
Manon Blanco
Browse files
Options
Downloads
Patches
Plain Diff
Check unicity of transcription entities
parent
db16ff3b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!424
Check unicity of transcription entities
Pipeline
#139653
passed
1 year ago
Stage: release
Changes
2
Pipelines
4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex_worker/worker/entity.py
+5
-0
5 additions, 0 deletions
arkindex_worker/worker/entity.py
tests/test_elements_worker/test_entities.py
+28
-5
28 additions, 5 deletions
tests/test_elements_worker/test_entities.py
with
33 additions
and
5 deletions
arkindex_worker/worker/entity.py
+
5
−
0
View file @
ec3ffa89
...
...
@@ -3,6 +3,7 @@
ElementsWorker methods for entities.
"""
from
operator
import
itemgetter
from
typing
import
Dict
,
List
,
Optional
,
TypedDict
,
Union
from
peewee
import
IntegrityError
...
...
@@ -273,6 +274,10 @@ class EntityMixin(object):
isinstance
(
confidence
,
float
)
and
0
<=
confidence
<=
1
),
f
"
Entity at index
{
index
}
in entities: confidence should be None or a float in [0..1] range
"
assert
len
(
entities
)
==
len
(
set
(
map
(
itemgetter
(
"
offset
"
,
"
length
"
,
"
name
"
,
"
type_id
"
),
entities
))
),
"
entities should be unique
"
if
self
.
is_read_only
:
logger
.
warning
(
"
Cannot create transcription entities in bulk as this worker is in read-only mode
"
...
...
This diff is collapsed.
Click to expand it.
tests/test_elements_worker/test_entities.py
+
28
−
5
View file @
ec3ffa89
...
...
@@ -864,11 +864,34 @@ def test_create_transcription_entities_wrong_transcription(
)
@pytest.mark.parametrize
(
"
entities
"
,
(
None
,
"
not a list of entities
"
,
1
))
def
test_create_transcription_entities_wrong_entities
(
mock_elements_worker
,
entities
):
with
pytest
.
raises
(
AssertionError
,
match
=
"
entities shouldn
'
t be null and should be of type list
"
):
@pytest.mark.parametrize
(
"
entities, error
"
,
(
(
None
,
"
entities shouldn
'
t be null and should be of type list
"
),
(
"
not a list of entities
"
,
"
entities shouldn
'
t be null and should be of type list
"
,
),
(
1
,
"
entities shouldn
'
t be null and should be of type list
"
),
(
[
{
"
name
"
:
"
A
"
,
"
type_id
"
:
"
12341234-1234-1234-1234-123412341234
"
,
"
offset
"
:
0
,
"
length
"
:
1
,
"
confidence
"
:
0.5
,
}
]
*
2
,
"
entities should be unique
"
,
),
),
)
def
test_create_transcription_entities_wrong_entities
(
mock_elements_worker
,
entities
,
error
):
with
pytest
.
raises
(
AssertionError
,
match
=
error
):
mock_elements_worker
.
create_transcription_entities
(
transcription
=
Transcription
(
id
=
"
transcription_id
"
),
entities
=
entities
,
...
...
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