Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

116
Vistas
How to use require js to do a sentiment analysis on a bunch of text

Background

I have a json file called Dictionary.js,it contains word objects. Each word has an integer value assigned to it based on whether its positive or negative. If the word is positive then its value must be greater than 0, if it is negative then the value assigned to that word must be less than 0. If a word is not found to exist in this array then it is assigned a default value of 0. The javascript file I have sums up all the values of the words and gives a resultant score that I must use to analyze if the sentiment of the comment was negative, neutral or positive.

Implementation

After learning that I cannot read the javascript object notation file directly then I decided to use require.js so that I can be able to use the requirejs(['path.json'],function(data){}) to read it.

I added an onkeydown() event listener to the input entry that accepts the comments from user and attached a javascript function called sentiments that is supposed to alert the score as the user continue to type words. There are a lot of lambda functions to handle the word processing from the json object but my code doesn't work for some reason please help...

<!--dependency for require.js-->
<head>
<script src='require.js'></script>
</head>
<body>
<input type="text" id="user_comment" onkeydown="sentiments()"/>
<script>
let comment=document.getElementById("user_comment").value;
function sentiments(){
requirejs(["Dictionary.json"],function(data){
let AFINN=json.parse(data);
const tokenize = text => text.toLowerCase().split(" ");

const deleteUselessChars = word => word.replace(/[^\w]/g, "");

const rateWord = word => (word in AFINN ? AFINN[word] : 0);

const sum = (x, y) => x + y;

const analyseText = text =>
tokenize(text)
.map(deleteUselessChars)
.map(rateWord)
.reduce(sum);

});
//supposed to get integer alerts from this
alert(analyseText(comment));
}
</script>
</body>

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda