@@ -59,8 +59,10 @@ const db = new sqlite3.cached.Database(path.join(__dirname, './slackDB.db'));
59
59
60
60
// the number of most frequent entities to retrieve from the db on request.
61
61
const NUM_ENTITIES = 20 ;
62
- // The magnitude of sentiment of a posted text above which the bot will respond.
63
- const SENTIMENT_THRESHOLD = 30 ;
62
+ // The threshold of sentiment score of a posted text, above which the bot will
63
+ // respond. This threshold is rather arbitrary; you may want to play with this
64
+ // value.
65
+ const SENTIMENT_THRESHOLD = 0.3 ;
64
66
const SEVEN_DAYS_AGO = 60 * 60 * 24 * 7 ;
65
67
66
68
const ENTITIES_BASE_SQL = `SELECT name, type, count(name) as wc
@@ -218,10 +220,11 @@ function analyzeSentiment (text) {
218
220
. then ( ( results ) => {
219
221
const sentiment = results [ 0 ] ;
220
222
221
- // Uncomment the following four lines to log the sentiment to the console:
222
- // if (results >= SENTIMENT_THRESHOLD) {
223
+ // Uncomment the following lines to log the sentiment to the console:
224
+ // console.log(`Sentiment: ${sentiment}`)
225
+ // if (sentiment >= SENTIMENT_THRESHOLD) {
223
226
// console.log('Sentiment: positive.');
224
- // } else if (results <= -SENTIMENT_THRESHOLD) {
227
+ // } else if (sentiment <= -SENTIMENT_THRESHOLD) {
225
228
// console.log('Sentiment: negative.');
226
229
// }
227
230
@@ -237,10 +240,11 @@ function handleAmbientMessage (bot, message) {
237
240
. then ( ( ) => analyzeSentiment ( message . text ) )
238
241
. then ( ( sentiment ) => {
239
242
if ( sentiment >= SENTIMENT_THRESHOLD ) {
240
- // We have a positive sentiment of magnitude larger than the threshold.
243
+ // We have a positive sentiment score larger than the threshold.
241
244
bot . reply ( message , ':thumbsup:' ) ;
242
245
} else if ( sentiment <= - SENTIMENT_THRESHOLD ) {
243
- // We have a negative sentiment of magnitude larger than the threshold.
246
+ // We have a negative sentiment score of absolute value larger than
247
+ // the threshold.
244
248
bot . reply ( message , ':thumbsdown:' ) ;
245
249
}
246
250
} ) ;
0 commit comments