Natural Language Processing
How to use it?
const zendarAI = require('zendarai')
// Configures NLP processing for sentiment and entity analysis
const zendarAINPL = zendarAI.check({
models: ['sentiment', 'entities'],
language: 'en'
})
async function analyzeText(text) {
try {
// Processes the text with NLP analysis
const analysis = await zendarAINPL.process(text)
// Checks if the analysis was successful
if (!analysis) {
console.log('Error in text analysis.')
return
}
// Displays sentiment analysis results
const sentiment = analysis.sentiment
console.log('Sentiment:', sentiment)
// Displays detected entities in the text
const entities = analysis.entities
console.log('Detected entities:', entities)
// Takes specific actions based on sentiment
if (sentiment && sentiment.score < -0.5) {
console.log('The text has a negative tone.')
} else if (sentiment && sentiment.score > 0.5) {
console.log('The text has a positive tone.')
} else {
console.log('The text is neutral.')
}
// Takes actions based on detected entities (simple example)
if (entities && entities.length > 0) {
entities.forEach((entity) => {
console.log(`Detected entity: ${entity.name} (${entity.type})`)
})
}
} catch (error) {
console.error('Error processing the text:', error)
}
}
// Example text for analysis
const text = 'ZendarAI is a powerful tool for natural language processing. It can easily identify sentiments and entities.'
analyzeText(text)
Last updated