function spellCheckPost(post, callback) { discourse.log('Spellaring psot ' + post.id); var raw = post.raw; spellcheck(dictionary, raw, function (err, typos) { if (err) { discourse.error(err); callback(); } // `typos` is an array, each one containing: // - `word`: the typo (string) // - `suggestions`: list of suggestions (string[]) // - `positions`: list of positions (object[]) typos.forEach(function (typo) { // `typo.positions` contains: // - `from`: start offset (int) // - `to`: end offset (int) // - `length`: length (int) }); discourse.log('Psot ' + post.id + ' spellard'); //Sign the post so we don't spellar it again raw += '\n\n' + spellardSig + ' ' + fullName + '-->'; discourse.editPost(post.id, raw, fullName, function () { callback(null, true); }); }); }
$(whitelist).each(function () { var text = $(this).text(); //remove linebreaks from text text = text.replace(/(\r\n|\n|\r)+/gm, " "); //replace ’ with ' text = text.replace(/’/g, "'"); //replace multiple spaces with a single one text = text.replace(/\s{2,}/g, ' '); //trim text text = text.trim(); if (text.length) { var writeGoodSuggestions = writeGood(text, writeGoodSettings); var spellcheckResolve = null; var promise = new Promise(function (r) { spellcheckResolve = r; }); promises.push(promise); spellcheck(dictionary, text, function (error, spellcheckerSuggestions) { suggestions.push({ text: text, suggestions: { writeGood: writeGoodSuggestions, spelling: spellcheckerSuggestions || [] } }); spellcheckResolve(); }); } });
return new Promise((resolve, reject) => { spellcheck(hunspell, text, (err, typos) => { if (err) { reject(err); } else { resolve(typos); } }); });
}, function(err, doc) { //Return Response var html = sanitizeHtml(doc.html, { allowedTags: [ '' ], textFilter: function(text) { return text + ' '; } }); affbuf = fs.readFileSync(__dirname + '/dictionaries/' + doc.currentDictionary + '.aff'); dictbuf = fs.readFileSync(__dirname + '/dictionaries/' + doc.currentDictionary + '.dic'); hunspell = new nodehun(affbuf, dictbuf); ignore = fs.readFileSync(__dirname+'/dictionaries/' + ignoreDict + '.dic'); hunspell.addDictionary(ignore); console.log("Affbuf:",affbuf); console.log("Dictbuf",dictbuf); spellcheck(hunspell, html, function(err, typos) { // console.log(typos); collection.findAndModify({ query: { _id: mongojs.ObjectId(id) }, update: { $set: { numOfMistakes: typos.length } }, new: true }, function(err, doc, lastErrorObject) { console.log("Page has: " + doc.numOfMistakes + " mistakes"); }); collection.findAndModify({ query: { _id: mongojs.ObjectId(id) }, update: { $set: { spellingMistakes: typos } }, new: true }, function(err, doc, lastErrorObject) { // console.log("Spelling Mistakes are: " + doc.spellingMistakes); res.json(doc); }); //console.log("Typos", typos.length) }); });
doc.forEach(function(item){ console.log("page id: " + item._id); //var html = htmlToText.fromString(item.html, { wordwrap: 130}); var html = sanitizeHtml(item.html, { allowedTags: [ '' ], textFilter: function(text) { return text + ' '; } }); spellcheck(hunspell, html, function(err, typos) { console.log(typos); collection.findAndModify({ query: {_id: mongojs.ObjectId(item._id)}, update: { $set: { numOfMistakes: typos.length } }, new: true }, function (err, doc, lastErrorObject) { // doc.tag === 'maintainer' console.log(doc._id); console.log("Page has: " + doc.numOfMistakes + " mistakes"); }); collection.findAndModify({ query: {_id: mongojs.ObjectId(item._id)}, update: { $set: { currentDictionary: myArgs.a } }, new: true }, function (err, doc, lastErrorObject) { // doc.tag === 'maintainer' console.log("Page dictionary is: " + doc.currentDictionary); }); collection.findAndModify({ query: {_id: mongojs.ObjectId(item._id)}, update: { $set: { spellingMistakes: typos } }, new: true }, function (err, doc, lastErrorObject) { //console.log("Spelling Mistakes are: " + doc.spellingMistakes); }); }); });