コード例 #1
0
app.post('/spell-checker/changedict/:id', function(req, res) {
    //console.log(req.body.id);
    dictCode = req.body.singleSelect;

    var pageID = req.params.id;

    collection.findAndModify({
        query: {
            _id: mongojs.ObjectId(pageID)
        },
        update: {
            $set: {
                currentDictionary: dictCode
            }
        },
        new: true
    }, function(err, doc, lastErrorObject) {
        // doc.tag === 'maintainer'
        //console.log(doc._id)
        res.json(doc);
      //  console.log("Page dictionary is: " + doc.currentDictionary);
    });

    //Set the dictionary
    affbuf = fs.readFileSync(__dirname + '/dictionaries/' + dictCode + '.aff');
    dictbuf = fs.readFileSync(__dirname + '/dictionaries/' + dictCode + '.dic');
    hunspell = new nodehun(affbuf, dictbuf);
    ignore = fs.readFileSync(__dirname+'/dictionaries/' + ignoreDict + '.dic');
    hunspell.addDictionary(ignore);


});
コード例 #2
0
    }, 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)

        });
    });
コード例 #3
0
//Dictionary is set to US
var affbuf = fs.readFileSync(__dirname+'/dictionaries/'+ myArgs.a +'.aff');
var dictbuf = fs.readFileSync(__dirname+'/dictionaries/'+ myArgs.a +'.dic');
var ignore = fs.readFileSync(__dirname+'/dictionaries/ignore.dic');
var hunspell = new nodehun(affbuf, dictbuf);
var bodyParser = require('body-parser');
var spellcheck = require('nodehun-sentences');
var docs;
var collection = db.collection(dbConfig.collection);
var siteID = myArgs.d;
var crawlID = myArgs.e;

app.use(bodyParser.json());

//Add dictionary with ignore words
hunspell.addDictionary(ignore);

collection.find({siteId : siteID}, function (err, doc){
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) {