'grammar & spell checking in nodejs
How to check spelling mistakes, grammar & punctuation errors, use of greetings & short keywords and total time to complete each single chat session in socket.io express mongoose chat application ?
Here is my code, I am successful with spell-checker, but not able to check rest of the things which i have mentioned,
// Grammar check for Message to user gingerbread(data.message, { /** options to override **/ }, function (err, text, result) { if (!err) { var grammar_result = { text: text, result: result }
// Insert message in Databae
chats.find({
'uid': data.uid,
'aid': data.aid
}).exec(function (err, userChat) {
if (userChat.length <= 0) {
// first time user chat this condition call
var messages_body = {
message: data.message,
message_details: data.message_detail,
grammar: grammar_result,
type: data.type
};
var chatsData = new chats();
chatsData.uid = data.uid;
chatsData.aid = data.aid;
chatsData.cid = data.cid;
chatsData.messages = messages_body;
chatsData.save(function (err, saveData) {
// call function : chatBot
botMessage();
});
} else {
// already user is chat this condition call
if (userChat[0]) {
var messages_body = {
message: data.message,
message_details: data.message_detail,
grammar: grammar_result,
type: data.type
};
var fieldsToSet = {
$push: {
messages: messages_body
}
};
var options = {
new: true
};
chats.findByIdAndUpdate(userChat[0]._id, fieldsToSet, options, function (err, data) {
// call function : chatBot
botMessage();
});
}
}
});
}
});
Solution 1:[1]
Try textgears-api It has a sample and development ability to convert and check the grammar of the application.
import textgears from 'textgears-api';
const textgearsApi = textgears('YOUR_KEY', {language: 'en-US'});
textgearsApi.checkGrammar('I is a engineer')
.then((data) => {
for (const error of data.response.errors) {
console.log('Error: %s. Suggestions: %s', error.bad, error.better.join(', '));
}
})
.catch((err) => {});
Follow the git repo for more information
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Pulasthi Aberathne |