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
Commits
6be3dcb0
Commit
6be3dcb0
authored
1 year ago
by
Yoann Schneider
Browse files
Options
Downloads
Plain Diff
Merge branch 'extract-page-without-entities' into 'main'
Allow extracting elements holding transcriptions without entities Closes
#254
See merge request
!348
parents
2e719c9e
4f880822
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!348
Allow extracting elements holding transcriptions without entities
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
dan/datasets/extract/arkindex.py
+5
-1
5 additions, 1 deletion
dan/datasets/extract/arkindex.py
tests/test_extract.py
+26
-0
26 additions, 0 deletions
tests/test_extract.py
with
31 additions
and
1 deletion
dan/datasets/extract/arkindex.py
+
5
−
1
View file @
6be3dcb0
...
@@ -106,9 +106,10 @@ class ArkindexExtractor:
...
@@ -106,9 +106,10 @@ class ArkindexExtractor:
raise
NoTranscriptionError
(
element
.
id
)
raise
NoTranscriptionError
(
element
.
id
)
transcription
=
random
.
choice
(
transcriptions
)
transcription
=
random
.
choice
(
transcriptions
)
stripped_text
=
transcription
.
text
.
strip
()
if
not
self
.
tokens
:
if
not
self
.
tokens
:
return
transcription
.
text
.
strip
()
return
stripped_text
entities
=
get_transcription_entities
(
entities
=
get_transcription_entities
(
transcription
.
id
,
transcription
.
id
,
...
@@ -116,6 +117,9 @@ class ArkindexExtractor:
...
@@ -116,6 +117,9 @@ class ArkindexExtractor:
supported_types
=
list
(
self
.
tokens
),
supported_types
=
list
(
self
.
tokens
),
)
)
if
not
entities
.
count
():
return
stripped_text
return
self
.
translate
(
return
self
.
translate
(
entities_to_xml
(
entities_to_xml
(
transcription
.
text
,
entities
,
entity_separators
=
self
.
entity_separators
transcription
.
text
,
entities
,
entity_separators
=
self
.
entity_separators
...
...
This diff is collapsed.
Click to expand it.
tests/test_extract.py
+
26
−
0
View file @
6be3dcb0
...
@@ -425,6 +425,32 @@ def test_empty_transcription(allow_empty, mock_database):
...
@@ -425,6 +425,32 @@ def test_empty_transcription(allow_empty, mock_database):
extractor
.
extract_transcription
(
element_no_transcription
)
extractor
.
extract_transcription
(
element_no_transcription
)
@pytest.mark.parametrize
(
"
tokens
"
,
(
None
,
EXTRACTION_DATA_PATH
/
"
tokens.yml
"
))
def
test_extract_transcription_no_translation
(
mock_database
,
tokens
):
extractor
=
ArkindexExtractor
(
element_type
=
[
"
text_line
"
],
entity_separators
=
None
,
tokens
=
tokens
,
)
element
=
Element
.
get_by_id
(
"
test-page_1-line_1
"
)
# Deleting one of the two transcriptions from the element
Transcription
.
get
(
Transcription
.
element
==
element
,
Transcription
.
worker_version_id
==
"
worker_version_id
"
,
).
delete_instance
(
recursive
=
True
)
# Deleting all entities on the element remaining transcription while leaving the transcription intact
if
tokens
:
TranscriptionEntity
.
delete
().
where
(
TranscriptionEntity
.
transcription
==
Transcription
.
select
().
where
(
Transcription
.
element
==
element
).
get
()
).
execute
()
# Early return with only the element transcription text instead of a translation
assert
extractor
.
extract_transcription
(
element
)
==
"
Coupez Bouis 7.12.14
"
@pytest.mark.parametrize
(
@pytest.mark.parametrize
(
"
nestation, xml_output, separators
"
,
"
nestation, xml_output, separators
"
,
(
(
...
...
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