mirror of
https://github.com/explosion/spaCy.git
synced 2025-01-12 10:16:27 +03:00
Fix vectors.add()
This commit is contained in:
parent
41d0f1665a
commit
ab5d5ed880
|
@ -56,6 +56,7 @@ cdef class Vectors:
|
||||||
self.i = 0
|
self.i = 0
|
||||||
self.key2row = {}
|
self.key2row = {}
|
||||||
self.keys = numpy.zeros((self.data.shape[0],), dtype='uint64')
|
self.keys = numpy.zeros((self.data.shape[0],), dtype='uint64')
|
||||||
|
if data is not None:
|
||||||
for i, string in enumerate(self.strings):
|
for i, string in enumerate(self.strings):
|
||||||
if i >= self.data.shape[0]:
|
if i >= self.data.shape[0]:
|
||||||
break
|
break
|
||||||
|
@ -124,25 +125,22 @@ cdef class Vectors:
|
||||||
vector (numpy.ndarray / None): A vector to add for the key.
|
vector (numpy.ndarray / None): A vector to add for the key.
|
||||||
row (int / None): The row-number of a vector to map the key to.
|
row (int / None): The row-number of a vector to map the key to.
|
||||||
"""
|
"""
|
||||||
if row is not None and vector is not None:
|
|
||||||
raise ValueError("Only one of 'row' and 'vector' may be set")
|
|
||||||
if isinstance(key, basestring_):
|
if isinstance(key, basestring_):
|
||||||
key = self.strings.add(key)
|
key = self.strings.add(key)
|
||||||
if key in self.key2row and vector is not None:
|
if key in self.key2row and row is None:
|
||||||
row = self.key2row[key]
|
row = self.key2row[key]
|
||||||
elif key in self.key2row and row is not None:
|
elif key in self.key2row and row is not None:
|
||||||
self.key2row[key] = row
|
self.key2row[key] = row
|
||||||
elif key not in self.key2row:
|
elif row is None:
|
||||||
if row is not None:
|
|
||||||
self.key2row[key] = row
|
|
||||||
else:
|
|
||||||
self.key2row[key] = self.i
|
|
||||||
row = self.i
|
row = self.i
|
||||||
|
self.i += 1
|
||||||
if row >= self.keys.shape[0]:
|
if row >= self.keys.shape[0]:
|
||||||
self.keys.resize((row*2,))
|
self.keys.resize((row*2,))
|
||||||
self.data.resize((row*2, self.data.shape[1]))
|
self.data.resize((row*2, self.data.shape[1]))
|
||||||
self.keys[self.i] = key
|
self.keys[self.i] = key
|
||||||
self.i += 1
|
|
||||||
|
self.key2row[key] = row
|
||||||
|
self.keys[row] = key
|
||||||
if vector is not None:
|
if vector is not None:
|
||||||
self.data[row] = vector
|
self.data[row] = vector
|
||||||
return row
|
return row
|
||||||
|
|
Loading…
Reference in New Issue
Block a user