diff --git a/lib/naive_bayes.js b/lib/naive_bayes.js index 15eb5b2..0270128 100644 --- a/lib/naive_bayes.js +++ b/lib/naive_bayes.js @@ -25,6 +25,9 @@ module.exports.fromJson = function (jsonStr) { } catch (e) { throw new Error('Naivebayes.fromJson expects a valid JSON string.') } + if (typeof parsed.options.tokenizer === 'string') { + parsed.options.tokenizer = eval(parsed.options.tokenizer) + } // init a new classifier var classifier = new Naivebayes(parsed.options) @@ -265,7 +268,12 @@ Naivebayes.prototype.toJson = function () { state[k] = self[k] }) - var jsonStr = JSON.stringify(state) + var jsonStr = JSON.stringify(state, function(key, val) { + if (typeof val === 'function') { + return val.toString() + } + return val; + }) return jsonStr }