From 05e18420008e6a324b37c8a2f8585192f4cb53b6 Mon Sep 17 00:00:00 2001 From: AllfatherHatt Date: Mon, 24 Feb 2025 18:46:19 +0100 Subject: [PATCH] trying to fix topic extraction --- reginaldCog/reginald.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/reginaldCog/reginald.py b/reginaldCog/reginald.py index 88ef7ec..342539e 100644 --- a/reginaldCog/reginald.py +++ b/reginaldCog/reginald.py @@ -282,18 +282,20 @@ class ReginaldCog(commands.Cog): def extract_topics_from_summary(self, summary): """Dynamically extracts the most important topics from a summary.""" + + if isinstance(summary, dict): # ✅ Extract summary content correctly + summary = summary.get("summary", "") + + if not isinstance(summary, str): # ✅ Additional safeguard + return [] - # 🔹 Extract all words from summary keywords = re.findall(r"\b\w+\b", summary.lower()) - # 🔹 Count word occurrences word_counts = Counter(keywords) - # 🔹 Remove unimportant words (common filler words) - stop_words = {"the", "and", "of", "in", "to", "is", "on", "for", "with", "at", "by", "it", "this", "that", "his", "her"} + stop_words = {"the", "and", "of", "in", "to", "is", "on", "for", "with", "at", "by", "it", "this", "that"} filtered_words = {word: count for word, count in word_counts.items() if word not in stop_words and len(word) > 2} - # 🔹 Take the 5 most frequently used words as "topics" topics = sorted(filtered_words, key=filtered_words.get, reverse=True)[:5] return topics