Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for empty list of roots #9

Merged
merged 1 commit into from
Jan 24, 2023

Conversation

jonwiggins
Copy link
Contributor

Currently, any document containing a sentence that spacy believes to be empty will cause an exception to be raised due to unsafe indexing into a list which may be empty. For example:

nlp = spacy.load("en_core_web_md")
nlp.add_pipe("entityLinker", last=True)

nlp("\n\n")

raises

.../spacy_entity_linker/TermCandidateExtractor.py in _get_candidates_in_sent(self, sent, doc)
     12 
     13     def _get_candidates_in_sent(self, sent, doc):
---> 14         root = list(filter(lambda token: token.dep_ == "ROOT", sent))[0]
     15 
     16         excluded_children = []

IndexError: list index out of range

This PR fixes that.

@jonwiggins
Copy link
Contributor Author

@egerber Any thoughts?

@MartinoMensio
Copy link
Collaborator

Hi @jonwiggins ,
Yes, this is a great PR! Thank you for contributing and fixing this error. I just notice this PR because of a recent comment in #10 .

Martino

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants