Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F65846053
faksimile_position.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
Thu, Jun 6, 14:57
Size
3 KB
Mime Type
text/x-python
Expires
Sat, Jun 8, 14:57 (2 d)
Engine
blob
Format
Raw Data
Handle
18136096
Attached To
rNIETZSCHEPYTHON nietzsche-python
faksimile_position.py
View Options
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" This class can be used to represent a faksimile word position.
"""
# Copyright (C) University of Basel 2019 {{{1
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/> 1}}}
__author__
=
"Christian Steiner"
__maintainer__
=
__author__
__copyright__
=
'University of Basel'
__email__
=
"christian.steiner@unibas.ch"
__status__
=
"Development"
__license__
=
"GPL v3"
__version__
=
"0.0.1"
from
lxml
import
etree
as
ET
from
.faksimile_image
import
FaksimileImage
from
.matrix
import
Matrix
from
.positional_object
import
PositionalObject
from
.text_field
import
TextField
from
.writing_process
import
WritingProcess
from
.word_position
import
WordPosition
class
FaksimilePosition
(
WordPosition
):
"""
This class represents the position of a Word on a TextField on a FaksimileImage.
Args:
id (int): word id
matrix (Matrix): matrix containing information about conversion.
height (float): height of word
width (float): width of word
x (float): x position of word
y (float): y position of word
faksimile_image (FaksimileImage) the faksimile image
text_field (TextField) the text_field on the faksimile_image.
"""
XML_TAG
=
'faksimile-position'
def
__init__
(
self
,
id
=
0
,
node
=
None
,
text
=
None
,
height
=
0.0
,
width
=
0.0
,
x
=
0.0
,
y
=
0.0
,
matrix
=
None
,
faksimile_image
=
None
,
text_field
=
None
):
super
(
FaksimilePosition
,
self
)
.
__init__
(
id
=
id
,
node
=
node
,
height
=
height
,
width
=
width
,
x
=
x
,
y
=
y
,
matrix
=
matrix
,
tag
=
WordPosition
.
FAKSIMILE
)
self
.
faksimile_image
=
faksimile_image
self
.
text_field
=
text_field
if
self
.
text_field
is
None
\
and
self
.
faksimile_image
is
not
None
\
and
self
.
faksimile_image
.
text_field
is
not
None
:
self
.
text_field
=
self
.
faksimile_image
.
text_field
@classmethod
def
get_semantic_dictionary
(
cls
):
""" Creates a semantic dictionary as specified by SemanticClass.
"""
dictionary
=
super
(
FaksimilePosition
,
cls
)
.
get_semantic_dictionary
()
dictionary
[
'properties'
]
.
update
(
cls
.
create_semantic_property_dictionary
(
'faksimile_image'
,
\
FaksimileImage
,
cardinality
=
1
,
name
=
'isOnFaksimileImage'
,
label
=
'faksimile position is on faksimile image'
,
\
comment
=
'Relates the faksimile position of a word to the faksimile image'
))
dictionary
[
'properties'
]
.
update
(
cls
.
create_semantic_property_dictionary
(
'text_field'
,
\
TextField
,
cardinality
=
1
,
name
=
'isOnTextField'
,
label
=
'faksimile position is on text field'
,
\
comment
=
'Relates the faksimile position of a word to its text field on a faksimile image'
))
return
dictionary
@classmethod
def
create_list_of_cls
(
cls
,
word_positions
,
faksimile_image
,
text_field
):
"""Instantiate cls from a list of WordPosition by adding FaksimileImage and TextField.
"""
return
[
cls
(
id
=
wp
.
id
,
height
=
wp
.
height
,
width
=
wp
.
width
,
x
=
wp
.
left
,
y
=
wp
.
top
,
matrix
=
wp
.
transform
,
\
faksimile_image
=
faksimile_image
,
text_field
=
text_field
)
\
for
wp
in
word_positions
]
Event Timeline
Log In to Comment