首页 > 其他分享 >hahah

hahah

时间:2023-10-28 11:00:30浏览次数:28  
标签:程度 degree 词是 词赋 score hahah words

# 定义一个函数,计算每个评论得分
def score(words):
# 程度词赋分
degrees = {
'most': 8,
'very': 6,
'more': 4,
'ish': 0.6,
'insufficiently': -2,
'over': 2
}

# 正负向词赋分
attitudes = {
'positive': 1,
'negative': -1,
'no_attitude': 0
}

# 句子得分(正向、负向、无态度词)
positive_score_in_sentences, negative_score_in_sentences, no_attitude_score_in_sentences = [], [], []
# 遍历每个词语
for word in words:
# 如果词语是负面词语
if word in negative_words:
degree = words[words.index(word) - 1] # 获取当前词语的前一个词语(程度词)
if degree in degree_most_words: # 如果程度词是 most
negative_score_in_sentences.append(degrees['most'] * attitudes['negative']) # 将“most”程度词赋分(负向)
elif degree in degree_very_words: # 如果程度词是 very
??? # 将“very”程度词赋分(负向)
elif degree in degree_more_words: # 如果程度词是 more
??? # 将“more”程度词赋分(负向)
elif degree in degree_ish_words: # 如果程度词是 ish
???# 将“ish”程度词赋分(负向)
elif degree in degree_insufficiently_words: # 如果程度词是 insufficiently
??? # 将“insufficiently”程度词赋分(负向)
elif degree in degree_over_words: # 如果程度词是 over
??? # 将“over”程度词赋分(负向)
else:
negative_score_in_sentences.append(attitudes['negative']) # 无程度词时,将词语赋予负向得分
# 如果词语是正面词语
elif word in positive_words:
degree = words[words.index(word) - 1] # 获取当前词语的前一个词语(程度词)
if degree in degree_most_words: # 如果程度词是 most
??? # 将“most”程度词赋分(正向)
elif degree in degree_very_words: # 如果程度词是 very
??? # 将“very”程度词赋分(负向)
elif degree in degree_more_words: # 如果程度词是 more
??? # 将“more”程度词赋分(负向)
elif degree in degree_ish_words: # 如果程度词是 ish
??? # 将“ish”程度词赋分(负向)
elif degree in degree_insufficiently_words: # 如果程度词是 insufficiently
??? # 将“insufficiently”程度词赋分(负向)
elif degree in degree_over_words: # 如果程度词是 over
???
else:
??? # 默认情况下,将词语赋予正向得分
else:
no_attitude_score_in_sentences.??? # 将无态度词赋予无态度得分
# 计算评论的总得分(负向得分总和加上正向得分总和)
sum_score = sum(negative_score_in_sentences) + sum(positive_score_in_sentences)
return sum_score
# 将评论内容经过分词后,应用 score 函数计算得分,将结果存储在 DataFrame 中的名为 'score' 的列中
df['score'] = df['评论内容-分词'].apply(score)
df.head()

标签:程度,degree,词是,词赋,score,hahah,words
From: https://www.cnblogs.com/bthcls/p/17793799.html

相关文章