Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
DAN
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Automatic Text Recognition
DAN
Merge requests
!11
Implement extraction command
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Implement extraction command
implement-extraction-command
into
main
Overview
1
Commits
12
Pipelines
0
Changes
12
Merged
Yoann Schneider
requested to merge
implement-extraction-command
into
main
2 years ago
Overview
1
Commits
12
Pipelines
0
Changes
12
Expand
Requires
!9 (merged)
Closes
#9 (closed)
0
0
Merge request reports
Viewing commit
0afccab8
Prev
Next
Show latest version
12 files
+
513
−
256
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
12
Search (e.g. *.vue) (Ctrl+P)
Verified
0afccab8
implement extraction
· 0afccab8
Yoann Schneider
authored
2 years ago
dan/datasets/extract/arkindex_utils.py deleted
100644 → 0
+
0
−
66
Options
# -*- coding: utf-8 -*-
"""
The arkindex_utils module
======================
"""
import
errno
import
logging
import
sys
from
apistar.exceptions
import
ErrorResponse
def
retrieve_corpus
(
client
,
corpus_name
:
str
)
->
str
:
"""
Retrieve the corpus id from the corpus name.
:param client: The arkindex client.
:param corpus_name: The name of the corpus to retrieve.
:return target_corpus: The id of the retrieved corpus.
"""
for
corpus
in
client
.
request
(
"
ListCorpus
"
):
if
corpus
[
"
name
"
]
==
corpus_name
:
target_corpus
=
corpus
[
"
id
"
]
try
:
logging
.
info
(
f
"
Corpus id retrieved:
{
target_corpus
}
"
)
except
NameError
:
logging
.
error
(
f
"
Corpus
{
corpus_name
}
not found
"
)
sys
.
exit
(
errno
.
EINVAL
)
return
target_corpus
def
retrieve_subsets
(
client
,
corpus
:
str
,
parents_types
:
list
,
parents_names
:
list
)
->
list
:
"""
Retrieve the requested subsets.
:param client: The arkindex client.
:param corpus: The id of the retrieved corpus.
:param parents_types: The types of parents of the elements to retrieve.
:param parents_names: The names of parents of the elements to retrieve.
:return subsets: The retrieved subsets.
"""
subsets
=
[]
for
parent_type
in
parents_types
:
try
:
subsets
.
extend
(
client
.
request
(
"
ListElements
"
,
corpus
=
corpus
,
type
=
parent_type
)[
"
results
"
]
)
except
ErrorResponse
as
e
:
logging
.
error
(
f
"
{
e
.
content
}
:
{
parent_type
}
"
)
sys
.
exit
(
errno
.
EINVAL
)
# Retrieve subsets with name in parents-names. If no parents-names given, keep all subsets.
if
parents_names
is
not
None
:
logging
.
info
(
f
"
Retrieving
{
parents_names
}
subset(s)
"
)
subsets
=
[
subset
for
subset
in
subsets
if
subset
[
"
name
"
]
in
parents_names
]
else
:
logging
.
info
(
"
Retrieving all subsets
"
)
if
len
(
subsets
)
==
0
:
logging
.
info
(
"
No subset found
"
)
return
subsets
Loading