Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Renat Shigapov <57352291+shigapov@users.noreply.github.com>
  • Loading branch information
ines and shigapov committed Sep 23, 2021
1 parent 00836c2 commit 57b5fc1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion spacy/displacy/render.py
Expand Up @@ -316,6 +316,10 @@ def render_ents(
end = span["end"]
kb_id = span.get("kb_id", "")
kb_url = span.get("kb_url", "")
if kb_id:
kb_link = """<a style="text-decoration: none; color: black; font-weight: bold" href="{}">{}</a>""".format(kb_url, kb_id)
else:
kb_link = ""
additional_params = span.get("params", {})
entity = escape_html(text[start:end])
fragments = text[offset:start].split("\n")
Expand All @@ -325,7 +329,7 @@ def render_ents(
markup += "</br>"
if self.ents is None or label.upper() in self.ents:
color = self.colors.get(label.upper(), self.default_color)
ent_settings = {"label": label, "text": entity, "bg": color, "kb_id": kb_id, "kb_url": kb_url}
ent_settings = {"label": label, "text": entity, "bg": color, "kb_link": kb_link}
ent_settings.update(additional_params)
markup += self.ent_template.format(**ent_settings)
else:
Expand Down
2 changes: 1 addition & 1 deletion spacy/displacy/templates.py
Expand Up @@ -52,7 +52,7 @@
<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}
<a style="text-decoration: none; color: black; font-weight: bold" href="{kb_url}">{kb_id}</a>
{kb_link}
</span>
</mark>
"""
Expand Down

0 comments on commit 57b5fc1

Please sign in to comment.