Skip to content

Commit

Permalink
refactor #9: fix index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiomrebelo committed Jan 28, 2023
1 parent 9432f61 commit a8168fc
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import express from 'express';
import dotenv from 'dotenv';

import cors from 'cors';
import {setup, classification, lexicon} from "./nlp-utils/nlp_utils.mjs";
import * as CLASSIFIER from "./nlp-utils/ml-emotion-analysis/ml-emotion-analysis.mjs";
import * as LEXICON from "./nlp-utils/lexicon-emotion-analysis/lexicon-emotion-analysis.mjs";
import sentenceTokeniser from "./nlp-utils/sentence-tokeniser/sentence-tokeniser.mjs";

const APP = express();
Expand All @@ -15,9 +16,10 @@ APP.use(express.urlencoded({extended: true}));
APP.use(express.static('src/public'));


APP.listen(PORT, () => {
APP.listen(PORT, async () => {
await CLASSIFIER.config(process.env.LANGUAGE_TRANSLATOR_IAM_APIKEY, process.env.LANGUAGE_TRANSLATOR_URL);
await LEXICON.config(process.env.MW_API_KEY, process.env.LANGUAGE_TRANSLATOR_IAM_APIKEY, process.env.LANGUAGE_TRANSLATOR_URL);
console.info(`👂at port ${PORT}`);
setup(process.env.MW_API_KEY, process.env.LANGUAGE_TRANSLATOR_IAM_APIKEY, process.env.LANGUAGE_TRANSLATOR_URL);
});

APP.get("/lines/:delimiter/:lang/:input/", async (req, res) => {
Expand Down Expand Up @@ -53,6 +55,7 @@ const _sentenceTokenizer = async (text) => {
return sentenceTokeniser(text);
}

// TODO: NLP UTILS..
const _lexiconGlobalResults = async (sentences) => {

// compute global lexicon value
Expand All @@ -77,13 +80,13 @@ const _lexiconGlobalResults = async (sentences) => {
const analysis = async (sentences = [], lang) => {
const text = sentences.flat().join(' ');
// classification analysis
const classificationResults = await classification(text, lang);
const classificationResults = await CLASSIFIER.classification(text, lang);
if (!classificationResults.success) return [400, errHandler(400, `Error in the classification method`)];

// lexicon-based analysis
let lexiconResults = { "global": null, "sentences": [] };
for (const sentence of sentences) {
const res = await lexicon(sentence, lang, false);
const res = await LEXICON.lexicon(sentence, lang, false);
lexiconResults.sentences.push(res);
if (!res.success) return [400, errHandler(400, `Error in the lexicon-based method (msg: ${res.msg})`)];;
}
Expand Down

0 comments on commit a8168fc

Please sign in to comment.