sentiment-parser
v0.0.106
Published
The sentiment-parser package is used to easily parse sentiments from sentences, using a simple one-liner.
Downloads
17
Maintainers
Readme
Sentiment Parser
Description
The sentiment-parser package is used to easily parse sentiments from sentences, using a simple one-liner.
Backend
The package currently uses both an offline package and the IBM Watson API to gather the results. It will also try to guess a best answer, based on the two differing results.
Prepare
You will need to secure credentials from IBM. To do that:
- Sign up for IBM Cloud.
- Once you have an accound - go to the Natural Language Understanding service page.
- Click the "Create" button.
- Click the "Service Credentials" tab on the Natural Language Understanding page in your IBM Cloud dashboard to view your credentials.
- Do the same for the ToneAnalyzer service
Initialization
const { Parser } = require('sentiment-parser');
const parser = new Parser();
parser.setCredentials({
nlAnalyzer: {
username: '{your-api-username}',
password: '{your-api-password}',
},
toneAnalyzer: {
username: '{your-api-username}',
password: '{your-api-password}',
}
});
Usage
parser.parseSentiment(userInput).then(response => {
// response.score is a value between -1 to 1
// response.label is "negative" or "positive"
}
parser.parseEmotion(`I hate this`).then(parsedTone => {
// parsedTone.watsonTone.strongestTone contains the strongest tone
// parsedTone.watsoneTone.allTones contains an array of all the recognized tones
// Each tone has a tone_id, tone_name and a score (from 0 to 1)
}