Line data Source code
1 1 : import { NaiveBayes } from "../ml/naivebayes.ts"; 2 : 3 1 : var classifier = new NaiveBayes(); 4 : 5 : // teach it positive phrases 6 : 7 1 : await classifier.learn("amazing, awesome movie!! Yeah!! Oh boy.", "positive"); 8 1 : await classifier.learn( 9 1 : "Sweet, this is incredibly, amazing, perfect, great!!", 10 1 : "positive", 11 1 : ); 12 : 13 : // teach it a negative phrase 14 : 15 1 : await classifier.learn("terrible, shitty thing. Damn. Sucks!!", "negative"); 16 : 17 : // now ask it to categorize a document it has never seen before 18 : 19 1 : let classification = await classifier.categorize( 20 1 : "awesome, cool, amazing!! Yay.", 21 1 : ); 22 : // => 'positive' 23 : 24 1 : console.log(classification);