fix: Fixed the error in generating word clouds when the text became empty after stop word filtering
This commit is contained in:
@@ -368,29 +368,28 @@ class LiveReportGenerator:
|
|||||||
if model.danmu_cloud:
|
if model.danmu_cloud:
|
||||||
all_danmu = param.get('all_danmu', [])
|
all_danmu = param.get('all_danmu', [])
|
||||||
|
|
||||||
if all_danmu:
|
if config.get("DANMU_CLOUD_DICT"):
|
||||||
|
try:
|
||||||
|
jieba.load_userdict(config.get("DANMU_CLOUD_DICT"))
|
||||||
|
except Exception:
|
||||||
|
logger.error("载入弹幕词云自定义词典失败, 请检查配置的词典路径是否正确")
|
||||||
|
|
||||||
|
all_danmu_str = " ".join(all_danmu)
|
||||||
|
words = list(jieba.cut(all_danmu_str))
|
||||||
|
counts = dict(Counter(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)
|
||||||
|
for sw in stop_words:
|
||||||
|
counts.pop(sw, None)
|
||||||
|
except Exception:
|
||||||
|
logger.error("载入弹幕词云停用词失败, 请检查配置的停用词路径是否正确")
|
||||||
|
|
||||||
|
if len(counts) > 0:
|
||||||
pic.draw_section("弹幕词云")
|
pic.draw_section("弹幕词云")
|
||||||
|
|
||||||
if config.get("DANMU_CLOUD_DICT"):
|
|
||||||
try:
|
|
||||||
jieba.load_userdict(config.get("DANMU_CLOUD_DICT"))
|
|
||||||
except Exception:
|
|
||||||
logger.error("载入弹幕词云自定义词典失败, 请检查配置的词典路径是否正确")
|
|
||||||
|
|
||||||
all_danmu_str = " ".join(all_danmu)
|
|
||||||
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)
|
|
||||||
|
|
||||||
font_base_path = os.path.dirname(os.path.dirname(__file__))
|
font_base_path = os.path.dirname(os.path.dirname(__file__))
|
||||||
word_cloud = WordCloud(width=900,
|
word_cloud = WordCloud(width=900,
|
||||||
height=450,
|
height=450,
|
||||||
|
|||||||
Reference in New Issue
Block a user