Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion scispacy/hyponym_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def expand_to_noun_compound(self, token: Token, doc: Doc):

start = token.i
while True:
if start==0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add spaces between symbols, (our linter requires it), like if start == 0:

break
previous = doc[start - 1]
if previous.pos_ in {"PROPN", "NOUN", "PRON"}:
start -= 1
Expand All @@ -70,7 +72,10 @@ def expand_to_noun_compound(self, token: Token, doc: Doc):

end = token.i + 1
while True:
previous = doc[end]
try:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using try/except here, could you get the length of the doc before this while loop (len(doc)) and check against it each time? It's more explicit and doesn't silently catch other index errors that may be thrown e.g within spacy.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. Should have time to make these updates shortly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, contributions are always welcome regardless of timeframe :)

previous = doc[end]
except IndexError:
break
if previous.pos_ in {"PROPN", "NOUN", "PRON"}:
end += 1
else:
Expand Down