CleanCoach
CleanCoach is a clean language coaching bot written in ES6.
Node Usage
CleanCoach can be required just like any other node module.
const Coach = require('CleanCoach');
const clive = new Coach("Clive");
let response = clive.getResponse("user input here");
console.log(response);
The primary ways of interacting with CleanCoach are:
const clive = new Coach("Clive");
clive.getResponse(str, sel);
clive.getProfile();
clive.newSession(false);
clive.reset();
getResponse(str, sel)
Takes an input string (str) and generates a response. getResponse is promise based so you can use .then and .catch etc.
getResponse can also take an optional 'sel' argument, which is another string. If the 'sel' string is present, the 'str' arugment will be used to formulate the reflective statement, and the 'sel' string will be used only to formulate the question. This can be useful for taking a user selected chunk of the 'str' string to use as focus for question creation.
The response is an object with the following structure:
{
data: {},
danger: false,
final: false,
reflection: 'and you want to get better at programming.',
question: 'and what would you like to have happen?',
reply: 'and you want to get better at programming. and what would you like to have happen?',
};
getProfile()
Dumps all the session data into an object which looks like this:
{
"sessions":0,
"iterations":1,
"sessionStartTime":"12:00:33",
"sessionRunTime":4.861,
"firstIssue":["moon"],
"lastIssue":["moon"],
"depthIssue":["moon"],
"json":
[{
"id":"0_1",
"session":0,
"iteration":1,
"time":"12:00:37",
"depth":1,
"category":null,
"question":null,
"originalStr":"I want to go to the moon",
"cleanedStr":"i want to go to the moon",
"tokens":["i","want","to","go","to","the","moon"],
"stats":{
"age":92.2602,
"gender":60.9501,
"past":-0.8187,
"present":-0.0608,
"future":-0.1899,
"optimism":4.90994586,
"affect":5.0639,
"intensity":2.5057,
"POS_P":0.1926,
"POS_E":0.5128,
"POS_R":-0.0735,
"POS_M":0.2261,
"POS_A":0.1846,
"NEG_P":0.1084,
"NEG_E":0.3489,
"NEG_R":0.1705,
"NEG_M":0.1441,
"NEG_A":0.2175
},
"pos":{
"nouns":["moon"],
"verbs":["want","go"],
"entities":[],
"sentences":["i want to go to the moon"],
"adjectives":[]
}
}],
"age":92.2602,
"gender":60.9501,
"past":-0.8187,
"present":-0.0608,
"future":-0.1899,
"optimism":4.90994586,
"affect":5.0639,
"intensity":2.5057,
"POS_P":0.1926,
"POS_E":0.5128,
"POS_R":-0.0735,
"POS_M":0.2261,
"POS_A":0.1846,
"NEG_P":0.1084,
"NEG_E":0.3489,
"NEG_R":0.1705,
"NEG_M":0.1441,
"NEG_A":0.2175
}
newSession(false)
First look at the output of getProfile(). New session will bump the "sessions" number, and reset the following data to a blank state:
clive.info: {
"iterations":0,
"sessionStartTime": null,
"sessionRunTime": 0,
"firstIssue":[],
"lastIssue":[],
"depthIssue":[],
}
newSession will not reset any other profile information. To completely wipe all other profile information, use Coach.reset();
newSession takes one argument, a boolean. If the boolean is true, newSession() will also call getResponse() which will return a response object with a generic clean language question to get the new session started.
Options
CleanCoach has several options you can customise:
const clive = new Coach("Clive");
clive.options = {
debug: false,
maxDepth: 3,
quoteUser: true,
removeSW: false,
trimFirstAnd: false,
trimSecondAnd: false,
};
CLI
npm install -g
will install a command-line interface called 'cleancoach' which can be used in your terminal.
Browser Usage
You can browserify the node module by doing:
npm run build
which will create a standalone coach.js file in the 'dist' folder.
In your main.js:
const coach = new Coach("Clive");
coach.options.debug = false;
coach.options.maxDepth = 3;
coach.options.quoteUser = true;
coach.options.removeSW = false;
coach.options.trimFirstAnd = false;
coach.options.trimSecondAnd = false;
let output = "Sorry, I didn't understand that. Try again."
coach.getResponse(string)
.then(response) {
if (response.reply) {
output = response.reply;
} else if (response.danger) {
output = response.reply;
} else if (response.final) {
coach.reset();
}
}
.catch(error) {
console.error(error);
coach.reset();
}
return output
License
CleanCoach is made available under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3
(C) P. Hughes 2017-18. All rights reserved.
See LICENSE file for full license text