Reuse source indexes in occurrence extraction
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user