mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-13 16:44:56 +03:00
Fix head alignment in GoldParse
This commit is contained in:
parent
88de8fe323
commit
9c5c940441
|
@ -451,17 +451,11 @@ cdef class GoldParse:
|
||||||
annot_tuples = (range(len(words)), words, tags, heads, deps, entities)
|
annot_tuples = (range(len(words)), words, tags, heads, deps, entities)
|
||||||
self.orig_annot = list(zip(*annot_tuples))
|
self.orig_annot = list(zip(*annot_tuples))
|
||||||
|
|
||||||
if words is not None:
|
|
||||||
self.words = self._alignment.to_yours(words)
|
self.words = self._alignment.to_yours(words)
|
||||||
if tags is not None:
|
|
||||||
self.tags = self._alignment.to_yours(tags)
|
self.tags = self._alignment.to_yours(tags)
|
||||||
if deps is not None:
|
|
||||||
self.labels = self._alignment.to_yours(deps)
|
self.labels = self._alignment.to_yours(deps)
|
||||||
if tags is not None:
|
|
||||||
self.tags = self._alignment.to_yours(tags)
|
self.tags = self._alignment.to_yours(tags)
|
||||||
if entities is not None:
|
|
||||||
self.ner = self._alignment.to_yours(entities)
|
self.ner = self._alignment.to_yours(entities)
|
||||||
if heads is not None:
|
|
||||||
for gold_i, gold_head in enumerate(heads):
|
for gold_i, gold_head in enumerate(heads):
|
||||||
if gold_head is None:
|
if gold_head is None:
|
||||||
continue
|
continue
|
||||||
|
@ -474,8 +468,12 @@ cdef class GoldParse:
|
||||||
elif isinstance(cand_i, list):
|
elif isinstance(cand_i, list):
|
||||||
for sub_i in cand_i[:-1]:
|
for sub_i in cand_i[:-1]:
|
||||||
self.heads[sub_i] = sub_i+1
|
self.heads[sub_i] = sub_i+1
|
||||||
|
if isinstance(cand_head, list):
|
||||||
|
self.heads[cand_i[-1]] = cand_head[-1]
|
||||||
|
else:
|
||||||
self.heads[cand_i[-1]] = cand_head
|
self.heads[cand_i[-1]] = cand_head
|
||||||
elif isinstance(cand_i, tuple):
|
elif isinstance(cand_i, tuple) and isinstance(cand_head, int):
|
||||||
|
# We only handle one-to-many or many-to-one, not many-to-many
|
||||||
cand_i, sub_i = cand_i
|
cand_i, sub_i = cand_i
|
||||||
if not isinstance(self.heads[cand_i], list):
|
if not isinstance(self.heads[cand_i], list):
|
||||||
self.heads[cand_i] = []
|
self.heads[cand_i] = []
|
||||||
|
@ -500,7 +498,7 @@ cdef class GoldParse:
|
||||||
self.labels[i] = self.labels[i][0]
|
self.labels[i] = self.labels[i][0]
|
||||||
else:
|
else:
|
||||||
self.labels[i] = 'subtok'
|
self.labels[i] = 'subtok'
|
||||||
self.heads[i] = i+1
|
#self.heads[i] = i+1
|
||||||
|
|
||||||
cycle = nonproj.contains_cycle(self._alignment.flatten(self.heads))
|
cycle = nonproj.contains_cycle(self._alignment.flatten(self.heads))
|
||||||
if cycle is not None:
|
if cycle is not None:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user