JavaScript 語言分析庫:Personify.js
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); });
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!