mirror of https://github.com/explosion/spaCy.git
Allow Example to align whitespace annotation (#10189)
Remove exception for whitespace tokens in `Example.get_aligned` so that annotation on whitespace tokens is aligned in the same way as for non-whitespace tokens.
This commit is contained in:
parent
2abd380f2d
commit
fef896ce49
|
@ -421,3 +421,13 @@ def test_Example_missing_heads():
|
||||||
# Ensure that the missing head doesn't create an artificial new sentence start
|
# Ensure that the missing head doesn't create an artificial new sentence start
|
||||||
expected = [True, False, False, False, False, False]
|
expected = [True, False, False, False, False, False]
|
||||||
assert example.get_aligned_sent_starts() == expected
|
assert example.get_aligned_sent_starts() == expected
|
||||||
|
|
||||||
|
|
||||||
|
def test_Example_aligned_whitespace(en_vocab):
|
||||||
|
words = ["a", " ", "b"]
|
||||||
|
tags = ["A", "SPACE", "B"]
|
||||||
|
predicted = Doc(en_vocab, words=words)
|
||||||
|
reference = Doc(en_vocab, words=words, tags=tags)
|
||||||
|
|
||||||
|
example = Example(predicted, reference)
|
||||||
|
assert example.get_aligned("TAG", as_string=True) == tags
|
||||||
|
|
|
@ -159,9 +159,6 @@ cdef class Example:
|
||||||
gold_values = self.reference.to_array([field])
|
gold_values = self.reference.to_array([field])
|
||||||
output = [None] * len(self.predicted)
|
output = [None] * len(self.predicted)
|
||||||
for token in self.predicted:
|
for token in self.predicted:
|
||||||
if token.is_space:
|
|
||||||
output[token.i] = None
|
|
||||||
else:
|
|
||||||
values = gold_values[align[token.i].dataXd]
|
values = gold_values[align[token.i].dataXd]
|
||||||
values = values.ravel()
|
values = values.ravel()
|
||||||
if len(values) == 0:
|
if len(values) == 0:
|
||||||
|
|
Loading…
Reference in New Issue