Sentiment Analysis API Tutorial: Build a Customer Review Dashboard
顧客レビューは洞察の金鉱です。しかし、数百件のレビューを手作業で読んで感情(センチメント)を理解する?それは悪夢です。すべてのレビューを数秒で自動的に分析できたらどうでしょうか?
このチュートリアルでは、RapidAPIのAI Text Analyzer APIを使ってリアルタイムのセンチメント分析ダッシュボードを構築する方法を紹介します。
問題
手作業でレビュー分析を行うと、通常は次のようになります。
- マネージャーAがレビューを読むのに2時間かける
- マネージャーBが手作業でカテゴリ分けする
- マネージャーCが繰り返し出てくる不満を見つけようとする
- 処理し終える頃には、データが古くなっている
解決策は?AIで自動化することです。
アーキテクチャ
Customer Reviews (CSV/JSON/API)
↓
[Sentiment Analyzer]
├─ 感情スコア(-1〜1)
├─ 感情の検出
├─ キーワード抽出
└─ 言語の検出
↓
[インタラクティブ・ダッシュボード]
はじめに
- RapidAPI.com にアクセスして無料アカウントを作成する
- AI Text Analyzer API をサブスクライブする
- APIキーをコピーする
Python実装
config.py:
import os
from dotenv import load_dotenv
load_dotenv()
class SentimentAnalyzerConfig:
def __init__(self):
self.api_key = os.getenv('RAPIDAPI_KEY')
self.api_host = 'ai-text-analyzer-api.p.rapidapi.com'
self.base_url = 'https://ai-text-analyzer-api.p.rapidapi.com'
def get_headers(self):
return {
'x-rapidapi-key': self.api_key,
'x-rapidapi-host': self.api_host,
'Content-Type': 'application/json'
}
config = SentimentAnalyzerConfig()
sentiment_analyzer.py:
import requests
from config import config
class SentimentAnalyzer:
def __init__(self):
self.headers = config.get_headers()
self.base_url = config.base_url
def analyze_review(self, text):
payload = {
'text': text,
'language': 'auto',
'include_emotions': True,
'include_keywords': True
}
response = requests.post(
f'{self.base_url}/analyze',
json=payload,
headers=self.headers,
timeout=10
)
if response.status_code == 200:
data = response.json()
return {
'sentiment': data.get('sentiment', {}),
'emotions': data.get('emotions'
返却形式: {"translated": "翻訳されたHTML"}, {}),
'keywords': data.get('keywords', [])
}
return None
def analyze_batch(self, reviews):
results = []
scores = []
for review in reviews:
result = self.analyze_review(review)
if result:
results.append(result)
scores.append(result['sentiment'].get('score', 0))
positive = sum(1 for s in scores if s > 0.1)
negative = sum(1 for s in scores if s < -0.1)
avg = sum(scores) / len(scores) if scores else 0
return {
'total': len(reviews),
'avg_sentiment': avg,
'positive': positive,
'negative': negative,
'neutral': len(scores) - positive - negative,
'details': results
}
JavaScript 実装
const axios = require('axios');
class SentimentAnalyzer {
constructor(apiKey) {
this.client = axios.create({
baseURL: 'https://ai-text-analyzer-api.p.rapidapi.com',
headers: {
'x-rapidapi-key': apiKey,
'x-rapidapi-host': 'ai-text-analyzer-api.p.rapidapi.com'
}
});
}
async analyzeReview(text) {
const { data } = await this.client.post('/analyze', {
text,
language: 'auto',
include_emotions: true,
include_keywords: true
});
return data;
}
返却形式: {"translated": "翻訳されたHTML"}async analyzeBatch(reviews) {
const results = [];
for (const review of reviews) {
const result = await this.analyzeReview(review);
results.push(result);
}
return results;
}
}
module.exports = SentimentAnalyzer;
実運用での成果
| 指標 | Before | After |
|---|---|---|
| レビュー分析にかかる時間 | 週4〜6時間 | 5分 |
| 検知できた問題 | 30〜40% | 95%+ |
| 苦情への対応 | 2〜3日 | 当日 |
| 識別されたキーワード | 手動 | 50+ 自動 |
高度なパターン
ネガティブなレビュー向けアラートシステム
const analyzeAndAlert = async (review) => {
const result = await analyzer.analyzeReview(review);
if (result.sentiment.score < -0.5) {
await notifySlack({
channel: '#customer-alerts',
text: \`Negative review detected: Score \{result.sentiment.score}\`
});
}
};
料金
- Free Tier: 100リクエスト/日 — スタートアップに最適
- Pro($9.99/月): 10,000リクエスト/日 — 本番利用
- Enterprise: 上限はカスタム、SLA
使い始める
お客様をより深く理解する準備はできていますか?
- RapidAPI上のAI Text Analyzer API
- あわせてチェック:Web Scraper Extractor | Instant SEO Audit | AI Content Generator
感情分析やAPI連携について質問があれば、コメントをください!