* Add cycle-checking code in gold.pyx

This commit is contained in:
Matthew Honnibal 2015-06-23 00:02:22 +02:00
parent 839e5038b7
commit 46fb24e9fd
1 changed files with 10 additions and 0 deletions

View File

@ -242,6 +242,16 @@ cdef class GoldParse:
self.heads[w2] = None
self.labels[w2] = ''
# Check there are no cycles in the dependencies, i.e. we are a tree
for w in range(self.length):
seen = set([w])
head = w
while self.heads[head] != head and self.heads[head] != None:
head = self.heads[head]
if head in seen:
raise Exception("Cycle found: %s" % seen)
seen.add(head)
self.brackets = {}
for (gold_start, gold_end, label_str) in brackets:
start = self.gold_to_cand[gold_start]