Implement NPC extraction follow-up fixes
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user