mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-13 16:44:56 +03:00
Bug fixes for alignment
This commit is contained in:
parent
c8ba54e052
commit
c9d314b7ba
|
@ -124,6 +124,9 @@ 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'''
|
||||||
|
if index is None:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
alignment = self._t2y[index]
|
alignment = self._t2y[index]
|
||||||
return alignment
|
return alignment
|
||||||
#if isinstance(alignment, int):
|
#if 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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user