Different WPI v3 results from Python and Node.js -
i using watson personality insights results body of text. results getting node.js personality insights demo different results when using python sdk.
python script:
with open('input_file.txt', encoding='utf-8') input_file: profile = personality_insights.profile( input_file.read(), content_type='text/plain;charset=utf-8', raw_scores=true, consumption_preferences=true) print(profile)
python output: (adding agreeableness scores stay under character limit)
{ "trait_id": "big5_agreeableness", "name": "agreeableness", "category": "personality", "percentile": 0.2641097108346445, "raw_score": 0.717124182764663, "children": [{ "trait_id": "facet_altruism", "name": "altruism", "category": "personality", "percentile": 0.5930367181429955, "raw_score": 0.7133462509414262 }, { "trait_id": "facet_cooperation", "name": "cooperation", "category": "personality", "percentile": 0.49207238025136585, "raw_score": 0.5781918028043768 }, { "trait_id": "facet_modesty", "name": "modesty", "category": "personality", "percentile": 0.7504251965616365, "raw_score": 0.4840369062774408 }, { "trait_id": "facet_morality", "name": "uncompromising", "category": "personality", "percentile": 0.4144135962141314, "raw_score": 0.6156094284542545 }, { "trait_id": "facet_sympathy", "name": "sympathy", "category": "personality", "percentile": 0.8204286367393345, "raw_score": 0.6984933017082747 }, { "trait_id": "facet_trust", "name": "trust", "category": "personality", "percentile": 0.5357101531393991, "raw_score": 0.5894943830064112 } ] }
node.js script:
fs.readfile('input_file.txt', 'utf-8', function (err,data) { var params={}; params.text=data; params.content_type='text/plain; charset=utf-8'; params.raw_scores=true; params.consumption_preferences=true; personality_insights.profile(params, function(error, response) { console.log(json.stringify(response)); }); });
node.js output:
{ "id": "agreeableness", "name": "agreeableness", "category": "personality", "percentage": 0.2798027409516949, "sampling_error": 0.101059064, "children": [{ "id": "altruism", "name": "altruism", "category": "personality", "percentage": 0.597937110939136, "sampling_error": 0.07455418080000001 }, { "id": "cooperation", "name": "cooperation", "category": "personality", "percentage": 0.46813215597029234, "sampling_error": 0.0832951302 }, { "id": "modesty", "name": "modesty", "category": "personality", "percentage": 0.7661123497302398, "sampling_error": 0.0594182198 }, { "id": "morality", "name": "uncompromising", "category": "personality", "percentage": 0.42178661415240626, "sampling_error": 0.0662383546 }, { "id": "sympathy", "name": "sympathy", "category": "personality", "percentage": 0.8252000440378008, "sampling_error": 0.1022423736 }, { "id": "trust", "name": "trust", "category": "personality", "percentage": 0.5190032062613837, "sampling_error": 0.0600995984 }] }
the input file both same:
operations @ ports in u.s. southeast shut region copes with changing path of 1 hurricane churning toward region. hurricane irma was downgraded category 1 storm pushed through western , central florida, wsj’s arian campo-flores , joseph de avila report. put port tampa bay in path left major trade gateways on atlantic coast, including jacksonville, georgia’s port of savannah , south carolina port of charleston largely outside storm’s strongest force. second category 4 storm reach u.s. season lashed miami area powerful winds , sheets of rain, , both florida coasts preparing severe storm surges , flooding it headed north , toward georgia. storm following after hurricane harvey hit gulf coast , third storm, jose, heading north, the u.s. issued rare waiver of jones act, federal law prohibits foreign ships operating in domestic sea routes, wsj’s costas paris reports. action allow foreign tankers distribute fuel hurricane-stricken areas.
there mismatch in values received 2 approaches. values same both scripts when content_type=text/plain
addition of charset=utf-8
attribute not seem make difference in results received through python code.
as can see, when params set text/plain, watson api suggest use param: accept: application/json
because desired content type of response
, can choose csv
or json
format.
for example:
profile(text, content_type='text/plain', content_language=none, accept='application/json', accept_language=none, raw_scores=false, consumption_preferences=false, csv_headers=false)
important: in example python, set print
profile
, , not use indent
getting basic pretty printing result node return. i think maybe problem return.
so try use print(json.dumps(profile, indent=2))
instead of print(profile)
i did example api reference python , node, , same result.
python example using personality insight:
personality_insights = personalityinsightsv3( version='2016-10-20', username='{username}', password='{password}') open(join(dirname(__file__), './profile.json')) profile_json: profile = personality_insights.profile( profile_json.read(), content_type='application/json', raw_scores=true, consumption_preferences=true) print(json.dumps(profile, indent=2))
node example using personality insight:
var personalityinsightsv3 = require('watson-developer-cloud/personality-insights/v3'); var personality_insights = new personalityinsightsv3({ username: '{username}', password: '{password}', version_date: '2016-10-20' }); var params = { // content items json file. content_items: require('./profile.json').contentitems, consumption_preferences: true, raw_scores: true, headers: { 'accept-language': 'en', 'accept': 'application/json' } }; personality_insights.profile(params, function(error, response) { if (error) console.log('error:', error); else console.log(json.stringify(response, null, 2)); } );
- reference json return python.
- api reference use personality insights.
Comments
Post a Comment