Validate correction repair through the processing command
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package validators
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -95,32 +96,35 @@ func (v ProtectedVocabulary) occurrences(text string) []protectedOccurrence {
|
||||
}
|
||||
|
||||
func validateIdentityPreservation(beforeByID, afterByID map[glossary.Identity][]protectedOccurrence) string {
|
||||
var spellings []string
|
||||
for identity, beforeItems := range beforeByID {
|
||||
if len(afterByID[identity]) < len(beforeItems) {
|
||||
return "proposal may alter protected glossary terminology"
|
||||
if len(afterByID[identity]) < len(beforeItems) && len(beforeItems) > 0 {
|
||||
spellings = append(spellings, beforeItems[0].canonical)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
return protectedSpellingMessage(spellings)
|
||||
}
|
||||
|
||||
func validateCapitalizationTransitions(beforeByID, afterByID map[glossary.Identity][]protectedOccurrence) string {
|
||||
var spellings []string
|
||||
for identity, afterItems := range afterByID {
|
||||
beforeItems := beforeByID[identity]
|
||||
for i, afterItem := range afterItems {
|
||||
if i >= len(beforeItems) {
|
||||
if i >= len(beforeItems) || afterItem.text == beforeItems[i].text || afterItem.text == afterItem.canonical {
|
||||
continue
|
||||
}
|
||||
beforeItem := beforeItems[i]
|
||||
if afterItem.text == beforeItem.text {
|
||||
continue
|
||||
}
|
||||
if afterItem.text == afterItem.canonical {
|
||||
continue
|
||||
}
|
||||
return "proposal may alter protected glossary terminology"
|
||||
spellings = append(spellings, afterItem.canonical)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
return protectedSpellingMessage(spellings)
|
||||
}
|
||||
|
||||
func protectedSpellingMessage(spellings []string) string {
|
||||
if len(spellings) == 0 {
|
||||
return ""
|
||||
}
|
||||
sort.Strings(spellings)
|
||||
return fmt.Sprintf("proposal may alter protected glossary spelling %q", spellings[0])
|
||||
}
|
||||
|
||||
// preservesRepeatedIdentities permits a spoken-word proposal to reduce repeated
|
||||
|
||||
Reference in New Issue
Block a user