Support single value for attribute list in doc.to_scalar conversion

This commit is contained in:
Ramanan Balakrishnan 2017-10-18 14:43:47 +05:30
parent cd9378c8f1
commit b47b4e2654
No known key found for this signature in database
GPG Key ID: 57283041B6B6D1D1
1 changed files with 6 additions and 0 deletions

View File

@ -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):