Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F80575598
test_fix_old_data.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, Sep 1, 11:35
Size
3 KB
Mime Type
text/x-python
Expires
Tue, Sep 3, 11:35 (2 d)
Engine
blob
Format
Raw Data
Handle
20400124
Attached To
rNIETZSCHEPYTHON nietzsche-python
test_fix_old_data.py
View Options
import
lxml.etree
as
ET
from
os
import
sep
,
path
,
remove
from
os.path
import
isdir
,
isfile
,
dirname
,
basename
import
shutil
import
sys
import
tempfile
import
unittest
import
warnings
import
fix_old_data
sys
.
path
.
append
(
'svgscripts'
)
from
datatypes.faksimile
import
FaksimilePage
from
datatypes.mark_foreign_hands
import
MarkForeignHands
from
datatypes.matrix
import
Matrix
from
datatypes.page
import
Page
from
datatypes.path
import
Path
from
datatypes.positional_word_part
import
PositionalWordPart
from
datatypes.text_connection_mark
import
TextConnectionMark
from
datatypes.transkriptionField
import
TranskriptionField
from
datatypes.word
import
Word
from
datatypes.word_position
import
WordPosition
from
process_words_post_merging
import
MERGED_DIR
class
TestFixFaksimile
(
unittest
.
TestCase
):
def
setUp
(
self
):
fix_old_data
.
UNITTESTING
=
True
DATADIR
=
path
.
dirname
(
__file__
)
+
sep
+
'test_data'
self
.
xml_file
=
DATADIR
+
sep
+
'N_VII_1_page138.xml'
self
.
fix_transkription_positions
=
DATADIR
+
sep
+
'Mp_XIV_page419a.xml'
def
test_convert_old_matrix
(
self
):
page
=
Page
(
self
.
xml_file
)
xmin
=
28.346
ymin
=
49.921
tp
=
page
.
words
[
63
]
.
transkription_positions
[
0
]
matrix
,
x
,
y
=
fix_old_data
.
convert_old_matrix
(
tp
,
xmin
,
ymin
)
#print(matrix.toString(), x, y)
def
test_fix_faksimile
(
self
):
page
=
Page
(
self
.
xml_file
)
fp
=
page
.
words
[
0
]
.
faksimile_positions
[
0
]
left
=
fp
.
left
top
=
fp
.
top
self
.
assertEqual
(
fix_old_data
.
fix_faksimile_positions
(
page
),
True
)
self
.
assertEqual
(
fp
.
left
,
left
+
page
.
text_field
.
xmin
)
self
.
assertEqual
(
fp
.
top
,
top
+
page
.
text_field
.
ymin
)
def
test_fix_faksimile_line_position
(
self
):
page
=
Page
(
self
.
xml_file
)
fix_old_data
.
fix_faksimile_line_position
(
page
)
for
line_number
in
page
.
line_numbers
:
#print(line_number.id)
self
.
assertTrue
(
line_number
.
faksimile_inner_top
<
line_number
.
faksimile_inner_bottom
)
@unittest.skip
(
'already tested, local file'
)
def
test_fix_transkription_positions
(
self
):
page
=
Page
(
'xml/Mp_XV_page74v.xml'
)
pwp
=
page
.
page_tree
.
xpath
(
'//word-part'
)[
0
]
left
=
float
(
pwp
.
get
(
'left'
))
fix_old_data
.
fix_transkription_positions
(
page
)
self
.
assertEqual
(
float
(
pwp
.
get
(
'left'
)),
left
+
page
.
svg_image
.
text_field
.
left
)
@unittest.skip
(
'already tested, local file'
)
def
test_fix_graphical_svg_file
(
self
):
fix_old_data
.
fix_graphical_svg_file
(
Page
(
'xml/Mp_XIV_page418.xml'
))
@unittest.skip
(
'already tested, local file'
)
def
test_get_words
(
self
):
page
=
Page
(
'xml/Mp_XIV_page418.xml'
)
print
([
word
.
text
for
word
in
page
.
words
if
word
.
id
==
300
])
words
=
fix_old_data
.
_get_words_from_response
(
'300-310'
,
page
.
words
)
print
(
words
)
def
test_fix_tp_of_word
(
self
):
page
=
Page
(
self
.
fix_transkription_positions
)
old_left
=
page
.
words
[
0
]
.
transkription_positions
[
0
]
.
left
old_top
=
page
.
words
[
0
]
.
transkription_positions
[
0
]
.
top
fix_old_data
.
fix_transkription_positions
(
page
)
self
.
assertTrue
(
page
.
svg_image
.
text_field
is
not
None
)
self
.
assertEqual
(
page
.
words
[
0
]
.
transkription_positions
[
0
]
.
left
,
old_left
+
page
.
svg_image
.
text_field
.
left
)
self
.
assertEqual
(
page
.
words
[
0
]
.
transkription_positions
[
0
]
.
top
,
old_top
+
page
.
svg_image
.
text_field
.
top
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Event Timeline
Log In to Comment