• 实践对热词进行自动分类。
  • 存储分类结果。
 
def classify_and_save(hot_words, rules, file_path):
    classified_words = {category: [] for category in rules.keys()}
    for word in hot_words:
        category = classify_word(word, rules)
        classified_words[category].append(word)
    
    with open(file_path, 'w') as f:
        for category, words in classified_words.items():
            f.write(f"{category}: {', '.join(words)}\n")

classify_and_save(hot_words, rules, "classified_hot_words.txt")