Skip to content

Commit 96af50f

Browse files
amygdalajmdobry
authored andcommitted
update the sentiment threshold; fix a typo in some commented-out code. (#341)
1 parent 36136fa commit 96af50f

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

cloud-language/snippets/slackbot/demo_bot.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,10 @@ const db = new sqlite3.cached.Database(path.join(__dirname, './slackDB.db'));
5959

6060
// the number of most frequent entities to retrieve from the db on request.
6161
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;
6466
const SEVEN_DAYS_AGO = 60 * 60 * 24 * 7;
6567

6668
const ENTITIES_BASE_SQL = `SELECT name, type, count(name) as wc
@@ -218,10 +220,11 @@ function analyzeSentiment (text) {
218220
.then((results) => {
219221
const sentiment = results[0];
220222

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) {
223226
// console.log('Sentiment: positive.');
224-
// } else if (results <= -SENTIMENT_THRESHOLD) {
227+
// } else if (sentiment <= -SENTIMENT_THRESHOLD) {
225228
// console.log('Sentiment: negative.');
226229
// }
227230

@@ -237,10 +240,11 @@ function handleAmbientMessage (bot, message) {
237240
.then(() => analyzeSentiment(message.text))
238241
.then((sentiment) => {
239242
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.
241244
bot.reply(message, ':thumbsup:');
242245
} 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.
244248
bot.reply(message, ':thumbsdown:');
245249
}
246250
});

0 commit comments

Comments
 (0)