88 lines
2.0 KiB
Go
88 lines
2.0 KiB
Go
package validators
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"gitea.maximumdirect.net/eric/audita/internal/framework/contracts"
|
|
"gitea.maximumdirect.net/eric/audita/internal/validators/protected_terms"
|
|
)
|
|
|
|
var builtInChains = map[string][]string{
|
|
"glossary": {
|
|
KeyNoEffect,
|
|
KeyOriginalTextPresence,
|
|
KeyConfidenceThreshold,
|
|
KeyProtectedTerms,
|
|
KeyNonEmptyCorrectedText,
|
|
KeySpokenFormPlausibility,
|
|
KeyMeaningReversalReview,
|
|
},
|
|
"homophones": {
|
|
KeyNoEffect,
|
|
KeyOriginalTextPresence,
|
|
KeyConfidenceThreshold,
|
|
KeyProtectedTerms,
|
|
KeyNonEmptyCorrectedText,
|
|
KeySpokenFormPlausibility,
|
|
KeyMeaningReversalReview,
|
|
},
|
|
"spoken_word": {
|
|
KeyNoEffect,
|
|
KeyOriginalTextPresence,
|
|
KeyConfidenceThreshold,
|
|
KeyProtectedTerms,
|
|
KeyNonEmptyCorrectedText,
|
|
KeySpokenWordReview,
|
|
KeyMeaningReversalReview,
|
|
},
|
|
"grammar": {
|
|
KeyNoEffect,
|
|
KeyOriginalTextPresence,
|
|
KeyConfidenceThreshold,
|
|
KeyProtectedTerms,
|
|
KeyNonEmptyCorrectedText,
|
|
KeyGrammarReview,
|
|
KeyMeaningReversalReview,
|
|
},
|
|
}
|
|
|
|
func BuiltInChainKeys(moduleKey string) ([]string, error) {
|
|
keys, ok := builtInChains[moduleKey]
|
|
if !ok {
|
|
return nil, fmt.Errorf("no built-in validator chain for module %q", moduleKey)
|
|
}
|
|
out := make([]string, len(keys))
|
|
copy(out, keys)
|
|
return out, nil
|
|
}
|
|
|
|
func ResolveBuiltInChain(moduleKey string, registry *Registry) ([]contracts.Validator, error) {
|
|
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 == "glossary" && 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
|
|
}
|