Beispiel #1
0
func init() {

	myClassifier, err := bayesian.NewClassifierFromFile("classifier.gob")
	if err != nil {
		panic(err)
	}
	classifier = myClassifier
}
Beispiel #2
0
func (scanner *Scanner) LoadOrCreate() {
	classifier, err := bayesian.NewClassifierFromFile(scanner.BayesianFile())

	if err != nil {
		if os.IsNotExist(err) {
			log.Printf("%s does not exist. Creating db\n", scanner.BayesianFile())
			classifier = bayesian.NewClassifier(BAYESIAN_CLASSES...)
		}
	}

	cat, err := catalog.NewCatalogFromFile(scanner.CatalogFile())

	if err != nil {
		if os.IsNotExist(err) {
			cat = &catalog.Catalog{Filename: scanner.CatalogFile(), Files: make([]uint32, 0)}
		}
	}
	scanner.classifier = classifier
	scanner.catalog = cat
}
Beispiel #3
0
// Sets up and trains a new analyzer to classify sentiment
func NewAnalyzer() Analyzer {
	a := Analyzer{}

	// Get the training data if not present
	_, err := os.Stat(DATA_FILE)
	if err != nil {
		if os.IsNotExist(err) {
			a.downloadDataSet()
		}
	}

	c, err := bayesian.NewClassifierFromFile(DATA_FILE)
	if err == nil {
		a.classifier = c
	} else {
		// Note: Nothing will be trained at this point, but we'll still have a classifier that can be trained
		a.classifier = bayesian.NewClassifier(Positive, Negative, Neutral)
	}

	return a
}
Beispiel #4
0
func Classifier() *bayesian.Classifier {
	classifier, _ := bayesian.NewClassifierFromFile("classifier.serialized")
	return classifier
}