File size: 1,210 Bytes
d02bacd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from __future__ import annotations

from typing import Iterable, Sequence


def build_hr_memo(audience: str, task_title: str, highlights: Sequence[str]) -> str:
    opening = f"Hello {audience},"
    body = [
        "Thank you for moving quickly on this update.",
        f"Here is the latest business update for {task_title}.",
    ]
    body.extend(f"- {line}" for line in highlights[:4])
    close = [
        "Please review the actions above and reply with any blockers today.",
        "Best,",
        "HR Operations",
    ]
    return "\n".join([opening, "", *body, "", *close])


def score_memo(memo: str, required_terms: Iterable[str]) -> float:
    text = memo.lower()
    score = 0.2
    if memo.startswith("Hello "):
        score += 0.15
    if "thank" in text or "appreciate" in text:
        score += 0.15
    if "please review" in text or "reply with any blockers" in text:
        score += 0.2
    if "best," in text:
        score += 0.1
    matched = 0
    terms = [t.lower() for t in required_terms if t]
    for term in terms:
        if term in text:
            matched += 1
    if terms:
        score += 0.2 * (matched / len(terms))
    return max(0.001, min(0.999, round(score, 4)))