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

Span.noun_chunks raises TypeError #1207

Closed
IamJeffG opened this issue Jul 20, 2017 · 2 comments
Closed

Span.noun_chunks raises TypeError #1207

IamJeffG opened this issue Jul 20, 2017 · 2 comments
Labels
bug Bugs and behaviour differing from documentation

Comments

@IamJeffG
Copy link
Contributor

This bug was first reported in #658 (comment) and I can reproduce on the latest release.

doc = nlp(u"Employees are recruiting talented staffers from overseas.")
list(doc.noun_chunks)  # [Employees, talented staffers]

span = doc[0:4]
list(span.noun_chunks)  # ERROR

for sent in doc.sents:
    list(sent.noun_chunks)  # ERROR

it raises the following exception:

/lib/python2.7/site-packages/spacy/tokens/span.pyx in __get__ (spacy/tokens/span.cpp:7229)()
    231             spans = []
    232             for start, end, label in self.doc.noun_chunks_iterator(self):
--> 233                 spans.append(Span(self, start, end, label=label))
    234             for span in spans:
    235                 yield span

TypeError: Argument 'doc' has incorrect type (expected spacy.tokens.doc.Doc, got spacy.tokens.span.Span)

For resolution (and forgive me for not actually doing the PR myself) I am pretty sure we just need to pass self.doc to the Scan constructor, rather than self:

232             for start, end, label in self.doc.noun_chunks_iterator(self):
233                 spans.append(Span(self.doc, start, end, label=label))
                #                         ++++
@honnibal honnibal added the bug Bugs and behaviour differing from documentation label Jul 21, 2017
@honnibal
Copy link
Member

Thanks for the analysis --- this will be an easy fix.

honnibal added a commit that referenced this issue Jul 22, 2017
tokestermw added a commit to tokestermw/spaCy that referenced this issue Nov 18, 2017
The noun chunk iterator should work for `Doc` but not for `Span`.
tokestermw added a commit to tokestermw/spaCy that referenced this issue Nov 18, 2017
Make sure to reference `self.doc` when getting the noun chunks.

Same fix as 9750a01
ines added a commit that referenced this issue Nov 18, 2017
Fixes error when getting `noun_chunks` from `Span`s. (Issue #1207)
@lock
Copy link

lock bot commented May 8, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bugs and behaviour differing from documentation
Projects
None yet
Development

No branches or pull requests

2 participants