fix: Fixed the error in generating word clouds when the text became empty after stop word filtering
This commit is contained in:
@@ -368,9 +368,6 @@ class LiveReportGenerator:
|
||||
if model.danmu_cloud:
|
||||
all_danmu = param.get('all_danmu', [])
|
||||
|
||||
if all_danmu:
|
||||
pic.draw_section("弹幕词云")
|
||||
|
||||
if config.get("DANMU_CLOUD_DICT"):
|
||||
try:
|
||||
jieba.load_userdict(config.get("DANMU_CLOUD_DICT"))
|
||||
@@ -381,15 +378,17 @@ class LiveReportGenerator:
|
||||
words = list(jieba.cut(all_danmu_str))
|
||||
counts = dict(Counter(words))
|
||||
|
||||
stop_words = {}
|
||||
if config.get("DANMU_CLOUD_STOP_WORDS"):
|
||||
try:
|
||||
with open(config.get("DANMU_CLOUD_STOP_WORDS"), "r", encoding="utf-8") as f:
|
||||
stop_words = set(line.strip() for line in f)
|
||||
except Exception:
|
||||
logger.error("载入弹幕词云停用词失败, 请检查配置的停用词路径是否正确")
|
||||
for sw in stop_words:
|
||||
counts.pop(sw, None)
|
||||
except Exception:
|
||||
logger.error("载入弹幕词云停用词失败, 请检查配置的停用词路径是否正确")
|
||||
|
||||
if len(counts) > 0:
|
||||
pic.draw_section("弹幕词云")
|
||||
|
||||
font_base_path = os.path.dirname(os.path.dirname(__file__))
|
||||
word_cloud = WordCloud(width=900,
|
||||
|
||||
Reference in New Issue
Block a user