Page MenuHomec4science

word_position.py
No OneTemporary

File Metadata

Created
Thu, May 2, 19:36

word_position.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
""" This class can be used to represent a 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 .matrix import Matrix
from .positional_object import PositionalObject
from .writing_process import WritingProcess
class WordPosition(PositionalObject):
"""
This class represents a word position.
Args:
id (int): word id
matrix (datatypes.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
tag (str) location of the word position: 'WordPosition.TRANSKRIPTION' (default) or 'WordPosition.FAKSIMILE'
"""
TRANSKRIPTION = 'transkription-position'
FAKSIMILE = 'faksimile-position'
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, tag=TRANSKRIPTION):
super(WordPosition, self).__init__(id=id, node=node, height=height, width=width, x=x, y=y, matrix=matrix, tag=tag)
self.intKeys.append('writing_process_id')
self.writing_process_id = -1
self.text = text
if node is not None:
self.writing_process_id = int(node.get('writing-process-id'))\
if bool(node.get('writing-process-id')) else -1
@classmethod
def copy_list_of_cls(cls, word_positions):
"""Return a copy of word_positions.
"""
return [ cls(id=wp.id, height=wp.height, width=wp.width, x=wp.left, y=wp.top, matrix=wp.transform)\
for wp in word_positions ]
@classmethod
def get_semantic_dictionary(cls):
""" Creates a semantic dictionary as specified by SemanticClass.
"""
dictionary = super(WordPosition,cls).get_semantic_dictionary()
"""
dictionary['properties'].update({'writing_process_id':\
{ 'class': WritingProcess, 'cardinality': 1, 'cardinality_restriction': 'cardinality',\
'name': '{}BelongsTo{}'.format(WordPosition.__name__, WritingProcess.__name__),\
'label': "connects a {} with a stage in Nietzsche's process of writing".format(WordPosition.__name__),\
'xpath': '{}/@writing-process-id'.format(cls.XML_TAG)}})
"""
return dictionary
def isOnTranskription(self):
"""Returns whether position is on transkription.
"""
return self.tag == self.TRANSKRIPTION
def isOnFaksimile(self):
"""Returns whether position is on transkription.
"""
return self.tag == self.FAKSIMILE

Event Timeline