From f5b0c342f24a42d6276eb48b109d61b2e4733eb5 Mon Sep 17 00:00:00 2001 From: Ceyda Cinarel <15624271+cceyda@users.noreply.github.com> Date: Wed, 19 Feb 2025 20:15:20 +0900 Subject: [PATCH] [Feature]: add scores to diplacy entity markup --- spacy/displacy/render.py | 3 +++ spacy/displacy/templates.py | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/spacy/displacy/render.py b/spacy/displacy/render.py index 40b9986e8..d89732725 100644 --- a/spacy/displacy/render.py +++ b/spacy/displacy/render.py @@ -14,6 +14,7 @@ from .templates import ( TPL_FIGURE, TPL_KB_LINK, TPL_PAGE, + TPL_SCORE, TPL_SPAN, TPL_SPAN_RTL, TPL_SPAN_SLICE, @@ -579,6 +580,7 @@ class EntityRenderer: 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 "" @@ -596,6 +598,7 @@ class EntityRenderer: "text": entity, "bg": color, "kb_link": kb_link, + "score": score, } ent_settings.update(additional_params) markup += self.ent_template.format(**ent_settings) diff --git a/spacy/displacy/templates.py b/spacy/displacy/templates.py index 40f5376b1..648e851d5 100644 --- a/spacy/displacy/templates.py +++ b/spacy/displacy/templates.py @@ -51,14 +51,14 @@ TPL_ENTS = """ TPL_ENT = """ {text} - {label}{kb_link} + {label}{kb_link}{score} """ TPL_ENT_RTL = """ {text} - {label}{kb_link} + {label}{kb_link}{score} """ @@ -127,3 +127,5 @@ TPL_PAGE = """ {content} """ + +TPL_SCORE = "({score:.2f})" \ No newline at end of file