mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-06-18 22:23:07 -03:00
go: remove Classifier from API
Even more reduces public API surface by hiding un-used Classifier API for providing a pre-trained classifier weights. Signed-off-by: Alexander Bezzubov <bzz@apache.org>
This commit is contained in:
16
common.go
16
common.go
@ -27,7 +27,7 @@ var DefaultStrategies = []Strategy{
|
||||
}
|
||||
|
||||
// defaultClassifier is a Naive Bayes classifier trained on Linguist samples.
|
||||
var defaultClassifier Classifier = &classifier{
|
||||
var defaultClassifier classifier = &naiveBayes{
|
||||
languagesLogProbabilities: data.LanguagesLogProbabilities,
|
||||
tokensLogProbabilities: data.TokensLogProbabilities,
|
||||
tokensTotal: data.TokensTotal,
|
||||
@ -108,10 +108,10 @@ func getFirstLanguageAndSafe(languages []string) (language string, safe bool) {
|
||||
return
|
||||
}
|
||||
|
||||
// GetLanguageBySpecificClassifier returns the most probably language for the given content using
|
||||
// getLanguageBySpecificClassifier returns the most probably language for the given content using
|
||||
// classifier to detect language.
|
||||
func GetLanguageBySpecificClassifier(content []byte, candidates []string, classifier Classifier) (language string, safe bool) {
|
||||
languages := GetLanguagesBySpecificClassifier(content, candidates, classifier)
|
||||
func getLanguageBySpecificClassifier(content []byte, candidates []string, classifier classifier) (language string, safe bool) {
|
||||
languages := getLanguagesBySpecificClassifier(content, candidates, classifier)
|
||||
return getFirstLanguageAndSafe(languages)
|
||||
}
|
||||
|
||||
@ -420,17 +420,17 @@ func GetLanguagesByClassifier(filename string, content []byte, candidates []stri
|
||||
return nil
|
||||
}
|
||||
|
||||
return GetLanguagesBySpecificClassifier(content, candidates, defaultClassifier)
|
||||
return getLanguagesBySpecificClassifier(content, candidates, defaultClassifier)
|
||||
}
|
||||
|
||||
// GetLanguagesBySpecificClassifier returns a slice of possible languages. It takes in a Classifier to be used.
|
||||
func GetLanguagesBySpecificClassifier(content []byte, candidates []string, classifier Classifier) (languages []string) {
|
||||
// getLanguagesBySpecificClassifier returns a slice of possible languages. It takes in a Classifier to be used.
|
||||
func getLanguagesBySpecificClassifier(content []byte, candidates []string, classifier classifier) (languages []string) {
|
||||
mapCandidates := make(map[string]float64)
|
||||
for _, candidate := range candidates {
|
||||
mapCandidates[candidate]++
|
||||
}
|
||||
|
||||
return classifier.Classify(content, mapCandidates)
|
||||
return classifier.classify(content, mapCandidates)
|
||||
}
|
||||
|
||||
// GetLanguageExtensions returns the different extensions being used by the language.
|
||||
|
Reference in New Issue
Block a user