From 6fb637167028da3dd62f7000bfcbcb44be0f844f Mon Sep 17 00:00:00 2001 From: ines Date: Sat, 28 Apr 2018 23:06:50 +0200 Subject: [PATCH] Add collapse_phrases option to displacy (closes #2266) --- spacy/displacy/__init__.py | 4 ++++ website/api/_top-level/_displacy.jade | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/spacy/displacy/__init__.py b/spacy/displacy/__init__.py index fb6487305..a3c6a5a94 100644 --- a/spacy/displacy/__init__.py +++ b/spacy/displacy/__init__.py @@ -86,6 +86,10 @@ def parse_deps(orig_doc, options={}): doc = Doc(orig_doc.vocab).from_bytes(orig_doc.to_bytes()) if not doc.is_parsed: user_warning(Warnings.W005) + if options.get('collapse_phrases', False): + for np in list(doc.noun_chunks): + np.merge(tag=np.root.tag_, lemma=np.root.lemma_, + ent_type=np.root.ent_type_) if options.get('collapse_punct', True): spans = [] for word in doc[:-1]: diff --git a/website/api/_top-level/_displacy.jade b/website/api/_top-level/_displacy.jade index 105bb0cc6..7fcf3d464 100644 --- a/website/api/_top-level/_displacy.jade +++ b/website/api/_top-level/_displacy.jade @@ -157,6 +157,12 @@ p | as it prevents long arcs to attach punctuation. +cell #[code True] + +row + +cell #[code collapse_phrases] + +cell bool + +cell Merge base noun phrases into one token. + +cell #[code False] + +row +cell #[code compact] +cell bool