morungos/wordnet

Maximum call stack size exceeded

Closed this issue · 3 comments

Hello, I got this:

C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\lib\wordnet.js:596
      reducer = function(previous, current, next) {
                        ^

RangeError: Maximum call stack size exceeded
    at reducer (C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\lib\wordnet.js:596:25)
    at C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\node_modules\async\lib\async.js:269:13
    at iterate (C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\node_modules\async\lib\async.js:146:13)
    at Object.async.eachSeries (C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\node_modules\async\lib\async.js:162:9)
    at Object.async.reduce (C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\node_modules\async\lib\async.js:268:15)
    at _validForms (C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\lib\wordnet.js:605:20)
    at reducer (C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\lib\wordnet.js:597:16)
    at C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\node_modules\async\lib\async.js:269:13
    at iterate (C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\node_modules\async\lib\async.js:146:13)
    at Object.async.eachSeries (C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\node_modules\async\lib\async.js:162:9)
    at Object.async.reduce (C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\node_modules\async\lib\async.js:268:15)
    at _validForms (C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\lib\wordnet.js:605:20)
    at reducer (C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\lib\wordnet.js:597:16)
    at C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\node_modules\async\lib\async.js:269:13
    at iterate (C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\node_modules\async\lib\async.js:146:13)
    at Object.async.eachSeries (C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\node_modules\async\lib\async.js:162:9)
    at Object.async.reduce (C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\node_modules\async\lib\async.js:268:15)
    at _validForms (C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\lib\wordnet.js:605:20)
    at reducer (C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\lib\wordnet.js:597:16)
    at C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\node_modules\async\lib\async.js:269:13
    at iterate (C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\node_modules\async\lib\async.js:146:13)
    at Object.async.eachSeries (C:\Users\Porcodio\Documents\GitHub\wikipedia-article-analyzer\node_modules\node-wordnet\node_modules\async\lib\async.js:162:9)

running this:

const lemmatizeNoun = (noun, cb) => {
  wordnet.validFormsAsync(noun).then((results) => {
    if (results.length > 0) {
      for (var i = 0; i < results.length; i++) {
        if (results[i].slice(-1) === 'n') {
          lemmatizedNouns.push(results[i].substring(0, results[i].length - 2))
          break
        }
      }
    }
    cb(null, 'Lemmatize noun')
  })
}

const lemmatizeNouns = (_nouns, cb) => {
  _nouns = _nouns.map((noun) => {
    return noun.toLowerCase()
  })
  async.each(
    nouns,
    lemmatizeNoun,
    (err, res) => {
      if (err) throw err
      else {
        cb(null, 'Lemmatize nouns')
      }
    }
  )
}

Can someone help me?

Thank you!

I found the issue: I was passing to the function malformed words containing special characters.
I think it crashed on sharp symbol.

Wonderful that you found this. It would be also really great if you could give me an example? Was it just the # token all alone? Then I can resolve the issue permanently?

@morungos I think it's the # because you used it as separator in the return value (eg. 'be#v'), but you should investigate a little bit deeper to be sure.

As you can see form this:

var WordNet = require("node-wordnet")
var wordnet = new WordNet({cache:true})

var word = '#' // RangeError: Maximum call stack size exceeded
var word = 'aaa#aaa' // Ok
var word = '#aaa' // Ok
var word = 'aaa#' // RangeError: Maximum call stack size exceeded

wordnet.validFormsAsync(word).then((results) => {
  console.log(results);
})

the problem seems to be the # at the end of the string.
I tried other special characters like \, @, ?, * but they seems to be ok. :)