From 46fb24e9fd20baa6c21623a895f01c53cf6ac107 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Tue, 23 Jun 2015 00:02:22 +0200 Subject: [PATCH] * Add cycle-checking code in gold.pyx --- spacy/gold.pyx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spacy/gold.pyx b/spacy/gold.pyx index f3ed33d10..489b8b124 100644 --- a/spacy/gold.pyx +++ b/spacy/gold.pyx @@ -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]