[EN] Privacy advice: Please tick the box below “Private profile” at the bottom of your personal settings page, or any user can see what you did when!
[DE] Diese GitLab-Instanz beachtet die DSGVO, aber 1 Einstellung können Sie nur selbst ändern: Settings → Profile → ✓Private profile (Info)

Commit a609828b authored by Benjamin Paaßen's avatar Benjamin Paaßen

removed another superfluous file

parent b10e0eea
"""
Implements alignment traces between two sequences or trees.
Copyright (C) 2019
Benjamin Paaßen
AG Machine Learning
Bielefeld University
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 <http://www.gnu.org/licenses/>.
"""
__author__ = 'Benjamin Paaßen'
__copyright__ = 'Copyright 2019, Benjamin Paaßen'
__license__ = 'GPLv3'
__version__ = '1.0.0'
__maintainer__ = 'Benjamin Paaßen'
__email__ = 'bpaassen@techfak.uni-bielefeld.de'
class Operation:
""" Models a single alignment entry with an operation name,
a left index, and a right index.
"""
def __init__(self, name, left, right):
self._name = name
self._left = left
self._right = right
def cost(self, x, y, deltas):
""" Computes the cost of the current edit operation.
Args:
x: A symbol list for the left indices.
y: A symbol list for the right indices.
deltas: A map which contains for any operation name
a function which assigns costs to symbol pairings.
If provided, the cost for any oepration is rendered as
well.
Returns: The cost assigned by deltas to this operation.
"""
if(self._left >= 0):
left = x[self._left]
else:
left = None
if(self._right >= 0):
right = y[self._right]
else:
right = None
if(self._name):
delta = deltas[self._name]
return delta(left, right)
else:
return deltas(left, right)
def render(self, x, y, deltas = None):
""" Represents an operation as a string, showing the left
and right indices in addition to the respective labels in x and y,
and in addition to the operation cost.
Args:
x: A symbol list for the left indices.
y: A symbol list for the right indices.
deltas: (optional) A map which contains for any operation name
a function which assigns costs to symbol pairings.
If provided, the cost for any oepration is rendered as
well.
Returns: A string representing this operation.
"""
op_str = ''
if(self._name):
op_str += str(self._name)
op_str += ': '
if(self._left >= 0):
left = x[self._left]
op_str += str(left) + ' [%d]' % self._left
else:
left = None
op_str += '-'
op_str += ' vs. '
if(self._right >= 0):
right = y[self._right]
op_str += str(right) + ' [%d]' % self._right
else:
right = None
op_str += '-'
if(deltas):
op_str += ': '
if(self._name):
delta = deltas[self._name]
op_str += str(delta(left, right))
else:
op_str += str(deltas(left, right))
return op_str
def __repr__(self):
op_str = ''
if(self._name):
op_str += str(self._name)
op_str += ': '
if(self._left >= 0):
op_str += str(self._left)
else:
op_str += '-'
op_str += ' vs. '
if(self._right >= 0):
op_str += str(self._right)
else:
op_str += '-'
return op_str
def __str__(self):
return self.__repr__()
def __eq__(self, other):
return isinstance(other, Operation) and self._name == other._name and self._left == other._left and self._right == other._right
class Trace(list):
""" Models a list of operations.
"""
def __init__(self):
list.__init__(self, [])
def append_operation(self, left, right, op = None):
""" Appends a new operation to the current trace.
Args:
left: the left index.
right: the right index.
op: (optional) a name for the operation.
"""
self.append(Operation(op, left, right))
def cost(self, x, y, deltas):
""" Computes the cost of this trace. This is equivalent to
the sum of the cost of all operations in this trace.
Args:
x: A symbol list for the left indices.
y: A symbol list for the right indices.
deltas: A map which contains for any operation name
a function which assigns costs to symbol pairings.
If provided, the cost for any oepration is rendered as
well.
Returns: The cost assigned by deltas to this trace.
"""
d = 0.
for op in self:
d += op.cost(x, y, deltas)
return d
def render(self, x, y, deltas = None):
""" Represents this trace as a string, showing the left
and right indices in addition to the respective labels in x and y,
and in addition to the operation cost. This is equivalent as to
calling 'render' on all operations in this trace and joining the
resulting strings with newlines.
Args:
x: A symbol list for the left indices.
y: A symbol list for the right indices.
deltas: (optional) A map which contains for any operation name
a function which assigns costs to symbol pairings.
If provided, the cost for any oepration is rendered as
well.
Returns: A string representing this trace.
"""
render = []
for op in self:
render.append(op.render(x, y, deltas))
return '\n'.join(render)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment