Esempio n. 1
0
//Benchmark training
func BenchmarkTrain(t *testing.B) {
	classifier := bayes.New()
	t.ResetTimer()
	//Yes, naive classifiers need a large corpus. Lets just go with this for now.
	classifier.Train("That is the ugliest haircut", "negative")
	classifier.Train("Totally, it looks like a mullet.", "negative")
	classifier.Train("I kinda like it!", "positive")
	classifier.Train("It looks niiiice", "positive")
}
Esempio n. 2
0
func BenchmarkClassify(t *testing.B) {
	classifier := bayes.New()

	//Train first
	classifier.Train("amazing, awesome movie!! Yeah!! Oh boy.", "positive")
	classifier.Train("Sweet, this is incredibly, amazing, perfect, great!!", "positive")
	classifier.Train("terrible, crappy thing. darn. Sucks!!", "negative")
	t.ResetTimer()
	classifier.Classify("awesome, cool, amazing!! Yay.")
}
Esempio n. 3
0
func TestClassify(t *testing.T) {
	classifier := bayes.New()

	//Train first
	classifier.Train("amazing, awesome movie!! Yeah!! Oh boy.", "positive")
	classifier.Train("Sweet, this is incredibly, amazing, perfect, great!!", "positive")
	classifier.Train("terrible, crappy thing. darn. Sucks!!", "negative")

	result := classifier.Classify("awesome, cool, amazing!! Yay.")

	if !strings.EqualFold(result, "positive") {
		t.Error("Classifier is not classifying accurately (or has too few inputs)")
	}
}
Esempio n. 4
0
//Test constructor
func TestNew(t *testing.T) {
	classifier := bayes.New()
	if classifier == nil {
		t.Errorf("bayes.New() returns nil pointer")
	}
}