Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

117
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda