From 0725e043162fd2f1a2de59b35c269522b4625bb9 Mon Sep 17 00:00:00 2001 From: Gregory Danielson Date: Tue, 23 Apr 2024 13:48:58 -0500 Subject: [PATCH] ilo nanpa Scaling o lon --- src/otokipona/Scorers.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/otokipona/Scorers.py b/src/otokipona/Scorers.py index b2442f5..75c3aa7 100644 --- a/src/otokipona/Scorers.py +++ b/src/otokipona/Scorers.py @@ -58,6 +58,24 @@ class Scaling(Scorer): In other words, filter order matters, weighing earlier listed filters higher than later ones. """ + @classmethod + def __score(cls, token: str, filters: List[Type[Filter]], scale: int): + for i, f in enumerate(filters): + if f.filter(token): + return scale - i + return 0 + + @classmethod + @override + def score(cls, tokens: List[str], filters: List[Type[Filter]]) -> Number: + total_score = 0 + len_tokens = len(tokens) + max_scale = len_tokens - 1 + max_score = max_scale * len_tokens + for token in tokens: + total_score += cls.__score(token, filters, max_scale) + return total_score / max_score if max_score else 0 + class Logarithmic(Scorer): ...