#Personify.js
A JavaScript based library that allows easy access to IBM Watson features utilizing Twitter data. IBM Watson has some of the most advanced linguistic analytics tools available today. Twitter is one of the world's most popular text-based communication platforms. Leverage the power of both with minimal effort through Personify.js.
Our current version implements:
- 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.
- Twitter REST API.
- Twitter Streaming API.
##Installing
npm install personify --save
##Usage:
var Personify = require('personify');
var config = {
translateConfig : {
service_url: '...',
service_username: '...',
service_password: '...'
},
personalityConfig : {
service_url: '...',
service_username: '...',
service_password: '...'
},
twitterConfig : {
consumer_key: '...',
consumer_secret: '...',
access_token: '...',
access_token_secret: '...'
}
};
var P = new Personify(config);
var params1 = {
screen_name: 'userName',
count: 100
};
P.userPersonify( params1 , function (data, error) {
console.log(data, error);
});
var params2 = {
count: 100,
exclude_tweets: true
};
P.homePersonify( params2, function (data, error) {
console.log(data, error);
});
var params3 = {
q: '#JavaScript',
geocode: 'San Francisco'
};
P.searchPersonify( params3 , function (data, error) {
console.log(data, error);
});
var params4 = {
q: 'JavaScript',
fromLanguage: 'ar',
toLanguage: 'en',
outputType: 'text'
};
P.searchTranslate( params4 , function (data, error) {
console.log(data, error);
});
var params5 = {
screen_name: 'userName',
fromLanguage: 'en',
toLanguage: 'fr',
outputType: 'text'
};
P.userTranslate( params5, function(data, error){
console.log(data, error);
});
var params6 = {
count: 150,
fromLanguage: 'en',
toLanguage: 'fr',
outputType: 'json'
};
P.homeTranslate( params6, function(data, error){
console.log(data, error);
});
var params7 = {
track: 'twitter',
fromLanguage: 'en',
toLanguage: 'fr',
outputType: 'text'
};
P.streamTranslate( params7, function(data, error){
console.log(data, error);
});
Personify API:
var P = new Personify( config )
Instantiate a new Personify object and pass in a config.
config - Type: Object
At least one set of OAuth credentials from both Twitter and IBM Bluemix are required to use the services Personify.js leverages for you.
P.userPersonify( userName , callback )
userName - Type: String
Required. Represents a Twitter handle. Optionally you can include an '@' before the username.
See here for more information on optional parameters.
P.homePersonify( [params] , callback )
[params] - Type: Object
Key-value pairs inside of [params] are optional, but at least an empty object literal is required.
See here for more information on optional parameters.
P.searchPersonify( { q: input , [params] }, callback )
input Type: String
The 'q' key and its associated value, which is a string, are required. input can be any word you may use to search in Twitter's internal search engine. Any additional search parameters are optional.
See here for more information on optional parameters.
P.searchTranslate( params , callback )
var params = {
q: input,
fromLanguage: 'en',
toLanguage: 'fr',
outputType: 'json'
}
params - Type: Object
input - Type: String
or Number
or Array
Language key:
- 'ar' = Arabic
- 'en' = English
- 'es' = Spanish
- 'fr' = French
- 'pt' = Brazilian Portuguese
Output Types:
All keys shown in params
are required.
See here for more information on optional parameters.
P.userTranslate( params , callback )
var params = {
screen_name: input,
fromLanguage: 'en',
toLanguage: 'fr',
outputType: 'json'
}
params - Type: Object
Please see Language key and Output Types under searchTranslate method in API.
See here for more information on optional parameters.
P.homeTranslate( params , callback)
var params = {
fromLanguage: 'en',
toLanguage: 'fr',
outputType: 'json'
}
All keys in params are required. Optionally you can specify a count
key. This limits the number of Tweets for the search.
count : val
val - Type: Number
val defaults to 20 and has a max of 200.
See here for more information on optional parameters.
P.streamTranslate( params , callback )
var params = {
track: input,
fromLanguage: 'en',
toLanguage: 'fr',
outputType: 'json'
}
All keys in params are required for streaming.
Please see Language key and Output Type options under searchTranslate method in API.
Additionally, optional search parameters that can be added to params:
- locations : boundingBox
- stop : time
boundingBox - Type: Array
boundingBox coordinates can be found here
boundingBox example:
var sanFrancisco = [ '-122.75', '36.8', '-121.75', '37.8' ];
time - Type: Number
time is the number of miliseconds after the stream starts that you want the stream to stop
See here for more information on optional parameters.
callback
Type: Function
- callback takes two parameters, data and error, in that order.
- callback is required for all methods.
##Find your OAuth credentials
Go here to create a Twitter app and get OAuth credentials (if you haven't already): https://dev.twitter.com/apps/new
In order to use IBM Watson, you need to:
##How do I run the tests?
To make the tests pass you will need to fill out the file: config.js
inside the tests folder.
To run the tests:
npm test
Contributing
See
To Do
- Expand library with more Watson services
Development Team
Example Application
Our PersonifyApp grabs tweets based on a keyword search and geolocation parameters and returns a Big Five assessment based on those tweets. It then compares that local result to the US in general. A company for example, might be interested to know about the collective Big Five traits of people who are talking about their products, services or brand.
Release History
- 1.0.1 README.md updated
- 1.0.0 Initial release