Пример #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")
}
Пример #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.")
}
Пример #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)")
	}
}
Пример #4
0
//Test constructor
func TestNew(t *testing.T) {
	classifier := bayes.New()
	if classifier == nil {
		t.Errorf("bayes.New() returns nil pointer")
	}
}