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
65646a89
Commit
65646a89
authored
4 years ago
by
Eva Bardou
Browse files
Options
Downloads
Patches
Plain Diff
Add few more helpers for developers
parent
df370aa3
No related branches found
No related tags found
No related merge requests found
Pipeline
#77911
failed
4 years ago
Stage: test
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
arkindex_worker/worker.py
+97
-0
97 additions, 0 deletions
arkindex_worker/worker.py
with
97 additions
and
0 deletions
arkindex_worker/worker.py
+
97
−
0
View file @
65646a89
...
...
@@ -9,6 +9,7 @@ import uuid
from
apistar.exceptions
import
ErrorResponse
from
arkindex
import
ArkindexClient
,
options_from_env
from
arkindex_common.enums
import
EntityType
,
TranscriptionType
from
arkindex_worker
import
logger
from
arkindex_worker.models
import
Element
from
arkindex_worker.reporting
import
Reporter
...
...
@@ -202,3 +203,99 @@ class ElementsWorker(BaseWorker):
},
)
self
.
report
.
add_element
(
element
.
id
,
type
)
def
create_transcription
(
self
,
element
,
text
,
type
,
score
):
"""
Create a transcription on the given element through API
"""
assert
element
and
isinstance
(
element
,
Element
),
"
element shouldn
'
t be null and should be of type Element
"
assert
type
and
isinstance
(
type
,
str
),
"
type shouldn
'
t be null and should be of type str
"
assert
(
type
in
TranscriptionType
.
_value2member_map_
),
"
type should be an allowed transcription type
"
assert
text
and
isinstance
(
text
,
str
),
"
text shouldn
'
t be null and should be of type str
"
assert
(
score
and
isinstance
(
score
,
float
)
and
0
<=
score
<=
1
),
"
score shouldn
'
t be null and should be a float in [0..1] range
"
self
.
api_client
.
request
(
"
CreateTranscription
"
,
id
=
element
.
id
,
body
=
{
"
text
"
:
text
,
"
type
"
:
type
,
"
worker_version
"
:
self
.
worker_version_id
,
"
score
"
:
score
,
},
)
self
.
report
.
add_transcription
(
element
.
id
,
type
)
def
create_classification
(
self
,
element
,
ml_class
,
confidence
,
high_confidence
):
"""
Create a classification on the given element through API
"""
assert
element
and
isinstance
(
element
,
Element
),
"
element shouldn
'
t be null and should be of type Element
"
assert
ml_class
and
isinstance
(
ml_class
,
str
),
"
ml_class shouldn
'
t be null and should be of type str
"
assert
(
confidence
and
isinstance
(
confidence
,
float
)
and
0
<=
confidence
<=
1
),
"
confidence shouldn
'
t be null and should be a float in [0..1] range
"
assert
high_confidence
and
isinstance
(
high_confidence
,
bool
),
"
high_confidence shouldn
'
t be null and should be of type bool
"
self
.
api_client
.
request
(
"
CreateClassification
"
,
body
=
{
"
element
"
:
element
.
id
,
"
ml_class
"
:
ml_class
,
"
worker_version
"
:
self
.
worker_version_id
,
"
confidence
"
:
confidence
,
"
high_confidence
"
:
high_confidence
,
},
)
self
.
report
.
add_classification
(
element
.
id
,
ml_class
)
def
create_entity
(
self
,
name
,
type
,
corpus
,
metas
=
None
,
validated
=
None
):
"""
Create an entity on the given corpus through API
"""
assert
name
and
isinstance
(
name
,
str
),
"
name shouldn
'
t be null and should be of type str
"
assert
type
and
isinstance
(
type
,
str
),
"
type shouldn
'
t be null and should be of type str
"
assert
(
type
in
EntityType
.
_value2member_map_
),
"
type should be an allowed entity type
"
assert
corpus
and
isinstance
(
corpus
,
str
),
"
corpus shouldn
'
t be null and should be of type str
"
if
metas
:
assert
isinstance
(
metas
,
dict
),
"
metas should be of type dict
"
if
validated
:
assert
isinstance
(
validated
,
bool
),
"
validated should be of type bool
"
self
.
api_client
.
request
(
"
CreateEntity
"
,
body
=
{
"
name
"
:
name
,
"
type
"
:
type
,
"
metas
"
:
metas
,
"
validated
"
:
validated
,
"
corpus
"
:
corpus
,
"
worker_version
"
:
self
.
worker_version_id
,
},
)
# TODO: Uncomment this when Reporter add_entity() method is implemented
# self.report.add_entity(element.id, type)
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