Add correction proposal models
This commit is contained in:
47
internal/framework/proposals/policy.go
Normal file
47
internal/framework/proposals/policy.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package proposals
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ReplacementPolicy controls how original_text spans are replaced in a target segment.
|
||||
type ReplacementPolicy string
|
||||
|
||||
const (
|
||||
ReplacementPolicyRequireUnique ReplacementPolicy = "require_unique"
|
||||
ReplacementPolicyReplaceAll ReplacementPolicy = "replace_all"
|
||||
)
|
||||
|
||||
func (p ReplacementPolicy) IsValid() bool {
|
||||
switch p {
|
||||
case ReplacementPolicyRequireUnique, ReplacementPolicyReplaceAll:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func ParseReplacementPolicy(raw string) (ReplacementPolicy, error) {
|
||||
parsed := ReplacementPolicy(strings.TrimSpace(raw))
|
||||
if !parsed.IsValid() {
|
||||
return "", fmt.Errorf("replacement policy must be one of: require_unique, replace_all")
|
||||
}
|
||||
return parsed, nil
|
||||
}
|
||||
|
||||
func (p *ReplacementPolicy) UnmarshalJSON(data []byte) error {
|
||||
var raw string
|
||||
if err := json.Unmarshal(data, &raw); err != nil {
|
||||
return fmt.Errorf("replacement policy must be a JSON string: %w", err)
|
||||
}
|
||||
|
||||
parsed, err := ParseReplacementPolicy(raw)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = parsed
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user