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
8d268f96
Commit
8d268f96
authored
1 year ago
by
Solene Tarride
Committed by
Solene Tarride
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Write tests for data extraction
parent
14df962d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_extract.py
+43
-0
43 additions, 0 deletions
tests/test_extract.py
with
43 additions
and
0 deletions
tests/test_extract.py
+
43
−
0
View file @
8d268f96
...
...
@@ -22,6 +22,8 @@ from tests import FIXTURES
EXTRACTION_DATA_PATH
=
FIXTURES
/
"
extraction
"
TWO_SPACES_REGEX
=
re
.
compile
(
r
"
{2}
"
)
ENTITY_TOKEN_SPACE
=
re
.
compile
(
r
"
[ⓢ|ⓕ|ⓑ]
"
)
TWO_SPACES_LM_REGEX
=
re
.
compile
(
r
"
⎵ ⎵
"
)
# NamedTuple to mock actual database result
Entity
=
NamedTuple
(
"
Entity
"
,
offset
=
int
,
length
=
int
,
type
=
str
,
value
=
str
)
...
...
@@ -427,6 +429,47 @@ def test_extract(
expected_charset
.
update
(
tokens
)
assert
set
(
pickle
.
loads
((
output
/
"
charset.pkl
"
).
read_bytes
()))
==
expected_charset
# Check "language_corpus.txt"
expected_language_corpus
=
"""
ⓢ C a i l l e t ⎵ ⎵ ⓕ M a u r i c e ⎵ ⎵ ⓑ 2 8 . 9 . 0 6
ⓢ R e b o u l ⎵ ⎵ ⓕ J e a n ⎵ ⎵ ⓑ 3 0 . 9 . 0 2
ⓢ B a r e y r e ⎵ ⎵ ⓕ J e a n ⎵ ⎵ ⓑ 2 8 . 3 . 1 1
ⓢ R o u s s y ⎵ ⎵ ⓕ J e a n ⎵ ⎵ ⓑ 4 . 1 1 . 1 4
ⓢ M a r i n ⎵ ⎵ ⓕ M a r c e l ⎵ ⎵ ⓑ 1 0 . 8 . 0 6
ⓢ R o q u e s ⎵ ⎵ ⓕ E l o i ⎵ ⎵ ⓑ 1 1 . 1 0 . 0 4
ⓢ G i r o s ⎵ ⎵ ⓕ P a u l ⎵ ⎵ ⓑ 3 0 . 1 0 . 1 0
"""
# Transcriptions with worker version are in lowercase
if
transcription_entities_worker_version
:
expected_language_corpus
=
expected_language_corpus
.
lower
()
# If we do not load entities, remove tokens
if
not
load_entities
:
token_translations
=
{
f
"
{
token
}
"
:
""
for
token
in
tokens
}
expected_language_corpus
=
ENTITY_TOKEN_SPACE
.
sub
(
""
,
expected_language_corpus
)
# Replace double spaces with regular space
if
not
keep_spaces
:
expected_language_corpus
=
TWO_SPACES_LM_REGEX
.
sub
(
"
⎵
"
,
expected_language_corpus
)
assert
(
output
/
"
language_corpus.txt
"
).
read_text
()
==
expected_language_corpus
# Check "language_tokens.txt"
expected_language_tokens
=
[
t
if
t
!=
"
"
else
"
⎵
"
for
t
in
sorted
(
list
(
expected_charset
))
]
expected_language_tokens
.
append
(
"
◌
"
)
assert
(
output
/
"
language_tokens.txt
"
).
read_text
()
==
"
\n
"
.
join
(
expected_language_tokens
)
# Check "language_lexicon.txt"
expected_language_lexicon
=
[
f
"
{
t
}
{
t
}
"
for
t
in
expected_language_tokens
]
assert
(
output
/
"
language_lexicon.txt
"
).
read_text
()
==
"
\n
"
.
join
(
expected_language_lexicon
)
# Check cropped images
for
expected_path
in
expected_paths
:
if
expected_path
.
suffix
!=
"
.jpg
"
:
...
...
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