Format. Remove counter.

This commit is contained in:
Raphael Mitsch 2023-10-18 10:39:17 +02:00
parent 35ff3c9406
commit e7ca6a2a56
3 changed files with 98 additions and 3 deletions

20
blub.py Normal file
View File

@ -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)

73
render.html Normal file
View File

@ -0,0 +1,73 @@
<div class="spans" style="line-height: 2.5; direction: ltr">
<span style="font-weight: bold; display: inline-block; position: relative; height: 60px;">
Welcome
<span style="background: #56B4E9; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
</span>
<span style="background: #56B4E9; top: 40px; height: 4px; border-top-left-radius: 3px; border-bottom-left-radius: 3px; left: -1px; width: calc(100% + 2px); position: absolute;">
<span style="background: #56B4E9; z-index: 10; color: #000; top: -0.5em; padding: 2px 3px; position: absolute; font-size: 0.6em; font-weight: bold; line-height: 1; border-radius: 3px">
Skill
</span>
</span>
</span>
<span style="font-weight: bold; display: inline-block; position: relative; height: 77px;">
to
<span style="background: #56B4E9; top: 40px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
</span>
<span style="background: #56B4E9; top: 57px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
</span>
<span style="background: #56B4E9; top: 57px; height: 4px; border-top-left-radius: 3px; border-bottom-left-radius: 3px; left: -1px; width: calc(100% + 2px); position: absolute;">
<span style="background: #56B4E9; z-index: 10; color: #000; top: -0.5em; padding: 2px 3px; position: absolute; font-size: 0.6em; font-weight: bold; line-height: 1; border-radius: 3px">
Skill
</span>
</span>
</span>
<span style="font-weight: bold; display: inline-block; position: relative; height: 77px;">
the
<span style="background: #56B4E9; top: 57px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
</span>
<span style="background: #FF5733; top: 57px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
</span>
<span style="background: #FF5733; top: 57px; height: 4px; border-top-left-radius: 3px; border-bottom-left-radius: 3px; left: -1px; width: calc(100% + 2px); position: absolute;">
<span style="background: #FF5733; z-index: 10; color: #000; top: -0.5em; padding: 2px 3px; position: absolute; font-size: 0.6em; font-weight: bold; line-height: 1; border-radius: 3px">
SkillNC
</span>
</span>
</span>
<span style="font-weight: bold; display: inline-block; position: relative; height: 60px;">
Bank
<span style="background: #FF5733; top: 57px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
</span>
</span>
<span style="font-weight: bold; display: inline-block; position: relative; height: 60px;">
of
<span style="background: #FF5733; top: 57px; height: 4px; left: -1px; width: calc(100% + 2px); position: absolute;">
</span>
</span>
China . </div>

View File

@ -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", "")