from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer

def analyze_sentiment(text: str) -> dict:
    """
    分析文本的情感倾向
    :param text: 要分析的文本
    :return: 包含负面/中性/正面得分和总体判断的字典
    """
    analyzer = SentimentIntensityAnalyzer()
    scores = analyzer.polarity_scores(text)
    # 补充总体情感判断
    if scores['compound'] >= 0.05:
        sentiment = "正面"
    elif scores['compound'] <= -0.05:
        sentiment = "负面"
    else:
        sentiment = "中性"
    scores['总体情感'] = sentiment
    return scores

# 测试代码（运行这个文件时执行）
if __name__ == "__main__":
    test_text = "I love this product! It's amazing."
    result = analyze_sentiment(test_text)
    print(f"文本：{test_text}")
    print(f"情感分析结果：{result}")