Files
audita/internal/validators/chains.go

96 lines
2.3 KiB
Go

package validators
import (
"fmt"
"strings"
"gitea.maximumdirect.net/eric/audita/internal/core/modulecatalog"
"gitea.maximumdirect.net/eric/audita/internal/framework/contracts"
"gitea.maximumdirect.net/eric/audita/internal/validators/protected_terms"
)
var builtInChains = map[string][]string{
modulecatalog.KeyGlossary: {
KeyProposalShape,
KeyNoEffect,
KeyOriginalTextPresence,
KeyConfidenceThreshold,
KeyProtectedTerms,
KeyNonEmptyCorrectedText,
KeySpokenFormPlausibility,
KeyMeaningReversalReview,
},
modulecatalog.KeyHomophones: {
KeyProposalShape,
KeyNoEffect,
KeyOriginalTextPresence,
KeyConfidenceThreshold,
KeyProtectedTerms,
KeyNonEmptyCorrectedText,
KeySpokenFormPlausibility,
KeyMeaningReversalReview,
},
modulecatalog.KeySpokenWord: {
KeyProposalShape,
KeyNoEffect,
KeyOriginalTextPresence,
KeyConfidenceThreshold,
KeyProtectedTerms,
KeyNonEmptyCorrectedText,
KeyEditorialReview,
KeyMeaningReversalReview,
},
modulecatalog.KeyGrammar: {
KeyProposalShape,
KeyNoEffect,
KeyOriginalTextPresence,
KeyConfidenceThreshold,
KeyProtectedTerms,
KeyNonEmptyCorrectedText,
KeyEditorialReview,
KeyMeaningReversalReview,
},
}
func BuiltInChainKeys(moduleKey string) ([]string, error) {
key := strings.TrimSpace(moduleKey)
keys, ok := builtInChains[key]
if !ok {
return nil, fmt.Errorf("no built-in validator chain for module %q", key)
}
out := make([]string, len(keys))
copy(out, keys)
return out, nil
}
func ResolveBuiltInChain(moduleKey string, registry *Registry) ([]contracts.Validator, error) {
moduleKey = strings.TrimSpace(moduleKey)
keys, err := BuiltInChainKeys(moduleKey)
if err != nil {
return nil, err
}
if registry == nil {
registry = NewBuiltInRegistry()
}
out := make([]contracts.Validator, 0, len(keys))
for _, key := range keys {
if moduleKey == modulecatalog.KeyGlossary && key == KeyProtectedTerms {
// Glossary stages preserve current stricter protection semantics while
// reporting the stable protected_terms key.
v, buildErr := protected_terms.NewGlossaryStage()
if buildErr != nil {
return nil, buildErr
}
out = append(out, v)
continue
}
v, buildErr := registry.MustBuild(key)
if buildErr != nil {
return nil, buildErr
}
out = append(out, v)
}
return out, nil
}