From f5c757bd5ee32a24098e1690a85e06d30b339c7a Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 25 Oct 2020 21:17:25 +0000 Subject: [PATCH] Added index checking to hyponym_detector.py --- scispacy/hyponym_detector.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/scispacy/hyponym_detector.py b/scispacy/hyponym_detector.py index 02dd2505..2d0d5e84 100644 --- a/scispacy/hyponym_detector.py +++ b/scispacy/hyponym_detector.py @@ -62,6 +62,8 @@ def expand_to_noun_compound(self, token: Token, doc: Doc): start = token.i while True: + if start==0: + break previous = doc[start - 1] if previous.pos_ in {"PROPN", "NOUN", "PRON"}: start -= 1 @@ -70,7 +72,10 @@ def expand_to_noun_compound(self, token: Token, doc: Doc): end = token.i + 1 while True: - previous = doc[end] + try: + previous = doc[end] + except IndexError: + break if previous.pos_ in {"PROPN", "NOUN", "PRON"}: end += 1 else: