Permalink
Browse files

Fixing bug where the text class returns words when no text is supplied.

  • Loading branch information...
1 parent ffb8876 commit 3f8616783f3f0f560ca436f188c5d1edb79da79a @vesln committed Jan 21, 2012
Showing with 13 additions and 4 deletions.
  1. +1 −3 lib/bot.js
  2. +11 −0 lib/index.js
  3. +1 −1 lib/text.js
View
@@ -32,9 +32,7 @@ function Bot(db, defaults) {
*/
Bot.prototype.answer = function(sentence, cb) {
var text = new Text(sentence);
- var results = null;
- if (!text.words().length) return null;
- results = this._db.findAll(text);
+ var results = this._db.findAll(text);
if (!results.length) results = this._defaults;
return this.random(results);
};
View
@@ -0,0 +1,11 @@
+/*!
+ * Bot - Feeling lonely? You personal bot is here.
+ *
+ * Veselin Todorov <hi@vesln.com>
+ * MIT License.
+ */
+
+/**
+ * Exposing the module.
+ */
+module.exports = require('./bot');
View
@@ -33,7 +33,7 @@ Text.prototype.analyze = function(text) {
text.split(/\s+/).forEach(function(word) {
word = word.toLowerCase().replace(/\W+/g, '');
- if (~stopWords.indexOf(word)) return;
+ if (~stopWords.indexOf(word) || !word) return;
words.push(word);
});

0 comments on commit 3f86167

Please sign in to comment.