I have a resource that is very similar to the WordNet, where I can retrieve the a of synonyms of a given word. The goal is given a seed word, for example "car", I want to retrieve all possible transitive synonyms, for example, in the first call I get the synonyms of "car", which is "auto", "motocar", then I retrieve all the synonyms of "auto", and "motocar" and etc. Obviously the fechting is a recursive process, and retrieving synonyms is performed in async call
loadSynonyms("car", [], function(err, res) {
console.log(res)
});
function loadResultSynonyms(synonyms, results, callback2) {
async.series([
function(callback) {
async.eachSeries(results, function(res, callbackDone) {
if (synonyms.indexOf(res) == -1) {
synonyms.push(res)
redisfetch(res, function(err, results) {
loadSynonyms(synonyms, results)
callbackDone();
});
} else {
callbackDone();
}
})
},
function(callback) {
callback2(null, synonyms)
}
])
}
So, here I expect that at the end synonyms list will contain all synonyms, but it doesn't work. I think I messed up with recursion and async calls.
I would appreciate if you could help me.