Guest User

Untitled

a guest
Apr 3rd, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. require("dotenv").config();
  2. const readline = require('readline');
  3. const PersonalityInsightsV3 = require('watson-developer-cloud/personality-insights/v3');
  4. const personality_insights = new PersonalityInsightsV3({
  5. username: process.env.PERSONALITY_INSIGHTS_USERNAME,
  6. password: process.env.PERSONALITY_INSIGHTS_PASSWORD,
  7. version_date: process.env.PERSONALITY_INSIGHTS_VERSION_DATE
  8. });
  9. const PersonalityTextSummaries = require('personality-text-summary');
  10. const v3EnglishTextSummaries = new PersonalityTextSummaries({
  11. locale: 'en',
  12. version: 'v3'
  13. });
  14.  
  15.  
  16. const rl = readline.createInterface({
  17. input: process.stdin,
  18. output: process.stdout
  19. });
  20.  
  21. rl.question('Please enter a short paragraph for Watson to analyze...', (text) => {
  22.  
  23. let params = {
  24. content: text,
  25. content_type: 'text/plain',
  26. raw_scores: true,
  27. consumption_preferences: true
  28. };
  29.  
  30. personality_insights.profile(params, function (error, response) {
  31. if (error)
  32. console.log('Error:', error);
  33. else
  34. console.log(getTextSummary(response));
  35. //console.log(JSON.stringify(response, null, 2));
  36. });
  37.  
  38. rl.close();
  39. });
  40.  
  41. const getTextSummary = personalityProfile => {
  42. let textSummary = v3EnglishTextSummaries.getSummary(personalityProfile);
  43. if (typeof (textSummary) !== 'string') {
  44. console.log("Could not get summary.");
  45. } else {
  46. return textSummary;
  47. }
  48. };
Add Comment
Please, Sign In to add comment