Implement NPC extraction follow-up fixes

This commit is contained in:
2026-07-20 23:10:25 -05:00
parent 20cfbfd311
commit c6f330eb06
13 changed files with 133 additions and 757 deletions

View File

@@ -17,8 +17,8 @@ func canonicalizeResponse(response *extractionResponse, doc *source.SourceDocume
canonicalizeNPC(&response.NPCs[index])
}
sort.SliceStable(response.NPCs, func(i, j int) bool {
left, leftOK := earliestSourceUnit(doc, response.NPCs[i])
right, rightOK := earliestSourceUnit(doc, response.NPCs[j])
left, leftOK := earliestSourceIndex(doc, response.NPCs[i])
right, rightOK := earliestSourceIndex(doc, response.NPCs[j])
if leftOK != rightOK {
return leftOK
}
@@ -77,7 +77,9 @@ func sameSourceRef(left npcSourceRefResponse, right npcSourceRefResponse) bool {
left.EndUnitID.Int() == right.EndUnitID.Int()
}
func earliestSourceUnit(doc *source.SourceDocument, npc npcResponse) (int, bool) {
func earliestSourceIndex(doc *source.SourceDocument, npc npcResponse) (int, bool) {
earliest := 0
found := false
for _, ref := range npc.SourceRefs {
start := ref.StartUnitID.Int()
end := ref.EndUnitID.Int()
@@ -87,10 +89,13 @@ func earliestSourceUnit(doc *source.SourceDocument, npc npcResponse) (int, bool)
if !startOK || !endOK || startIndex > endIndex {
continue
}
return start, true
if !found || startIndex < earliest {
earliest = startIndex
found = true
}
}
}
return 0, false
return earliest, found
}
func unitSortValue(ref shared.UnitRef) int {