Ejemplo n.º 1
0
func NewBayesianAnalyzer(traningDataFilePath string, dictDataFilePath string) (*BayesianAnalyzer, error) {
	tokenizer, err := goseg.NewTokenizerFromFile(dictDataFilePath)
	if err != nil {
		return nil, err
	}

	coordinator := &sync.RWMutex{}
	classifier, err := bayesian.NewClassifierFromFile(traningDataFilePath)
	if err != nil {
		return nil, err
	}

	return &BayesianAnalyzer{tokenizer, classifier, nil, coordinator}, nil
}
Ejemplo n.º 2
0
func NewBayesianAnalyzerWithUpdater(traningDataFilePath string, dictDataFilePath string, updateDelay time.Duration) (*BayesianAnalyzer, error) {
	tokenizer, err := goseg.NewTokenizerFromFile(dictDataFilePath)
	if err != nil {
		return nil, err
	}

	coordinator := &sync.RWMutex{}
	classifier, err := bayesian.NewClassifierFromFile(traningDataFilePath)
	if err != nil {
		return nil, err
	}

	updater := NewDelayedUpdater(classifier, traningDataFilePath, updateDelay, coordinator)

	return &BayesianAnalyzer{tokenizer, classifier, updater, coordinator}, nil
}