Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F65461937
test_text_connection_mark.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
Mon, Jun 3, 23:33
Size
4 KB
Mime Type
text/x-python
Expires
Wed, Jun 5, 23:33 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
18075793
Attached To
rNIETZSCHEPYTHON nietzsche-python
test_text_connection_mark.py
View Options
import
unittest
from
os
import
sep
,
path
from
os.path
import
dirname
,
isdir
import
lxml.etree
as
ET
import
sys
sys
.
path
.
append
(
'svgscripts'
)
from
datatypes.matrix
import
Matrix
from
datatypes.page
import
Page
from
datatypes.reference
import
Reference
from
datatypes.transkriptionField
import
TranskriptionField
from
datatypes.transkription_position
import
TranskriptionPosition
from
datatypes.text_connection_mark
import
TextConnectionMark
from
datatypes.word
import
Word
class
TestTextConnectionMark
(
unittest
.
TestCase
):
def
setUp
(
self
):
DATADIR
=
dirname
(
__file__
)
+
sep
+
'test_data'
self
.
xml_file
=
DATADIR
+
sep
+
'N_VII_1_page008.xml'
mylist
=
{
'text'
:
'*'
,
'id'
:
'0'
,
'line-number'
:
'2'
}
self
.
node
=
ET
.
Element
(
TextConnectionMark
.
XML_TAG
,
attrib
=
mylist
)
word_position
=
TranskriptionPosition
(
x
=
0
,
y
=
1
,
height
=
10
,
width
=
10
,
matrix
=
Matrix
(
'matrix(0.94 0.342 -0.342 0.94 0 0)'
))
self
.
transkription_positions
=
[
word_position
]
word_position
.
attach_object_to_tree
(
self
.
node
)
self
.
test_tcm_xml
=
DATADIR
+
sep
+
'N_VII_1_page013.xml'
def
test_create_cls
(
self
):
text_connection_mark
=
TextConnectionMark
.
create_cls
(
self
.
node
)
self
.
assertEqual
(
text_connection_mark
.
id
,
0
)
self
.
assertEqual
(
text_connection_mark
.
transkription_positions
[
0
]
.
bottom
,
11
)
self
.
assertEqual
(
text_connection_mark
.
transkription_positions
[
0
]
.
height
,
10
)
self
.
assertEqual
(
text_connection_mark
.
transkription_positions
[
0
]
.
top
,
1
)
self
.
assertEqual
(
text_connection_mark
.
transkription_positions
[
0
]
.
left
,
0
)
self
.
assertEqual
(
text_connection_mark
.
transkription_positions
[
0
]
.
width
,
10
)
self
.
assertEqual
(
text_connection_mark
.
text
,
'*'
)
self
.
assertEqual
(
text_connection_mark
.
line_number
,
2
)
self
.
assertEqual
(
text_connection_mark
.
transkription_positions
[
0
]
.
transform
.
isRotationMatrix
(),
True
)
def
test_attach_word_to_tree
(
self
):
text_connection_mark
=
TextConnectionMark
.
create_cls
(
self
.
node
)
text_connection_mark
.
text_source
=
Reference
(
first_line
=
1
,
title
=
'ASDF'
,
page_number
=
'5c'
)
empty_tree
=
ET
.
ElementTree
(
ET
.
Element
(
'page'
))
text_connection_mark
.
attach_word_to_tree
(
empty_tree
)
#print(ET.dump(empty_tree.getroot()))
for
node
in
empty_tree
.
xpath
(
'//'
+
TextConnectionMark
.
XML_TAG
):
mark
=
TextConnectionMark
.
create_cls
(
node
)
self
.
assertEqual
(
mark
.
id
,
0
)
self
.
assertEqual
(
mark
.
transkription_positions
[
0
]
.
bottom
,
11
)
self
.
assertEqual
(
mark
.
transkription_positions
[
0
]
.
height
,
10
)
self
.
assertEqual
(
mark
.
transkription_positions
[
0
]
.
top
,
1
)
self
.
assertEqual
(
mark
.
transkription_positions
[
0
]
.
left
,
0
)
self
.
assertEqual
(
mark
.
transkription_positions
[
0
]
.
width
,
10
)
self
.
assertEqual
(
mark
.
text
,
'*'
)
self
.
assertEqual
(
mark
.
line_number
,
2
)
self
.
assertEqual
(
mark
.
transkription_positions
[
0
]
.
transform
.
isRotationMatrix
(),
True
)
self
.
assertEqual
(
mark
.
text_source
.
first_line
,
text_connection_mark
.
text_source
.
first_line
)
self
.
assertEqual
(
mark
.
text_source
.
page_number
,
text_connection_mark
.
text_source
.
page_number
)
def
test_get_semanticAndDataDict
(
self
):
dictionary
=
TextConnectionMark
.
get_semantic_dictionary
()
#print(dictionary)
def
test_find_content
(
self
):
page
=
Page
(
self
.
test_tcm_xml
)
transkription_field
=
TranskriptionField
(
page
.
source
)
svg_tree
=
ET
.
parse
(
page
.
source
)
text_connection_marks
=
[
TextConnectionMark
.
create_cls_from_word
(
word
)
for
word
in
page
.
words
if
word
.
text
==
TextConnectionMark
.
SPECIAL_CHAR_LIST
[
1
]]
TextConnectionMark
.
find_content_in_footnotes
(
text_connection_marks
,
transkription_field
,
svg_tree
,
title
=
page
.
title
,
page_number
=
page
.
number
)
self
.
assertEqual
(
len
(
text_connection_marks
),
4
)
for
tcm
in
text_connection_marks
:
self
.
assertEqual
(
tcm
.
text_source
is
not
None
,
True
)
self
.
assertEqual
(
tcm
.
text_source
.
first_line
>
-
1
,
True
)
self
.
assertEqual
(
tcm
.
text_source
.
page_number
,
'14'
)
if
__name__
==
"__main__"
:
unittest
.
main
()
Event Timeline
Log In to Comment