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: