mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-12 02:06:31 +03:00
* 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:
parent
388062ae01
commit
f32927efbf
|
@ -55,6 +55,14 @@ cdef class Lexeme:
|
||||||
property vector:
|
property vector:
|
||||||
def __get__(self):
|
def __get__(self):
|
||||||
cdef int length = self.vocab.vectors_length
|
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
|
repvec_view = <float[:length,]>self.c.repvec
|
||||||
return numpy.asarray(repvec_view)
|
return numpy.asarray(repvec_view)
|
||||||
|
|
||||||
|
|
|
@ -232,6 +232,13 @@ cdef class Doc:
|
||||||
@property
|
@property
|
||||||
def noun_chunks(self):
|
def noun_chunks(self):
|
||||||
"""Yield spans for base noun phrases."""
|
"""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
|
cdef const TokenC* word
|
||||||
labels = ['nsubj', 'dobj', 'nsubjpass', 'pcomp', 'pobj', 'attr', 'conj']
|
labels = ['nsubj', 'dobj', 'nsubjpass', 'pcomp', 'pobj', 'attr', 'conj']
|
||||||
np_deps = [self.vocab.strings[label] for label in labels]
|
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.
|
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
|
cdef int i
|
||||||
start = 0
|
start = 0
|
||||||
for i in range(1, self.length):
|
for i in range(1, self.length):
|
||||||
|
|
|
@ -131,6 +131,13 @@ cdef class Token:
|
||||||
property vector:
|
property vector:
|
||||||
def __get__(self):
|
def __get__(self):
|
||||||
cdef int length = self.vocab.vectors_length
|
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
|
repvec_view = <float[:length,]>self.c.lex.repvec
|
||||||
return numpy.asarray(repvec_view)
|
return numpy.asarray(repvec_view)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user