Move scene shape facts into the scene family
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
scenefacts "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/scenedescriptions"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/shared/diagnostics"
|
||||
)
|
||||
|
||||
@@ -42,53 +43,41 @@ func (v *Validator) Validate(_ context.Context, req contracts.TypedValidationReq
|
||||
return contracts.ValidationResult{Approved: true}, nil
|
||||
}
|
||||
|
||||
func Validate(value dnd.SceneDescriptionList) error { return validate(value, false) }
|
||||
|
||||
func ValidateForStage(value dnd.SceneDescriptionList, stage string) error {
|
||||
return validate(value, stage == string(pipeline.StageExtract))
|
||||
}
|
||||
|
||||
func validate(value dnd.SceneDescriptionList, exactlyOne bool) error {
|
||||
issues, _ := assess(value, exactlyOne)
|
||||
if len(issues) == 0 {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("%s", diagnostics.Aggregate("invalid scene description shape", issues))
|
||||
}
|
||||
|
||||
func assess(value dnd.SceneDescriptionList, exactlyOne bool) ([]string, diagnostics.Corrections) {
|
||||
issues := make([]string, 0)
|
||||
var issues []string
|
||||
var corrections diagnostics.Corrections
|
||||
if value.Scenes == nil {
|
||||
issues = append(issues, "scenes must be present")
|
||||
corrections.Add("scene", "Return one scene description for the supplied extraction chunk.", "")
|
||||
} else if len(value.Scenes) == 0 {
|
||||
issues = append(issues, "scenes must not be empty")
|
||||
corrections.Add("scene", "Return one scene description for the supplied extraction chunk.", "")
|
||||
} else if exactlyOne && len(value.Scenes) != 1 {
|
||||
facts := scenefacts.Check(value)
|
||||
if exactlyOne && len(value.Scenes) > 0 && len(value.Scenes) != 1 {
|
||||
issues = append(issues, "extraction must contain exactly one scene")
|
||||
corrections.Add("scene", "Return exactly one scene description for the supplied extraction chunk.", "")
|
||||
}
|
||||
for index, scene := range value.Scenes {
|
||||
prefix := fmt.Sprintf("scenes[%d]", index)
|
||||
for _, fact := range facts {
|
||||
if fact.Field == scenefacts.ScenesMissing || fact.Field == scenefacts.ScenesEmpty {
|
||||
message := "scenes must be present"
|
||||
if fact.Field == scenefacts.ScenesEmpty {
|
||||
message = "scenes must not be empty"
|
||||
}
|
||||
issues = append(issues, message)
|
||||
corrections.Add("scene", "Return one scene description for the supplied extraction chunk.", "")
|
||||
continue
|
||||
}
|
||||
scene := value.Scenes[fact.Index]
|
||||
prefix := fmt.Sprintf("scenes[%d]", fact.Index)
|
||||
record := fmt.Sprintf("Affected scene titled %s with kind %s, citing %s.", diagnostics.Quote(strings.TrimSpace(scene.Title)), diagnostics.Quote(string(scene.Kind)), diagnostics.SourceRefRange(scene.SourceRef))
|
||||
if strings.TrimSpace(scene.ID) == "" || scene.ID != strings.TrimSpace(scene.ID) {
|
||||
switch fact.Field {
|
||||
case scenefacts.ID:
|
||||
issues = append(issues, prefix+".id must be non-empty and trimmed")
|
||||
corrections.Add("scene", "Return exactly one scene description for the supplied extraction chunk.", record)
|
||||
}
|
||||
if !ValidKind(scene.Kind) {
|
||||
case scenefacts.Kind:
|
||||
issues = append(issues, prefix+".kind is unsupported: "+diagnostics.Quote(string(scene.Kind)))
|
||||
corrections.Add("kind", "Set `kind` to exactly one of `combat`, `narrative`, `recap`, or `meta`.", record)
|
||||
}
|
||||
if strings.TrimSpace(scene.Title) == "" || scene.Title != strings.TrimSpace(scene.Title) {
|
||||
case scenefacts.Title:
|
||||
issues = append(issues, prefix+".title must be non-empty and trimmed")
|
||||
corrections.Add("title", "Provide a concise, nonblank, trimmed title grounded in the supplied scene transcript.", record)
|
||||
}
|
||||
if strings.TrimSpace(scene.Summary) == "" || scene.Summary != strings.TrimSpace(scene.Summary) {
|
||||
case scenefacts.Summary:
|
||||
issues = append(issues, prefix+".summary must be non-empty and trimmed")
|
||||
corrections.Add("summary", "Provide a concise, nonblank, trimmed summary grounded in the supplied scene transcript.", record)
|
||||
}
|
||||
if strings.TrimSpace(scene.SourceRef.SourceID) == "" || scene.SourceRef.SourceID != strings.TrimSpace(scene.SourceRef.SourceID) || scene.SourceRef.StartUnitID <= 0 || scene.SourceRef.EndUnitID <= 0 {
|
||||
case scenefacts.SourceRef:
|
||||
issues = append(issues, prefix+".source_ref must have a trimmed source ID and positive unit IDs")
|
||||
corrections.Add("scene", "Return exactly one scene description for the supplied extraction chunk.", record)
|
||||
}
|
||||
@@ -96,15 +85,6 @@ func assess(value dnd.SceneDescriptionList, exactlyOne bool) ([]string, diagnost
|
||||
return issues, corrections
|
||||
}
|
||||
|
||||
func ValidKind(value dnd.SceneKind) bool {
|
||||
switch value {
|
||||
case dnd.SceneKindCombat, dnd.SceneKindNarrative, dnd.SceneKindRecap, dnd.SceneKindMeta:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func Spec() pipeline.ValidatorSpec {
|
||||
return pipeline.ValidatorSpec{Key: Key, ExecutionClass: contracts.ExecutionClassDeterministic}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user