From 16b47eb387c3ff41a165d44cfbcb82ebb4526f40 Mon Sep 17 00:00:00 2001 From: Raphael Mitsch Date: Fri, 10 Mar 2023 14:16:27 +0100 Subject: [PATCH] Fix case for len(ent.sents) == 1. --- spacy/pipeline/entity_linker.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/spacy/pipeline/entity_linker.py b/spacy/pipeline/entity_linker.py index 0d0d366b5..85680ffaf 100644 --- a/spacy/pipeline/entity_linker.py +++ b/spacy/pipeline/entity_linker.py @@ -484,10 +484,13 @@ class EntityLinker(TrainablePipe): # 2. "8 was beautiful" # This makes it tricky to receive the last sentence by indexing doc.sents - hence we use an offset # to determine sent_indices[1]. - sent_indices = ( - sentences.index(sents[0]), - sentences.index(sents[0]) + len(sents) - 1, - ) + if len(sents) > 1: + sent_indices = ( + sentences.index(sents[0]), + sentences.index(sents[0]) + len(sents) - 1, + ) + else: + sent_indices = (sentences.index(ent.sent), sentences.index(ent.sent)) assert all([si >= 0 for si in sent_indices]) if self.incl_context: