Complete Phase 13 glossary module
This commit is contained in:
@@ -4,8 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/audita/internal/framework/proposals"
|
||||
)
|
||||
|
||||
type ConfidenceThresholdValidator struct{}
|
||||
@@ -110,11 +108,12 @@ func (v ProtectedGlossaryTermValidator) Validate(_ context.Context, req Request)
|
||||
return Result{ValidatorName: v.Name(), Decisions: decisions}, nil
|
||||
}
|
||||
|
||||
terms := glossaryTerms(req)
|
||||
vocab := NewProtectedVocabulary(req.Glossary)
|
||||
decisions := make([]Decision, 0, len(req.CandidateProposal))
|
||||
for _, c := range req.CandidateProposal {
|
||||
if altersProtectedTerm(c.CorrectionProposal, terms) {
|
||||
decisions = append(decisions, rejection(c.ProposalIndex, ReasonProtectedGlossaryTerm, "proposal may alter protected glossary terminology"))
|
||||
reason := vocab.violationReason(c.OriginalText, c.CorrectedText)
|
||||
if reason != "" {
|
||||
decisions = append(decisions, rejection(c.ProposalIndex, ReasonProtectedGlossaryTerm, reason))
|
||||
continue
|
||||
}
|
||||
decisions = append(decisions, approval(c.ProposalIndex))
|
||||
@@ -125,37 +124,25 @@ func (v ProtectedGlossaryTermValidator) Validate(_ context.Context, req Request)
|
||||
return Result{ValidatorName: v.Name(), Decisions: decisions}, nil
|
||||
}
|
||||
|
||||
func glossaryTerms(req Request) []string {
|
||||
if req.Glossary == nil {
|
||||
return nil
|
||||
}
|
||||
out := make([]string, 0)
|
||||
for _, e := range req.Glossary.Entries {
|
||||
if t := strings.TrimSpace(strings.ToLower(e.Name)); t != "" {
|
||||
out = append(out, t)
|
||||
}
|
||||
for _, a := range e.Aliases {
|
||||
if t := strings.TrimSpace(strings.ToLower(a)); t != "" {
|
||||
out = append(out, t)
|
||||
}
|
||||
}
|
||||
if t := strings.TrimSpace(strings.ToLower(e.Plural)); t != "" {
|
||||
out = append(out, t)
|
||||
}
|
||||
}
|
||||
return out
|
||||
type GlossaryStageProtectedGlossaryTermValidator struct{}
|
||||
|
||||
func (v GlossaryStageProtectedGlossaryTermValidator) Name() string {
|
||||
return "glossary_stage_protected_glossary_terms"
|
||||
}
|
||||
|
||||
func altersProtectedTerm(p proposals.CorrectionProposal, terms []string) bool {
|
||||
if len(terms) == 0 {
|
||||
return false
|
||||
}
|
||||
orig := strings.ToLower(p.OriginalText)
|
||||
corr := strings.ToLower(p.CorrectedText)
|
||||
for _, t := range terms {
|
||||
if strings.Contains(orig, t) && !strings.Contains(corr, t) {
|
||||
return true
|
||||
func (v GlossaryStageProtectedGlossaryTermValidator) Validate(_ context.Context, req Request) (Result, error) {
|
||||
vocab := NewProtectedVocabulary(req.Glossary)
|
||||
decisions := make([]Decision, 0, len(req.CandidateProposal))
|
||||
for _, c := range req.CandidateProposal {
|
||||
reason := vocab.glossaryStageViolationReason(c.OriginalText, c.CorrectedText)
|
||||
if reason != "" {
|
||||
decisions = append(decisions, rejection(c.ProposalIndex, ReasonProtectedGlossaryTerm, reason))
|
||||
continue
|
||||
}
|
||||
decisions = append(decisions, approval(c.ProposalIndex))
|
||||
}
|
||||
return false
|
||||
if err := EnforceDecisionCardinality(req.CandidateProposal, decisions); err != nil {
|
||||
return Result{}, err
|
||||
}
|
||||
return Result{ValidatorName: v.Name(), Decisions: decisions}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user