Tighten evidence context source excerpts
This commit is contained in:
@@ -167,6 +167,7 @@ func canonicalizeOwned(value Document) (Document, error) {
|
||||
return nil, fmt.Errorf("document must be a JSON array")
|
||||
}
|
||||
seenUnitIDs := make(map[int]struct{}, len(value))
|
||||
sourceID := ""
|
||||
for unitIndex := range value {
|
||||
unit := value[unitIndex]
|
||||
if unit.ID <= 0 || strings.TrimSpace(unit.Kind) == "" || strings.TrimSpace(unit.Text) == "" {
|
||||
@@ -175,6 +176,11 @@ func canonicalizeOwned(value Document) (Document, error) {
|
||||
if err := validateUnitRef(unit, unitIndex); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if sourceID == "" {
|
||||
sourceID = unit.Ref.SourceID
|
||||
} else if unit.Ref.SourceID != sourceID {
|
||||
return nil, fmt.Errorf("units[%d].ref.source_id must match units[0].ref.source_id", unitIndex)
|
||||
}
|
||||
if _, exists := seenUnitIDs[unit.ID]; exists {
|
||||
return nil, fmt.Errorf("units contains duplicate unit id %d", unit.ID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user