const natural = require('natural');
const NLC = require('natural').NlcClassifier;
// Create a new NLC instance
const classifier = new natural.BayesClassifier();
// Train the classifier with sample data
const trainingData = [
{ text: 'I am feeling happy today !', category: 'positive' },
{ text: 'This movie is not terrible.', category: 'negative' },
{ text: 'I love listening to bengali rock music .', category: 'positive' },
{ text: 'I don\'t love to do homework .', category: 'negative' }
];
for (let i = 0; i < trainingData.length; i++) {
const { text, category } = trainingData[i];
// nlc.addDocument(text, category);
classifier.addDocument(text, category);
}
classifier.train((err) => {
if (err) {
console.error('Error training NLC:', err);
} else {
console.log('NLC trained successfully');
// Test the classifier with sample data
const testData = [
'I am feeling sad today',
'This book is amazing',
'I hate eating vegetables',
'The weather is beautiful'
];
for (let i = 0; i < testData.length; i++) {
const text = testData[i];
const category = classifier.classify(text);
console.log(`${text} -> ${category}`);
}
}
});
const testText = prompt("Enter Your Sentence -");
const category = classifier.classify(testText);
console.log('Predicted category:', category);