-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_chinese.py
More file actions
41 lines (34 loc) · 1.24 KB
/
test_chinese.py
File metadata and controls
41 lines (34 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
测试中文情感分析
"""
from sentiment_monitor.text_analysis.sentiment import SentimentAnalyzer
def main():
# 创建情感分析器
analyzer = SentimentAnalyzer()
# 中文测试文本
texts = [
"我今天感觉很开心,天气真好!",
"这个产品质量太差了,我非常失望。",
"今天天气不错,但是交通有点堵。",
"我对这个服务非常满意,工作人员态度很好。",
"这家餐厅的菜品很一般,价格却很贵。"
]
# 分析每个文本
for text in texts:
# 检测语言
language = analyzer.detect_language(text)
print(f"文本: {text}")
print(f"语言: {language}")
# 进行情感分析
result = analyzer.analyze(text)
print(f"情感: {result['sentiment']}")
print(f"分数: {result['score']:.2f}")
print(f"置信度: {result['confidence']:.2f}")
print("-" * 50)
# 进行情绪分析
emotion_result = analyzer.analyze_emotions(text)
print(f"主要情绪: {emotion_result['main_emotion']}")
print(f"情绪分布: {emotion_result['emotions']}")
print("=" * 50)
if __name__ == "__main__":
main()