diff --git a/blub.py b/blub.py new file mode 100644 index 000000000..4b9524815 --- /dev/null +++ b/blub.py @@ -0,0 +1,20 @@ +doc_rendering = { + "text": "Welcome to the Bank of China.", + "spans": [ + {"start_token": 2, "end_token": 5, "label": "SkillNC"}, + {"start_token": 0, "end_token": 2, "label": "Skill"}, + {"start_token": 1, "end_token": 3, "label": "Skill"}, + ], + "tokens": ["Welcome", "to", "the", "Bank", "of", "China", "."], +} + +from spacy import displacy + +html = displacy.render( + doc_rendering, + style="span", + manual=True, + options={"colors": {"Skill": "#56B4E9", "SkillNC": "#FF5733"}}, +) +with open("render.html", "w") as file: + file.write(html) diff --git a/render.html b/render.html new file mode 100644 index 000000000..b28d3e935 --- /dev/null +++ b/render.html @@ -0,0 +1,73 @@ +
+ + Welcome + + + + + + + + Skill + + + + + + + + to + + + + + + + + + + + Skill + + + + + + + + the + + + + + + + + + + + SkillNC + + + + + + + + Bank + + + + + + + + + of + + + + + + +China .
\ No newline at end of file diff --git a/spacy/displacy/render.py b/spacy/displacy/render.py index 6500ca658..a6033efc9 100644 --- a/spacy/displacy/render.py +++ b/spacy/displacy/render.py @@ -163,7 +163,6 @@ class SpanRenderer: # start token of said Span. We'll use this for the final HTML render token_markup: Dict[str, Any] = {} token_markup["text"] = token - concurrent_spans = 0 intersecting_spans: List[Dict[str, Any]] = [] entities = [] for span in spans: @@ -176,8 +175,11 @@ class SpanRenderer: # When the span starts, we need to know how many other # spans are on the 'span stack' and will be rendered. # This value becomes the vertical render slot for this entire span - span["render_slot"] = \ - (intersecting_spans[-1]["render_slot"] if len(intersecting_spans) else 0) + 1 + span["render_slot"] = ( + intersecting_spans[-1]["render_slot"] + if len(intersecting_spans) + else 0 + ) + 1 intersecting_spans.append(span) ent["render_slot"] = span["render_slot"] kb_id = span.get("kb_id", "")