1

I started doing NLP operation for a NodeJS app; The idea is to analyze some text and classify words as a verb, adjective, adverb, etc.

I found wordpos and it responds completely to my needs: https://www.npmjs.com/package/wordpos

I am trying to create a process function to create a keyword list using Wordpos.

My code is:

let content = lines.map(line => {
   let element = line.split("=");
   return {
      name: element[0],
      content: element[1],
      keyword: process(element[1])
   }
});

All functions of Wordpos require a callback. Promises can be used too to do some functions chaining. I understand that its operations need to hit wordnet-db so it works is async. Or I need to make sync calls and get results before going to the next steps of my code.

wordpos.getPOS(text, console.log);
{
  nouns:[],        
  verbs:[],        
  adjectives:[],  
  adverbs:[],     
  rest:[]          
}

I tried to create async/ await calls but it's not working:

async function f(text) {
   return await wordpos.getPOS(text);
}
console.log(f('The angry bear chased the frightened little squirrel'));

And result is:

node api_data.js

Promise { }

Community
  • 1
  • 1
  • Hey welcome to SO! Do you mind editing your question a bit to make it more clear what exactly you are asking? – tehp Mar 02 '19 at 19:27
  • You can't do async things in a sync way. You have to deal with that ... – Jonas Wilms Mar 02 '19 at 19:34
  • check this answer, [link](https://stackoverflow.com/questions/49938266/how-to-return-values-from-async-functions-using-async-await-from-function/49938734#49938734), this is similar to your case – The Reason Mar 02 '19 at 19:35

0 Answers0