Skip to content

Commit

Permalink
Merge pull request #341 from astraszab/hyponym-detector-index-error-fix
Browse files Browse the repository at this point in the history
Hyponym detector index error fix
  • Loading branch information
dakinggg authored Mar 19, 2021
2 parents 5df54e4 + d191052 commit 4ade4ec
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions scispacy/hyponym_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,20 @@ def expand_to_noun_compound(self, token: Token, doc: Doc):

start = token.i
while True:
previous = doc[start - 1]
if previous.pos_ in {"PROPN", "NOUN", "PRON"}:
if start - 1 < 0:
break
previous_token = doc[start - 1]
if previous_token.pos_ in {"PROPN", "NOUN", "PRON"}:
start -= 1
else:
break

end = token.i + 1
while True:
previous = doc[end]
if previous.pos_ in {"PROPN", "NOUN", "PRON"}:
if end >= len(doc):
break
next_token = doc[end]
if next_token.pos_ in {"PROPN", "NOUN", "PRON"}:
end += 1
else:
break
Expand Down

0 comments on commit 4ade4ec

Please sign in to comment.