Bug fixes for alignment

This commit is contained in:
Matthew Honnibal 2018-04-02 23:50:21 +02:00
parent c8ba54e052
commit c9d314b7ba

View File

@ -124,8 +124,11 @@ class Alignment(object):
def index_to_yours(self, index): def index_to_yours(self, index):
'''Translate an index that points into their tokens to point into yours''' '''Translate an index that points into their tokens to point into yours'''
alignment = self._t2y[index] if index is None:
return alignment return None
else:
alignment = self._t2y[index]
return alignment
#if isinstance(alignment, int): #if isinstance(alignment, int):
# return alignment # return alignment
#elif len(alignment) == 1 and isinstance(alignment, int): #elif len(alignment) == 1 and isinstance(alignment, int):
@ -170,8 +173,7 @@ class Alignment(object):
[(0, 0), (0, 1), [1, 2]] [(0, 0), (0, 1), [1, 2]]
''' '''
if cand_words == gold_words: if cand_words == gold_words:
alignment = numpy.arange(len(cand_words)) return 0, list(range(len(cand_words))), list(range(len(cand_words)))
return 0, alignment, alignment, {}, {}, []
cand_words = [w.replace(' ', '') for w in cand_words] cand_words = [w.replace(' ', '') for w in cand_words]
gold_words = [w.replace(' ', '') for w in gold_words] gold_words = [w.replace(' ', '') for w in gold_words]
cost, i2j, j2i, matrix = levenshtein_align(cand_words, gold_words) cost, i2j, j2i, matrix = levenshtein_align(cand_words, gold_words)
@ -217,8 +219,9 @@ class Alignment(object):
for head_vals in heads: for head_vals in heads:
if isinstance(head_vals, int): if isinstance(head_vals, int):
head_vals = [(head_vals, 0)] head_vals = [(head_vals, 0)]
elif isinstance(head_vals, tuple): elif head_vals is None or isinstance(head_vals, tuple):
head_vals = [None] new.append(None)
continue
for head_val in head_vals: for head_val in head_vals:
if not isinstance(head_val, tuple): if not isinstance(head_val, tuple):
head_val = (head_val, 0) head_val = (head_val, 0)