さらにソースコードの更新です。

ーーーーーーーーーーーーーーーー

# 感情状態チェックツール - ルールベースアナライザー


# ポジティブおよびネガティブな言葉のリスト

positive_words = ["happy", "joy", "love", "excited", "grateful", "content", "delighted", "cheerful", "energetic", "hopeful"]

negative_words = ["sad", "angry", "lonely", "depressed", "anxious", "hurt", "gloomy", "miserable", "frustrated", "hopeless"]


def analyze_emotion(text):

    # ポジティブおよびネガティブな言葉の出現回数をカウント

    positive_count = sum(text.count(word) for word in positive_words)

    negative_count = sum(text.count(word) for word in negative_words)


    # 感情状態スコアを算出

    emotion_score = (positive_count - negative_count) * 100 / (positive_count + negative_count if positive_count + negative_count != 0 else 1)


    # フィードバックの準備

    identified_positive = [word for word in positive_words if word in text]

    identified_negative = [word for word in negative_words if word in text]


    # 結果の出力

    print(f"Identified Positive Words: {identified_positive}")

    print(f"Identified Negative Words: {identified_negative}")

    print(f"Emotion Score: {emotion_score:.2f}")


    # スコアに基づいて感情状態を評価

    if emotion_score > 0:

        print("Overall Emotion: Positive")

    elif emotion_score < 0:

        print("Overall Emotion: Negative")

    else:

        print("Overall Emotion: Neutral")


    # 乖離の原因についてのフィードバック

    if identified_positive and not identified_negative:

        print("Your text is purely positive. Keep up the positive vibe!")

    elif identified_negative and not identified_positive:

        print("Your text is purely negative. It's okay to have off days. Consider what might improve your mood.")

    elif identified_positive and identified_negative:

        print("Your text contains a mix of emotions. It's normal to have complex feelings.")


# テキスト入力の例

user_input = "I feel happy and excited today, but also a bit anxious about tomorrow."

analyze_emotion(user_input)

ーーーーーーーーーーーーーー

ソースコードの使用条件がありますが、今までにない概念なので暫定的にAll People Happy Policyとします。それについては後で説明します。


Policyについてはこちらの記事を参考にしてください。