reorganization

This commit is contained in:
Roberto Treviño Cervantes
2026-10-31 12:47:59 -06:00
parent ae1ee4633f
commit fce6ccd40a
9 changed files with 185 additions and 23 deletions
+5 -4
View File
@@ -1,10 +1,11 @@
"""Auto-match suggestions for the column-mapping UI, based on stdlib `difflib`."""
"""Auto-match suggestions for the column-mapping UI, based on `rapidfuzz`."""
import difflib
import re
import unicodedata
from dataclasses import dataclass
from rapidfuzz import fuzz
# Keys are target fields; values are normalized source-column names (see
# `_normalize`: lowercase, no accents, spaces/dashes/dots -> "_").
SYNONYMS: dict[str, set[str]] = {
@@ -75,7 +76,7 @@ def _word_score(source_words: list[str], target_words: list[str]) -> float:
return 0.0
total = 0.0
for word in source_words:
best = max(difflib.SequenceMatcher(None, word, other).ratio() for other in target_words)
best = max(fuzz.ratio(word, other) / 100.0 for other in target_words)
if best >= _NEAR_WORD:
total += best
return total / max(len(source_words), len(target_words))
@@ -150,6 +151,6 @@ def _score_one(source: str, target: str) -> tuple[float, str] | None:
if words >= _WORD_FLOOR:
# 0.5..0.7 by word overlap, plus a tiny whole-string tiebreak so
# "fecha_reporte" prefers bx_fecha_reporte over another one-word overlap.
ratio = difflib.SequenceMatcher(None, normalized_source, unprefixed_target).ratio()
ratio = fuzz.ratio(normalized_source, unprefixed_target) / 100.0
return min(0.5 + (words - _WORD_FLOOR) * 0.36 + ratio * 0.02, _FUZZY_CAP), "fuzzy"
return None