Reuse source indexes in occurrence extraction

This commit is contained in:
2026-11-26 01:37:56 +00:00
parent f789e41faf
commit 553276c0a0
11 changed files with 42 additions and 8 deletions

View File

@@ -52,6 +52,11 @@ type groundingProjectionLocation struct {
// NewGrounding creates the contextual location projection for one source
// document and resolved registry.
func NewGrounding(registry *Registry, doc *source.SourceDocument) (*Grounding, error) {
return NewGroundingForSource(registry, doc, nil)
}
// NewGroundingForSource uses a matching whole-source index when supplied.
func NewGroundingForSource(registry *Registry, doc *source.SourceDocument, supplied *source.DocumentIndex) (*Grounding, error) {
if registry == nil {
return nil, fmt.Errorf("location registry is required")
}
@@ -59,7 +64,12 @@ func NewGrounding(registry *Registry, doc *source.SourceDocument) (*Grounding, e
return nil, fmt.Errorf("source document is required")
}
index := source.NewDocumentIndex(doc)
var index source.DocumentIndex
if supplied == nil {
index = source.NewDocumentIndex(doc)
} else {
index = *supplied
}
order := shared.NewSourceRefOrderFromIndex(index)
locations := registry.Locations()
grouped := make(map[string][]int, len(locations))