Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F62589338
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
Tue, May 14, 04:48
Size
3 KB
Mime Type
text/x-python
Expires
Thu, May 16, 04:48 (2 d)
Engine
blob
Format
Raw Data
Handle
17665843
Attached To
rNIETZSCHEPYTHON nietzsche-python
text_connection_mark.py
View Options
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" This class can be used to represent a text connection mark ("Anschlusszeichen").
"""
# 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
import
sys
from
.footnotes
import
extract_footnotes_as_strings
from
.reference
import
Reference
from
.special_word
import
SpecialWord
class
TextConnectionMark
(
SpecialWord
):
"""
This class represents a text connection mark.
"""
XML_TAG
=
'text-connection-mark'
XML_SUB_TAG
=
Reference
.
XML_TAG
SPECIAL_CHAR_LIST
=
[
'*'
,
'W'
]
def
__init__
(
self
,
id
=
0
,
line_number
=-
1
,
text
=
'*'
,
transkription_positions
=
[],
faksimile_positions
=
[],
text_source
=
None
):
super
(
TextConnectionMark
,
self
)
.
__init__
(
id
=
id
,
text
=
text
,
line_number
=
line_number
,
transkription_positions
=
transkription_positions
,
\
faksimile_positions
=
faksimile_positions
)
self
.
text_source
=
text_source
def
add_content
(
self
,
node
):
"""Adds content to TextConnectionMark.
"""
self
.
text_source
=
Reference
.
create_cls
(
node
=
node
)
def
attach_word_to_tree
(
self
,
target_tree
):
"""Attaches TextConnectionMark to tree target_tree.
"""
node
=
super
(
TextConnectionMark
,
self
)
.
attach_word_to_tree
(
target_tree
)
if
self
.
text_source
is
not
None
:
self
.
text_source
.
attach_object_to_tree
(
node
)
@staticmethod
def
find_content_in_footnotes
(
list_of_text_connection_marks
,
transkription_field
,
svg_tree
,
title
=
''
,
page_number
=
''
):
"""Find content for the TextConnectionMark.
"""
footnotes
=
extract_footnotes_as_strings
(
transkription_field
=
transkription_field
,
svg_tree
=
svg_tree
,
contains_string
=
'Anschlußzeichen'
)
for
text_connection_mark
in
list_of_text_connection_marks
:
relevant_footnotes
=
[
footnote_string
for
footnote_string
in
footnotes
if
footnote_string
.
strip
()
.
startswith
(
str
(
text_connection_mark
.
line_number
)
+
':'
)
]
if
len
(
relevant_footnotes
)
>
0
:
footnote_string
=
relevant_footnotes
[
0
]
.
strip
()
line_number
=
int
(
footnote_string
.
split
(
':'
)[
0
])
is_uncertain
=
footnote_string
.
endswith
(
'?'
)
reference_string
=
footnote_string
.
replace
(
'?'
,
''
)
.
split
(
'zu'
)[
1
]
.
strip
()
text_connection_mark
.
text_source
=
Reference
.
create_cls
(
is_uncertain
=
is_uncertain
,
\
reference_string
=
reference_string
,
title
=
title
,
page_number
=
page_number
)
@classmethod
def
get_semantic_dictionary
(
cls
):
""" Creates a semantic dictionary as specified by SemanticClass.
"""
dictionary
=
super
(
TextConnectionMark
,
cls
)
.
get_semantic_dictionary
()
dictionary
[
'properties'
]
.
update
(
cls
.
create_semantic_property_dictionary
(
'text_source'
,
Reference
,
\
cardinality
=
1
,
name
=
'textConnectionMarkHasTextSource'
,
label
=
'text connection mark has a text source'
))
return
cls
.
return_dictionary_after_updating_super_classes
(
dictionary
)
@classmethod
def
get_special_char_list
(
cls
):
"""Returns a list of the chars that define this special word.
"""
return
cls
.
SPECIAL_CHAR_LIST
Event Timeline
Log In to Comment