I have to check a string with more strings through api, I am using request module for get Request. The api request is stored in an array, after completion of all requests i am using callback to send prepared list. but I am getting empty list from for loop. Where I am going wrong? Please tell me.
var list = ['Mobiles with best', 'what is a processor', 'what do you mean by', 'show me poular phones', 'show me best phones', 'Show me the phones with best', 'phones better than', 'show me thephones released', 'where can i find', 'what is the lowest price of', 'Why are mobiles ranked this way?', 'Why only these features are considered for ranking?', 'can you tell me moreabout', 'Do you know anything about', 'What are the highlights of', 'Why is', 'How good is', 'How good are the reviews of', 'What is great about', 'What are people talking about', 'Give me the reviews of', 'What is the logic ?', 'What is the basis of your ranking?', 'How did you rank them?', 'how did you shortlist this?', 'help me understand the scores better',
'Show me models better than', 'Show me devices more advanced when compared to', 'Give me mobiles with better specs than', 'what is the best phone in the list?']
var phrase1 =" mobiles with best";
function find(callback) {
var semantic_list = []
for (var i in list) {
phrase1 = querystring.escape(phrase1)
var phrase2 = querystring.escape(list[i])
var query_string = "http://swoogle.umbc.edu/SimService/GetSimilarity?operation=api&phrase1=" + phrase1 + "&phrase2=" + phrase2;
request(query_string, function (error, response, body) {
if (!error && response.statusCode == 200) {
//console.log(body) // Show the HTML for the Google homepage.
semantic_list.push(body)
}
})
console.log(semantic_list)
if( i == list.length -1){
console.log(semantic_list)
callback && callback(semantic_list)
}
}
}
find(function(data){
"use strict";
console.log(data);
})