JavaScript 语言分析库:Personify.js

jopen 11年前

Personify.js 是一个 JavaScript 库,可以让你轻松访问 IBM Watson特性并利用 推ter 的数据。IBM Watson 提供很多高级的语言分析工具,而 推ter 是最受欢迎的基于文本的通讯平台。

当前版本实现了:

  • Watson User Modeling service which extracts cognitive and social characteristics, including Big Five, Values, and Needs, from communications data provided.
  • Watson Machine Translation service which converts text input in one language into a desired language for the end user. Translation is available for English, Brazilian Portuguese, Spanish, French and Arabic.
  • 推ter REST API.
  • 推ter Streaming API.

使用方法:

var Personify = require('personify');     // For every service you use through Watson, IBM will provide you with a separate set of   // OAuth credentials. See below to find out where to get these credentials.  var config = {  // example credentials for Watson Machine Translation service      translateConfig : {          service_url:          '...',          service_username:     '...',          service_password:     '...'      },  // example credentials for Watson User Modeling service      personalityConfig : {          service_url:          '...',          service_username:     '...',          service_password:     '...'      },  // example credentials for 推ter API      推terConfig : {          consumer_key:         '...',          consumer_secret:      '...',          access_token:         '...',          access_token_secret:  '...'      }  };     //  // Instantiate a new Personify object and pass in OAuth credentials   // inside of an object literal  //  var P = new Personify(config);     //  // Use Watson to discover personality traits, values and needs for a 推ter user  // '@' can be used before a username, but is not required (e.g. '@userName')  //  var params1 = {                   screen_name: 'userName',                  count: 100                };     P.userPersonify( params1 , function (data, error) {      console.log(data, error);  });     //  // Watson provides a personality assessment of the combined input of tweets in a   // user's home timeline. Includes tweets from friends and accounts the user is following,   // and their retweets  //  var params2 = {                   count: 100,                   exclude_tweets: true                 };     P.homePersonify( params2, function (data, error) {      console.log(data, error);  });     //  // Search 推ter with a (required) keyword. Accepts all of 推ter's optional search   // parameters and a few additional ones we've created for your convenience.  //  var params3 = {                   q: '#JavaScript',                   geocode: 'San Francisco' //geocode takes most major US cities and all US states                };                         //see this method in API for a full list of city and state shortcut terms     P.searchPersonify( params3 , function (data, error) {    console.log(data, error);  });     //  // Grab a number of Tweets in a specified language and get back both the original text and its   // translation in another destination language. Most of the search parameters available   // here are the same as those in our searchTweet method.  //  var params4 = {                   q: 'JavaScript',                   fromLanguage: 'ar', // Translate from Arabic                  toLanguage: 'en',   // to English                  outputType: 'text'  // Choose from text, json or XML                };     P.searchTranslate( params4 , function (data, error) {      console.log(data, error);  });     //  // Input a 推ter handle and get back their tweets translated  //  var params5 = {                  screen_name: 'userName',                  fromLanguage: 'en',                  toLanguage: 'fr',                  outputType: 'text'                };     P.userTranslate( params5, function(data, error){      console.log(data, error);  });     //  // Get tweets from your home timeline and have them translated into another language  //  var params6 = {                  count: 150,                  fromLanguage: 'en',                  toLanguage: 'fr',                  outputType: 'json'                };     P.homeTranslate( params6, function(data, error){      console.log(data, error);  });     //  // Find public tweets talkng about the Large Hadron Collider using 推ter's Streaming API and   // translate them into another language  //  var params7 = {                  track: '推ter',                  fromLanguage: 'en',                  toLanguage: 'fr',                  outputType: 'text'                };     P.streamTranslate( params7, function(data, error){      console.log(data, error);  });

项目主页:http://www.open-open.com/lib/view/home/1421469734156