* Raise exceptions if attempt to access parse, but data is not installed. This partly but not fully addresses Issue #97. Still need exceptions on the various Token attributes that access the parse tree, e.g. token.head, token.lefts, token.rights, etc. Exceptions should be centralized, too.

This commit is contained in:
Matthew Honnibal 2015-09-21 18:35:40 +10:00
parent 388062ae01
commit f32927efbf
3 changed files with 28 additions and 0 deletions

View File

@ -55,6 +55,14 @@ cdef class Lexeme:
property vector:
def __get__(self):
cdef int length = self.vocab.vectors_length
if length == 0:
raise ValueError(
"Word vectors set to length 0. This may be because the "
"data is not installed. If you haven't already, run"
"\npython -m spacy.en.download all\n"
"to install the data."
)
repvec_view = <float[:length,]>self.c.repvec
return numpy.asarray(repvec_view)

View File

@ -232,6 +232,13 @@ cdef class Doc:
@property
def noun_chunks(self):
"""Yield spans for base noun phrases."""
if not self.is_parsed:
raise ValueError(
"noun_chunks requires the dependency parse, which "
"requires data to be installed. If you haven't done so, run: "
"\npython -m spacy.en.download all\n"
"to install the data")
cdef const TokenC* word
labels = ['nsubj', 'dobj', 'nsubjpass', 'pcomp', 'pobj', 'attr', 'conj']
np_deps = [self.vocab.strings[label] for label in labels]
@ -246,6 +253,12 @@ cdef class Doc:
"""
Yield a list of sentence Span objects, calculated from the dependency parse.
"""
if not self.is_parsed:
raise ValueError(
"sentence boundary detection requires the dependency parse, which "
"requires data to be installed. If you haven't done so, run: "
"\npython -m spacy.en.download all\n"
"to install the data")
cdef int i
start = 0
for i in range(1, self.length):

View File

@ -131,6 +131,13 @@ cdef class Token:
property vector:
def __get__(self):
cdef int length = self.vocab.vectors_length
if length == 0:
raise ValueError(
"Word vectors set to length 0. This may be because the "
"data is not installed. If you haven't already, run"
"\npython -m spacy.en.download all\n"
"to install the data."
)
repvec_view = <float[:length,]>self.c.lex.repvec
return numpy.asarray(repvec_view)