PythonでWatson APIのPersonality Insightsを使う
目的
Watson API の Personality Insights で文書作成者の特徴分析・性格分析がしたい!
参考リンク
personality-insights - API Reference | IBM Watson Developer Cloud
動作環境
Python 2.7.13 :: Anaconda 4.3.1 (64-bit)
やりかた
1.Python で Watson API を使えるようにする
コマンドプロンプトから以下を実行
> pip install watson-developer-cloud
2.ユーザ名とパスワードを確認
1) Bluemix にログイン
2) Personality Insights サービスにログイン
3) サービス資格情報
4) 資格情報の表示 で "username" と "password" を確認
3.分析
Python で以下を実行
# -*- coding: utf-8 -*
import json
from watson_developer_cloud import PersonalityInsightsV3
personality_insights = PersonalityInsightsV3(
version='2016-10-20',
username='ユーザ名',
password='パスワード')
with open('テキストファイル名') as textdata:
profile = personality_insights.profile(textdata.read(), content_language='ja', accept_language='ja')
for x in profile['needs']:
print x['trait_id'], x['percentile']
for x in profile['values']:
print x['trait_id'], x['percentile']
for x in profile['personality']:
print x['trait_id'], x['percentile']
for x in profile['warnings']:
print x['message']
Good Luck !!!