Skip to content

Commit

Permalink
fix(linker): properly collect all named entities from linkedDocs
Browse files Browse the repository at this point in the history
  • Loading branch information
nsantacruz committed Nov 9, 2023
1 parent 8655a6a commit 10178b5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions sefaria/model/linker/linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class LinkedDoc:
resolved_refs: List[PossiblyAmbigResolvedRef]
resolved_named_entities: List[ResolvedNamedEntity]

@property
def all_resolved(self) -> List[Union[PossiblyAmbigResolvedRef, ResolvedNamedEntity]]:
return self.resolved_refs + self.resolved_named_entities


class Linker:

Expand All @@ -36,7 +40,7 @@ def bulk_link(self, inputs: List[str], book_context_refs: Optional[List[Optional
@return: list of LinkedDocs
"""
all_named_entities = self._ne_recognizer.bulk_recognize(inputs)
resolved = []
docs = []
book_context_refs = book_context_refs or [None]*len(all_named_entities)
iterable = self._get_bulk_link_iterable(inputs, all_named_entities, book_context_refs, verbose)
for input_str, book_context_ref, inner_named_entities in iterable:
Expand All @@ -46,11 +50,11 @@ def bulk_link(self, inputs: List[str], book_context_refs: Optional[List[Optional
resolved_refs = self._ref_resolver.bulk_resolve(raw_refs, book_context_ref, with_failures, thoroughness)
if type_filter in {'all', 'named entity'}:
resolved_named_entities = self._ne_resolver.bulk_resolve(named_entities, with_failures)
resolved += [LinkedDoc(input_str, resolved_refs, resolved_named_entities)]
docs += [LinkedDoc(input_str, resolved_refs, resolved_named_entities)]

named_entity_list_list = [[rr.raw_named_entity for rr in inner_resolved] for inner_resolved in resolved]
named_entity_list_list = [[rr.raw_entity for rr in doc.all_resolved] for doc in docs]
self._ne_recognizer.bulk_map_normal_output_to_original_input(inputs, named_entity_list_list)
return resolved
return docs

def link(self, input_str: str, book_context_ref: Optional[Ref] = None, with_failures=False,
thoroughness=ResolutionThoroughness.NORMAL, type_filter='all') -> LinkedDoc:
Expand Down

0 comments on commit 10178b5

Please sign in to comment.