AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He
fix(image-search): required terms match whole Latin words
hugohe3d4ac79dfc0cf
diff --git a/skills/ppt-master/scripts/image_sources/provider_common.py b/skills/ppt-master/scripts/image_sources/provider_common.pyindex d652d8af..8e4fdb32 100644--- a/skills/ppt-master/scripts/image_sources/provider_common.py+++ b/skills/ppt-master/scripts/image_sources/provider_common.py@@ -386,6 +386,19 @@ def _normalize_match_text(text: str) -> str:return _MATCH_SEPARATOR_RE.sub(" ", lowered).strip()+def _contains_term(term: str, text: str) -> bool:+ """Match one normalized term: whole words for Latin, spacing-free for CJK.++ "iran" must not pass on "tirana"; "liberation monument" still matches a+ run-together "liberationmonument" slug, and CJK ignores inserted spaces.+ """+ compact_term = term.replace(" ", "")+ if term.isascii():+ forms = "|".join(re.escape(form) for form in {term, compact_term})+ return re.search(rf"(?<![a-z0-9])(?:{forms})(?![a-z0-9])", text) is not None+ return term in text or compact_term in text.replace(" ", "")++def _term_group_alternatives(term_group: str) -> list[str]:"""Split one required term group into alternatives.@@ -414,16 +427,12 @@ def missing_required_terms(return []text = _normalize_match_text(_candidate_text(candidate))- compact_text = text.replace(" ", "")missing: list[str] = []for group in required_terms:alternatives = _term_group_alternatives(group)if not alternatives:continue- matched = any(- alt in text or alt.replace(" ", "") in compact_text- for alt in alternatives- )+ matched = any(_contains_term(alt, text) for alt in alternatives)if not matched:missing.append(str(group))return missing@@ -480,13 +489,9 @@ def score_candidate(candidate: AssetCandidate, request: ImageSearchRequest) -> fscore = relevance * 10000.0title_text = _normalize_match_text(candidate.title)- compact_title = title_text.replace(" ", "")for group in request.required_terms or ():alternatives = _term_group_alternatives(group)- if any(- alt in title_text or alt.replace(" ", "") in compact_title- for alt in alternatives- ):+ if any(_contains_term(alt, title_text) for alt in alternatives):score += 1500.0# Penalize infrastructure/transit metadata if the user didn't explicitly ask for it.diff --git a/skills/ppt-master/scripts/tests/test_image_search.py b/skills/ppt-master/scripts/tests/test_image_search.pyindex a9205ce7..4b14a7f4 100644--- a/skills/ppt-master/scripts/tests/test_image_search.py+++ b/skills/ppt-master/scripts/tests/test_image_search.py@@ -257,3 +257,16 @@ class InfrastructurePenaltyTests(unittest.TestCase):self._score("team", "team office"),)self.assertGreater(self._score("bus station", "team bus station"), 0)+++class RequiredTermsGateTests(unittest.TestCase):+ def test_latin_terms_match_whole_words_and_cjk_ignores_spacing(self) -> None:+ from image_sources.provider_common import AssetCandidate, missing_required_terms++ def missing(title: str, terms: tuple[str, ...]) -> list[str]:+ return missing_required_terms(AssetCandidate(provider="test", title=title), terms)++ self.assertEqual(missing("Tirana, Albania", ("Iran",)), ["Iran"])+ self.assertEqual(missing("Tehran, Iran", ("Iran",)), [])+ self.assertEqual(missing("LiberationMonument at night", ("Liberation Monument",)), [])+ self.assertEqual(missing("重庆 解放 碑", ("解放碑",)), [])