Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/naive_bayes.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,18 @@ Naivebayes.prototype.frequencyTable = function (tokens) {

/**
* Dump the classifier's state as a JSON string.
* @param {Boolean} Optionally format the serialized JSON output for easier human consumption
* @return {String} Representation of the classifier.
*/
Naivebayes.prototype.toJson = function () {
Naivebayes.prototype.toJson = function (prettyPrint) {
var state = {}
var self = this
var prettyPrintSpaces = prettyPrint ? 2 : 0
STATE_KEYS.forEach(function (k) {
state[k] = self[k]
})

var jsonStr = JSON.stringify(state)
var jsonStr = JSON.stringify(state, null, prettyPrintSpaces)

return jsonStr
}
Expand Down