Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F80566705
test_footnotes.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, 10:23
Size
3 KB
Mime Type
text/x-python
Expires
Tue, Sep 3, 10:23 (2 d)
Engine
blob
Format
Raw Data
Handle
20396455
Attached To
rNIETZSCHEPYTHON nietzsche-python
test_footnotes.py
View Options
import
unittest
from
os
import
sep
,
path
,
remove
from
os.path
import
isdir
,
isfile
,
dirname
import
shutil
import
sys
import
lxml.etree
as
ET
import
warnings
import
sys
sys
.
path
.
append
(
'svgscripts'
)
import
datatypes.footnotes
from
datatypes.footnotes
import
FootnoteColumns
,
extract_footnotes
,
extract_footnotes_as_strings
,
UNITTESTING
,
DEBUG
from
datatypes.matrix
import
Matrix
from
datatypes.page
import
Page
from
datatypes.positional_word_part
import
PositionalWordPart
from
datatypes.transkriptionField
import
TranskriptionField
class
TestExtractFootnotes
(
unittest
.
TestCase
):
def
setUp
(
self
):
datatypes
.
footnotes
.
UNITTESTING
=
True
DATADIR
=
path
.
dirname
(
__file__
)
+
sep
+
'test_data'
self
.
test_footnote
=
DATADIR
+
sep
+
'W_I_8_neu_125-01.svg'
self
.
test_footnote_verso
=
DATADIR
+
sep
+
'N_VII_1_xp5_4_page5.svg'
self
.
test_footnote_recto
=
DATADIR
+
sep
+
'N_VII_1_xp5_4_page6.svg'
self
.
test_footnote_multi
=
DATADIR
+
sep
+
'N_VII_1_xp5_4_page13.svg'
self
.
test_footnote_multi_xml
=
DATADIR
+
sep
+
'N_VII_1_page013.xml'
self
.
test_categorize_footnote
=
DATADIR
+
sep
+
'N_VII_1_page006.xml'
def
test_extract_footnotes
(
self
):
footnotes
=
extract_footnotes_as_strings
(
svg_file
=
self
.
test_footnote_multi
,
contains_string
=
'Anschlußzeichen'
)
self
.
assertEqual
(
len
(
footnotes
),
4
)
page
=
Page
(
self
.
test_footnote_multi_xml
)
footnotes
=
extract_footnotes
(
page
,
svg_file
=
self
.
test_footnote_multi
,
contains_string
=
'Anschlußzeichen'
)
self
.
assertEqual
(
len
(
footnotes
),
4
)
footnotes
=
extract_footnotes
(
page
,
svg_file
=
self
.
test_footnote_multi
)
self
.
assertEqual
(
len
(
footnotes
),
7
)
"""
page = Page('xml/Mp_XV_page86r.xml')
footnotes = extract_footnotes(page)
print(footnotes)
"""
def
test_columns
(
self
):
svg_tree
=
ET
.
parse
(
self
.
test_footnote_multi
)
transkription_field
=
TranskriptionField
(
self
.
test_footnote_multi
)
nodes_in_footnote_area
=
[
item
for
item
in
filter
(
lambda
x
:
Matrix
.
IS_IN_FOOTNOTE_AREA
(
x
.
get
(
'transform'
),
transkription_field
),
\
svg_tree
.
getroot
()
.
iterfind
(
'.//text'
,
svg_tree
.
getroot
()
.
nsmap
))]
bottom_values
=
sorted
([
bottom_value
for
bottom_value
in
set
(
Matrix
(
transform_matrix_string
=
item
.
get
(
'transform'
))
.
getY
()
for
item
in
nodes_in_footnote_area
)
])
footnote_columns
=
FootnoteColumns
(
svg_tree
.
getroot
()
.
nsmap
,
nodes_in_footnote_area
,
bottom_values
,
None
)
self
.
assertEqual
(
len
(
footnote_columns
.
footnote_columns
),
2
)
footnote_columns
.
register_index
(
184
)
footnote_columns
.
append
(
'asdf'
)
self
.
assertEqual
(
len
(
footnote_columns
.
footnote_columns
[
0
]),
1
)
with
self
.
assertRaises
(
Exception
):
FootnoteColumns
(
svg_tree
.
getroot
()
.
nsmap
,
[],
bottom_values
,
None
)
"""
page = Page('xml/Mp_XV_page86r.xml')
local_file = page.source#'/home/knister0/ownCloud/myNietzscheDE/KGW-IX_12/Bd_12_XIV-XVI_Druck_als_SVG//07.svg'
svg_tree = ET.parse(local_file)
transkription_field = TranskriptionField(local_file)
nodes_in_footnote_area = [ item for item in filter(lambda x: Matrix.IS_IN_FOOTNOTE_AREA(x.get('transform'), transkription_field),\
svg_tree.getroot().iterfind('.//text', svg_tree.getroot().nsmap))]
bottom_values = sorted([ bottom_value for bottom_value in set(Matrix(transform_matrix_string=item.get('transform')).getY() for item in nodes_in_footnote_area) ])
print(len(bottom_values[1:]))
footnote_columns = FootnoteColumns(svg_tree.getroot().nsmap, nodes_in_footnote_area, bottom_values[1:], None, debug=True)
"""
if
__name__
==
"__main__"
:
unittest
.
main
()
Event Timeline
Log In to Comment