vendredi 27 août 2021

Uncaught TypeError: natural.WordTokenizer is not a function when trying to tokenize a word in Javascript

I have been trying to make a function that tokenizes and stems an input sentence, but it throws this couple of errors:

Uncaught TypeError: natural.WordTokenizer is not a function

Uncaught SyntaxError: expected expression, got '<'

The code that I'm using is this:

function preprocess(data) {
  var natural = require(['natural']);
  var tokens = natural.WordTokenizer().tokenize(data); 
  stemmer = natural.PorterStemmer(data);
  var outData = stemmer.stem(tokens);
  return outData; 
}

I would like to find a solution to this problem soon.




Aucun commentaire:

Enregistrer un commentaire