mcpField
S
sentiment-analyzer

sentiment-analyzer

github.com/dkyazzentwatwaデータ・データベース12690 回インストール30 週間前に更新
リポジトリ

sentiment-analyzer について

sentiment-analyzerは、テキストの感情、情動、主観性を評価するPythonツールとコマンドラインツールです。単一テキストとCSVの一括処理に対応し、分布や時系列のグラフも作成できます。

主な機能

  1. 01ポジティブ・ネガティブ・中立の分類
  2. 02極性と信頼度のスコア
  3. 03主観性と感情の検出
  4. 04CSVの一括処理
  5. 05分布・推移・ワードクラウドの作成

活用シーン

  1. 01商品レビューの感情集計
  2. 02日付付き投稿の感情推移追跡
  3. 03顧客フィードバックの分類

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/dkyazzentwatwa/chatgpt-skills --skill sentiment-analyzer

インストール後、Claude Code で/sentiment-analyzerを入力して読み込まれたか確認します。

同梱ファイルscripts/requirements.txtscripts/sentiment_analyzer.py

詳細

感情分析

詳細なスコアリング、感情の検出、可視化機能を使ってテキストの感情を分析します。単一のテキストや CSV ファイルを処理したり、時間の経過に伴う感情の傾向を追跡したりできます。

クイックスタート

from scripts.sentiment_analyzer import SentimentAnalyzer

# Analyze single text
analyzer = SentimentAnalyzer()
result = analyzer.analyze("I love this product! It's amazing.")
print(f"Sentiment: {result['sentiment']} ({result['score']:.2f})")

# Batch analyze CSV
results = analyzer.analyze_csv("reviews.csv", text_column="review")
analyzer.plot_distribution("sentiment_dist.png")

機能

  • 感情分類:肯定的、否定的、中立を信頼度とともに分類します
  • 極性スコアリング:-1.0(否定的)から +1.0(肯定的)まで
  • 主観性の検出:客観的な内容か主観的な内容かを判定します
  • 感情の検出:喜び、怒り、悲しみ、恐れ、驚き
  • バッチ処理:任意のテキスト列を含む CSV ファイルを分析します
  • 傾向分析:時間の経過に伴う感情を追跡します
  • 可視化:分布図、傾向グラフ、ワードクラウド

API リファレンス

初期化
analyzer = SentimentAnalyzer()
単一テキストの分析
result = analyzer.analyze("This is great!")
# Returns:
# {
#     'text': 'This is great!',
#     'sentiment': 'positive',  # positive, negative, neutral
#     'score': 0.85,            # -1.0 to 1.0
#     'confidence': 0.92,       # 0.0 to 1.0
#     'subjectivity': 0.75,     # 0.0 (objective) to 1.0 (subjective)
#     'emotions': {'joy': 0.8, 'anger': 0.0, ...}
# }
バッチ分析
# From list
texts = ["Great product!", "Terrible service.", "It's okay."]
results = analyzer.analyze_batch(texts)

# From CSV
results = analyzer.analyze_csv(
    "reviews.csv",
    text_column="review_text",
    output="results.csv"
)
傾向分析
# Analyze sentiment over time
results = analyzer.analyze_csv(
    "posts.csv",
    text_column="content",
    date_column="posted_at"
)
analyzer.plot_trend("sentiment_trend.png")
可視化
# Sentiment distribution
analyzer.plot_distribution("distribution.png")

# Sentiment over time
analyzer.plot_trend("trend.png")

# Word cloud by sentiment
analyzer.plot_wordcloud("positive", "positive_words.png")

CLI の使い方

# Analyze single text
python sentiment_analyzer.py --text "I love this product!"

# Analyze file
python sentiment_analyzer.py --input reviews.csv --column review --output results.csv

# With visualization
python sentiment_analyzer.py --input reviews.csv --column text --plot distribution.png

# Trend analysis
python sentiment_analyzer.py --input posts.csv --column content --date posted_at --trend trend.png
CLI 引数
引数説明デフォルト
--text分析する単一のテキスト-
--input入力 CSV ファイル-
--columnテキスト列名text
--date傾向分析用の日付列-
--output出力 CSV ファイル-
--plot分布図を保存-
--trend傾向グラフを保存-
--format出力形式(json、csv)json

例

製品レビューの分析
analyzer = SentimentAnalyzer()
results = analyzer.analyze_csv("amazon_reviews.csv", text_column="review")

# Summary statistics
positive = sum(1 for r in results if r['sentiment'] == 'positive')
negative = sum(1 for r in results if r['sentiment'] == 'negative')
print(f"Positive: {positive}, Negative: {negative}")

# Average sentiment score
avg_score = sum(r['score'] for r in results) / len(results)
print(f"Average sentiment: {avg_score:.2f}")
ソーシャルメディアのモニタリング
analyzer = SentimentAnalyzer()

# Analyze tweets with timestamps
results = analyzer.analyze_csv(
    "tweets.csv",
    text_column="tweet_text",
    date_column="created_at"
)

# Plot sentiment trend
analyzer.plot_trend("twitter_sentiment.png", title="Brand Sentiment Over Time")
顧客フィードバックの分類
analyzer = SentimentAnalyzer()

feedback = [
    "Your support team was incredibly helpful!",
    "The product broke after one day.",
    "Shipping was on time.",
    "I'm extremely disappointed with the quality.",
    "It works as expected, nothing special."
]

for text in feedback:
    result = analyzer.analyze(text)
    print(f"{result['sentiment'].upper():8} ({result['score']:+.2f}): {text[:50]}")

出力形式

JSON 出力
{
  "text": "I love this product!",
  "sentiment": "positive",
  "score": 0.85,
  "confidence": 0.92,
  "subjectivity": 0.75,
  "emotions": {
    "joy": 0.82,
    "anger": 0.02,
    "sadness": 0.01,
    "fear": 0.03,
    "surprise": 0.12
  }
}
CSV 出力
テキスト感情スコア信頼度主観性
素晴らしい製品です!positive0.850.910.80
ひどい……negative-0.720.880.65

依存関係

textblob>=0.17.0
pandas>=2.0.0
matplotlib>=3.7.0

制限事項

  • 英語に最適化されています(他の言語では精度が低下する場合があります)
  • 皮肉やアイロニーを正確に検出できない場合があります
  • 文脈に依存する感情を検出できない場合があります
  • 短いテキスト(5 語未満)は信頼度が低くなります

コメント