mirror of
https://github.com/explosion/spaCy.git
synced 2025-05-04 15:53:40 +03:00
[Feature]: add scores to diplacy entity markup
This commit is contained in:
parent
b3c46c315e
commit
f5b0c342f2
|
@ -14,6 +14,7 @@ from .templates import (
|
||||||
TPL_FIGURE,
|
TPL_FIGURE,
|
||||||
TPL_KB_LINK,
|
TPL_KB_LINK,
|
||||||
TPL_PAGE,
|
TPL_PAGE,
|
||||||
|
TPL_SCORE,
|
||||||
TPL_SPAN,
|
TPL_SPAN,
|
||||||
TPL_SPAN_RTL,
|
TPL_SPAN_RTL,
|
||||||
TPL_SPAN_SLICE,
|
TPL_SPAN_SLICE,
|
||||||
|
@ -579,6 +580,7 @@ class EntityRenderer:
|
||||||
label = span["label"]
|
label = span["label"]
|
||||||
start = span["start"]
|
start = span["start"]
|
||||||
end = span["end"]
|
end = span["end"]
|
||||||
|
score = TPL_SCORE.format(score=span["score"]) if "score" in span else ""
|
||||||
kb_id = span.get("kb_id", "")
|
kb_id = span.get("kb_id", "")
|
||||||
kb_url = span.get("kb_url", "#")
|
kb_url = span.get("kb_url", "#")
|
||||||
kb_link = TPL_KB_LINK.format(kb_id=kb_id, kb_url=kb_url) if kb_id else ""
|
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,
|
"text": entity,
|
||||||
"bg": color,
|
"bg": color,
|
||||||
"kb_link": kb_link,
|
"kb_link": kb_link,
|
||||||
|
"score": score,
|
||||||
}
|
}
|
||||||
ent_settings.update(additional_params)
|
ent_settings.update(additional_params)
|
||||||
markup += self.ent_template.format(**ent_settings)
|
markup += self.ent_template.format(**ent_settings)
|
||||||
|
|
|
@ -51,14 +51,14 @@ TPL_ENTS = """
|
||||||
TPL_ENT = """
|
TPL_ENT = """
|
||||||
<mark class="entity" style="background: {bg}; padding: 0.45em 0.6em; margin: 0 0.25em; line-height: 1; border-radius: 0.35em;">
|
<mark class="entity" style="background: {bg}; padding: 0.45em 0.6em; margin: 0 0.25em; line-height: 1; border-radius: 0.35em;">
|
||||||
{text}
|
{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>
|
</mark>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
TPL_ENT_RTL = """
|
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">
|
<mark class="entity" style="background: {bg}; padding: 0.45em 0.6em; margin: 0 0.25em; line-height: 1; border-radius: 0.35em">
|
||||||
{text}
|
{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>
|
</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>
|
<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>
|
</html>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
TPL_SCORE = "({score:.2f})"
|
Loading…
Reference in New Issue
Block a user