diff --git a/spacy/displacy/render.py b/spacy/displacy/render.py index f5c06d06b..0928f9cb9 100644 --- a/spacy/displacy/render.py +++ b/spacy/displacy/render.py @@ -1,6 +1,8 @@ # coding: utf8 from __future__ import unicode_literals +import random + from .templates import TPL_DEP_SVG, TPL_DEP_WORDS, TPL_DEP_ARCS from .templates import TPL_ENT, TPL_ENTS, TPL_FIGURE, TPL_TITLE, TPL_PAGE from ..util import minify_html, escape_html @@ -38,7 +40,10 @@ class DependencyRenderer(object): minify (bool): Minify HTML markup. RETURNS (unicode): Rendered SVG or HTML markup. """ - rendered = [self.render_svg(i, p['words'], p['arcs']) + # Create a random ID prefix to make sure parses don't receive the + # same ID, even if they're identical + id_prefix = random.randint(0, 999) + rendered = [self.render_svg('{}-{}'.format(id_prefix, i), p['words'], p['arcs']) for i, p in enumerate(parsed)] if page: content = ''.join([TPL_FIGURE.format(content=svg)