Skip to content

Commit

Permalink
Create natural-language-processing.js
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Jul 22, 2024
1 parent 469f268 commit 1af2408
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions routes/natural-language-processing.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 1af2408

Please sign in to comment.