from typing import List, Dict
class CustomPllLabel:
def __init__(
self
) -> None:
self.html_head = """
"""
self.html_footer =""
def __progressbar(
self,
percentage: int,
sent: str,
ratio: float,
score: float,
size: int=15
) -> str:
html = f"""
"""
return html
def __render(
self,
sents: List[str],
scores: List[float],
ratios: List[float]
) -> str:
max_ratio = max(ratios)
ratio2percentage = lambda ratio: int(ratio*100/max_ratio)
html = ""
for sent, ratio, score in zip(sents, ratios, scores):
html += self.__progressbar(
percentage=ratio2percentage(ratio),
sent=sent,
ratio=ratio,
score=score
)
return self.html_head + html + self.html_footer
def __getProportions(
self,
scores: List[float],
) -> List[float]:
min_score = min(scores)
return [min_score/s for s in scores]
def compute(
self,
pll_dict: Dict[str, float]
) -> str:
sorted_pll_dict = sorted(pll_dict.items(), key=lambda x: x[1], reverse=True)
sents = [k for k,_ in sorted_pll_dict]
scores = [v for _,v in sorted_pll_dict]
# Scape < and > marks from hightlight word/s
sents = [s.replace("<","<").replace(">",">") for s in sents]
ratios = self.__getProportions(scores)
return self.__render(sents, scores, ratios)