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
29 changes: 29 additions & 0 deletions lib/ector.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var concept_network = require('concept-network');
var ConceptNetwork = concept_network.ConceptNetwork;
var ConceptNetworkState = concept_network.ConceptNetworkState;
var rwc = require('random-weighted-choice');
var fs = require('fs');

/**
* ## Ector's constructor
Expand Down Expand Up @@ -342,6 +343,34 @@ Ector.prototype = {
this.cn = new ConceptNetwork();
throw new Error('NewConceptNetwork is not a ConceptNetwork');
}
},

/**
* ### saveCN
* @param {string} file path and name. e.g. /home/ubuntu/node.json
* @return {string|Error} true, or an Error.
*/
saveCN : function (filePath) {
if (typeof filePath !== 'string') {
return new Error("filePath should be a string");
}

fs.writeFileSync(filePath, JSON.stringify(this.cn));
return true;
},

/**
* ### loadCN
* @param {string} file path and name. e.g. /home/ubuntu/node.json
* @return {string|Error} true, or an Error.
*/
loadCN : function (filePath) {
if (typeof filePath !== 'string') {
return new Error("filePath should be a string");
}

Object.merge(this.cn, JSON.parse(fs.readFileSync(filePath, 'utf8')));
return true;
}

};
Expand Down