[Feature]: add scores to diplacy entity markup

This commit is contained in:
Ceyda Cinarel 2025-02-19 20:15:20 +09:00
parent b3c46c315e
commit f5b0c342f2
2 changed files with 7 additions and 2 deletions

View File

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

View File

@ -51,14 +51,14 @@ TPL_ENTS = """
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>
"""
@ -127,3 +127,5 @@ TPL_PAGE = """
<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})"