Skip to content

Span.noun_chunks raises TypeError #1207

@IamJeffG

Description

@IamJeffG

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))
                #                         ++++

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBugs and behaviour differing from documentation

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions