13 lines
492 B
Python
13 lines
492 B
Python
"""Fuzzy grounding: decide whether a search hit matches an LLM candidate."""
|
|
|
|
from difflib import SequenceMatcher
|
|
|
|
|
|
def normalize(text: str) -> str:
|
|
"""Lowercase and strip decorations that vary across releases."""
|
|
return text.lower().strip()
|
|
|
|
|
|
def title_similarity(candidate_title: str, catalog_title: str) -> float:
|
|
"""Ratio in [0, 1] between a proposed title and a catalog title."""
|
|
return SequenceMatcher(None, normalize(candidate_title), normalize(catalog_title)).ratio()
|