AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary
Python ai-promptsai-skillblueskyclaudeclaude-codeclawhubdeep-researchhackernewsinstagramopenclawpolymarketrecencyredditresearchsocial-mediatiktoktrendstwitterweb-searchyoutube
fix(polymarket): match spelled-out topics against acronym titles (#891)
Terry Li21c54d646c6d
diff --git a/changelog.d/891.fixed.md b/changelog.d/891.fixed.mdnew file mode 100644index 00000000..119c4dba--- /dev/null+++ b/changelog.d/891.fixed.md@@ -0,0 +1 @@+Polymarket topics spelled out in full ("artificial general intelligence") now match markets titled in shorthand ("AGI by 2030?"). Previously the topic filter and the relevance floor both compared full words against an acronym, so every on-topic market was dropped and the run reported zero results — indistinguishable from the source genuinely having none.diff --git a/skills/last30days/scripts/lib/polymarket.py b/skills/last30days/scripts/lib/polymarket.pyindex a9c446ac..340f6619 100644--- a/skills/last30days/scripts/lib/polymarket.py+++ b/skills/last30days/scripts/lib/polymarket.py@@ -199,6 +199,31 @@ def _domain_word_fallback_allows(core_words: list[str], informative: list[str],return False+def _acronym_credit(core_words: list[str], title_words: set[str]) -> int:+ """Credit matches when the title abbreviates a phrase the topic spells out.++ Prediction-market titles use shorthand ("AGI by 2030?") while topics arrive+ spelled out ("artificial general intelligence"), so word overlap scores zero+ on a title that is squarely on topic. For each run of 3+ consecutive+ informative words, build its initialism and, if the title carries it as a+ whole word, credit one match per abbreviated word. Requiring at least three+ letters avoids treating ambiguous tokens such as "ML" as expanded phrases.+ """+ informative_set = set(_informative_words(core_words))+ credit = 0+ run: list[str] = []+ for word in core_words + [""]:+ if word in informative_set:+ run.append(word)+ continue+ if len(run) >= 3:+ acronym = "".join(w[0] for w in run)+ if len(acronym) >= 3 and acronym in title_words:+ credit = max(credit, len(run))+ run = []+ return credit++def _passes_topic_filter(topic: str, event_title: str) -> bool:"""Check if event title contains enough informative words from the topic.@@ -236,6 +261,12 @@ def _passes_topic_filter(topic: str, event_title: str) -> bool:if len(word) >= 4 and word in title_lower:match_count += 1+ # A title that abbreviates what the topic spells out ("AGI" for+ # "artificial general intelligence") scores zero above; credit it here.+ if match_count < 2:+ match_count = max(match_count,+ _acronym_credit(core_words, title_words))+# For topics with 3+ informative words, require at least 2 matches.# This prevents single-word false positives like "mill" in "Meek Mill"# when the topic is "Mill.com food recycler" (3 informative words).@@ -594,6 +625,14 @@ def _compute_text_similarity(topic: str, title: str, outcomes: List[str] = None)if core in title_lower:return 1.0+ # Same match, abbreviated: "AGI" standing in for an informative phrase.+ # Use the filter's matcher so modifiers and minimum acronym length cannot+ # produce different decisions at the filtering and scoring stages.+ core_words = [w for w in re.sub(r"[^\w\s]", " ", core).split() if len(w) > 1]+ title_words = set(re.sub(r"[^\w\s]", " ", title_lower).split())+ if _acronym_credit(core_words, title_words):+ return 1.0+query_type = _infer_query_intent(topic)title_score = token_overlap_relevance(core, title)best_score = title_scorediff --git a/tests/test_polymarket_disambiguation.py b/tests/test_polymarket_disambiguation.pyindex 3529034b..9505c91e 100644--- a/tests/test_polymarket_disambiguation.py+++ b/tests/test_polymarket_disambiguation.py@@ -65,3 +65,71 @@ class FilterItemsAgainstKeywordsTests(unittest.TestCase):if __name__ == "__main__":unittest.main()+++def test_acronym_title_matches_spelled_out_topic():+ """A title abbreviating what the topic spells out must not be filtered.++ Market titles use shorthand ("AGI by 2030?") while topics arrive spelled+ out, so proportional word overlap scored zero on squarely on-topic markets.+ """+ assert polymarket._passes_topic_filter(+ "artificial general intelligence",+ "OpenAI announces it has achieved AGI before 2027?",+ )+ assert polymarket._passes_topic_filter("artificial general intelligence", "AGI by 2030?")+++def test_acronym_credit_does_not_widen_the_filter():+ """The acronym bridge must not rescue off-topic or weak single-word hits."""+ assert not polymarket._passes_topic_filter(+ "artificial general intelligence", "Premier League top scorer 2026"+ )+ assert not polymarket._passes_topic_filter(+ "Mill.com food recycler", "Meek Mill announces tour"+ )+ assert polymarket._passes_topic_filter("AGI", "AGI by 2030?")+ assert polymarket._passes_topic_filter("Kanye West", "Kanye West announces new album")+++def test_similarity_scores_acronym_title_as_full_match():+ """Clearing the topic filter is not enough: the relevance floor also drops it.++ An on-topic market passed _passes_topic_filter and was then dropped by the+ 0.15 relevance floor, because the similarity scorer compared spelled-out+ topic words against a shorthand title.+ """+ assert (+ polymarket._compute_text_similarity(+ "artificial general intelligence", "AGI by 2030?"+ )+ == 1.0+ )+ assert (+ polymarket._compute_text_similarity(+ "artificial general intelligence", "Premier League top scorer 2026"+ )+ == 0.0+ )+ assert (+ polymarket._compute_text_similarity("Kanye West", "Kanye West announces new album")+ == 1.0+ )+++def test_modifier_separated_acronym_matches_filter_and_similarity():+ """A leading modifier must not change the initialism used by the scorer."""+ topic = "impact of artificial general intelligence"+ title = "AGI by 2030?"++ assert polymarket._passes_topic_filter(topic, title)+ assert polymarket._compute_text_similarity(topic, title) == 1.0+++def test_two_letter_initialism_does_not_expand_topic():+ """Ambiguous two-letter tokens must not receive full expanded-phrase relevance."""+ topic = "machine learning"+ title = "ML market cap above $1 billion?"++ assert not polymarket._passes_topic_filter(topic, title)+ assert polymarket._compute_text_similarity(topic, title) < 1.0