From 1af240890fea2084e1adeba6c12e55100259d8e7 Mon Sep 17 00:00:00 2001 From: KOSASIH Date: Mon, 22 Jul 2024 20:52:31 +0700 Subject: [PATCH] Create natural-language-processing.js --- routes/natural-language-processing.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 routes/natural-language-processing.js diff --git a/routes/natural-language-processing.js b/routes/natural-language-processing.js new file mode 100644 index 0000000..b1e6af1 --- /dev/null +++ b/routes/natural-language-processing.js @@ -0,0 +1,27 @@ +import express from 'express'; +import * as NLTK from 'nltk'; +import * as spaCy from 'spacy'; + +const router = express.Router(); +const nlp = new NLTK.NLP(); +const spacy = new spaCy.SpaCy(); + +router.post('/sentiment-analysis', async (req, res) => { + const { text } = req.body; + const sentiment = await nlp.sentiment(text); + res.json({ sentiment }); +}); + +router.post('/entity-recognition', async (req, res) => { + const { text } = req.body; + const entities = await spacy.entities(text); + res.json({ entities }); +}); + +router.post('/language-translation', async (req, res) => { + const { text, sourceLang, targetLang } = req.body; + const translation = await nlp.translate(text, sourceLang, targetLang); + res.json({ translation }); +}); + +export default router;