diff --git a/spacy/lang/de/syntax_iterators.py b/spacy/lang/de/syntax_iterators.py index 73c1b1a6e..c5513abc0 100644 --- a/spacy/lang/de/syntax_iterators.py +++ b/spacy/lang/de/syntax_iterators.py @@ -38,9 +38,13 @@ def noun_chunks(doclike): close_app = doc.vocab.strings.add("nk") rbracket = 0 + prev_end = -1 for i, word in enumerate(doclike): if i < rbracket: continue + # Prevent nested chunks from being produced + if word.left_edge.i <= prev_end: + continue if word.pos in (NOUN, PROPN, PRON) and word.dep in np_deps: rbracket = word.i + 1 # try to extend the span to the right @@ -48,6 +52,7 @@ def noun_chunks(doclike): for rdep in doc[word.i].rights: if rdep.pos in (NOUN, PROPN) and rdep.dep == close_app: rbracket = rdep.i + 1 + prev_end = rbracket - 1 yield word.left_edge.i, rbracket, np_label