Fix inconsistency of Vectors class API

This commit is contained in:
Matthew Honnibal 2017-10-01 17:00:34 -05:00
parent 94df115a81
commit b2a8b9be77

View File

@ -24,7 +24,12 @@ cdef class Vectors:
cdef public int i cdef public int i
def __init__(self, strings, data_or_width=0): def __init__(self, strings, data_or_width=0):
if isinstance(strings, StringStore):
self.strings = strings
else:
self.strings = StringStore() self.strings = StringStore()
for string in strings:
self.strings.add(string)
if isinstance(data_or_width, int): if isinstance(data_or_width, int):
self.data = data = numpy.zeros((len(strings), data_or_width), self.data = data = numpy.zeros((len(strings), data_or_width),
dtype='f') dtype='f')
@ -82,7 +87,8 @@ cdef class Vectors:
return i return i
def items(self): def items(self):
for i, string in enumerate(self.strings): for i, key in enumerate(self.keys):
string = self.strings[key]
yield string, self.data[i] yield string, self.data[i]
@property @property