From b47b4e2654f69498b68c06a0b6464db4e924d268 Mon Sep 17 00:00:00 2001 From: Ramanan Balakrishnan Date: Wed, 18 Oct 2017 14:43:47 +0530 Subject: [PATCH] Support single value for attribute list in doc.to_scalar conversion --- spacy/tokens/doc.pyx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spacy/tokens/doc.pyx b/spacy/tokens/doc.pyx index aca35a73f..9a644b86d 100644 --- a/spacy/tokens/doc.pyx +++ b/spacy/tokens/doc.pyx @@ -496,13 +496,19 @@ cdef class Doc: cdef int i, j cdef attr_id_t feature cdef np.ndarray[attr_t, ndim=2] output + cdef np.ndarray[attr_t, ndim=1] output_1D # Make an array from the attributes --- otherwise our inner loop is Python # dict iteration. + if( type(py_attr_ids) is not list ): + py_attr_ids = [ py_attr_ids ] cdef np.ndarray[attr_t, ndim=1] attr_ids = numpy.asarray(py_attr_ids, dtype=numpy.int32) output = numpy.ndarray(shape=(self.length, len(attr_ids)), dtype=numpy.int32) for i in range(self.length): for j, feature in enumerate(attr_ids): output[i, j] = get_token_attr(&self.c[i], feature) + if( len(attr_ids) == 1 ): + output_1D = output.reshape((self.length)) + return output_1D return output def count_by(self, attr_id_t attr_id, exclude=None, PreshCounter counts=None):