Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Generic Training Dataset
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
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
Arkindex
Workers
Generic Training Dataset
Merge requests
!2
Implement worker
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Implement worker
implem
into
main
Overview
80
Commits
25
Pipelines
1
Changes
5
Merged
Yoann Schneider
requested to merge
implem
into
main
1 year ago
Overview
80
Commits
25
Pipelines
1
Changes
5
Expand
Closes
#2 (closed)
0
0
Merge request reports
Viewing commit
ec6c64fa
Prev
Next
Show latest version
5 files
+
310
−
13
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
Verified
ec6c64fa
first working version
· ec6c64fa
Yoann Schneider
authored
1 year ago
worker_generic_training_dataset/db.py
0 → 100644
+
89
−
0
Options
# -*- coding: utf-8 -*-
from
typing
import
NamedTuple
from
arkindex_export
import
Classification
from
arkindex_export.models
import
(
Element
,
Entity
,
EntityType
,
Transcription
,
TranscriptionEntity
,
)
from
arkindex_worker.cache
import
(
CachedElement
,
CachedEntity
,
CachedTranscription
,
CachedTranscriptionEntity
,
)
DEFAULT_TRANSCRIPTION_ORIENTATION
=
"
horizontal-lr
"
def
retrieve_element
(
element_id
:
str
):
return
Element
.
get_by_id
(
element_id
)
def
list_classifications
(
element
:
Element
):
query
=
Classification
.
select
().
where
(
Classification
.
element
==
element
)
return
query
def
parse_transcription
(
transcription
:
NamedTuple
,
element
:
CachedElement
):
return
CachedTranscription
(
id
=
transcription
.
id
,
element
=
element
,
text
=
transcription
.
text
,
confidence
=
transcription
.
confidence
,
orientation
=
DEFAULT_TRANSCRIPTION_ORIENTATION
,
worker_version_id
=
transcription
.
worker_version
.
id
if
transcription
.
worker_version
else
None
,
)
def
list_transcriptions
(
element
:
CachedElement
):
query
=
Transcription
.
select
().
where
(
Transcription
.
element_id
==
element
.
id
)
return
[
parse_transcription
(
x
,
element
)
for
x
in
query
]
def
parse_entities
(
data
:
NamedTuple
,
transcription
:
CachedTranscription
):
entity
=
CachedEntity
(
id
=
data
.
entity_id
,
type
=
data
.
type
,
name
=
data
.
name
,
validated
=
data
.
validated
,
metas
=
data
.
metas
,
)
return
entity
,
CachedTranscriptionEntity
(
id
=
data
.
transcription_entity_id
,
transcription
=
transcription
,
entity
=
entity
,
offset
=
data
.
offset
,
length
=
data
.
length
,
confidence
=
data
.
confidence
,
)
def
retrieve_entities
(
transcription
:
CachedTranscription
):
query
=
(
TranscriptionEntity
.
select
(
TranscriptionEntity
.
id
.
alias
(
"
transcription_entity_id
"
),
TranscriptionEntity
.
length
.
alias
(
"
length
"
),
TranscriptionEntity
.
offset
.
alias
(
"
offset
"
),
TranscriptionEntity
.
confidence
.
alias
(
"
confidence
"
),
Entity
.
id
.
alias
(
"
entity_id
"
),
EntityType
.
name
.
alias
(
"
type
"
),
Entity
.
name
,
Entity
.
validated
,
Entity
.
metas
,
)
.
where
(
TranscriptionEntity
.
transcription_id
==
transcription
.
id
)
.
join
(
Entity
,
on
=
TranscriptionEntity
.
entity
)
.
join
(
EntityType
,
on
=
Entity
.
type
)
)
return
zip
(
*
[
parse_entities
(
entity_data
,
transcription
)
for
entity_data
in
query
.
namedtuples
()
]
)
Loading