Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions spacy/displacy/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
TPL_FIGURE,
TPL_KB_LINK,
TPL_PAGE,
TPL_SCORE,
TPL_SPAN,
TPL_SPAN_RTL,
TPL_SPAN_SLICE,
Expand Down Expand Up @@ -579,6 +580,7 @@ def render_ents(
label = span["label"]
start = span["start"]
end = span["end"]
score = TPL_SCORE.format(score=span["score"]) if "score" in span else ""
kb_id = span.get("kb_id", "")
kb_url = span.get("kb_url", "#")
kb_link = TPL_KB_LINK.format(kb_id=kb_id, kb_url=kb_url) if kb_id else ""
Expand All @@ -596,6 +598,7 @@ def render_ents(
"text": entity,
"bg": color,
"kb_link": kb_link,
"score": score,
}
ent_settings.update(additional_params)
markup += self.ent_template.format(**ent_settings)
Expand Down
6 changes: 4 additions & 2 deletions spacy/displacy/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@
TPL_ENT = """
<mark class="entity" style="background: {bg}; padding: 0.45em 0.6em; margin: 0 0.25em; line-height: 1; border-radius: 0.35em;">
{text}
<span style="font-size: 0.8em; font-weight: bold; line-height: 1; border-radius: 0.35em; vertical-align: middle; margin-left: 0.5rem">{label}{kb_link}</span>
<span style="font-size: 0.8em; font-weight: bold; line-height: 1; border-radius: 0.35em; vertical-align: middle; margin-left: 0.5rem">{label}{kb_link}{score}</span>
</mark>
"""

TPL_ENT_RTL = """
<mark class="entity" style="background: {bg}; padding: 0.45em 0.6em; margin: 0 0.25em; line-height: 1; border-radius: 0.35em">
{text}
<span style="font-size: 0.8em; font-weight: bold; line-height: 1; border-radius: 0.35em; vertical-align: middle; margin-right: 0.5rem">{label}{kb_link}</span>
<span style="font-size: 0.8em; font-weight: bold; line-height: 1; border-radius: 0.35em; vertical-align: middle; margin-right: 0.5rem">{label}{kb_link}{score}</span>
</mark>
"""

Expand Down Expand Up @@ -127,3 +127,5 @@
<body style="font-size: 16px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol'; padding: 4rem 2rem; direction: {dir}">{content}</body>
</html>
"""

TPL_SCORE = "({score:.2f})"