From 0153220304aa89080acf3b3fa7ccace8028c4868 Mon Sep 17 00:00:00 2001 From: Matthew Honnibal Date: Sun, 14 Jan 2018 13:57:57 +0100 Subject: [PATCH] Make set_vector add word to vocab. Fixes #1807 --- spacy/tests/regression/test_issue1807.py | 14 ++++++++++++++ spacy/vocab.pyx | 1 + 2 files changed, 15 insertions(+) create mode 100644 spacy/tests/regression/test_issue1807.py diff --git a/spacy/tests/regression/test_issue1807.py b/spacy/tests/regression/test_issue1807.py new file mode 100644 index 000000000..c73f008eb --- /dev/null +++ b/spacy/tests/regression/test_issue1807.py @@ -0,0 +1,14 @@ +'''Test vocab.set_vector also adds the word to the vocab.''' +from __future__ import unicode_literals +from ...vocab import Vocab + +import numpy + + +def test_issue1807(): + vocab = Vocab() + arr = numpy.ones((50,), dtype='f') + assert 'hello' not in vocab + vocab.set_vector('hello', arr) + assert 'hello' in vocab + diff --git a/spacy/vocab.pyx b/spacy/vocab.pyx index 34ad4eb67..a103bcd0e 100644 --- a/spacy/vocab.pyx +++ b/spacy/vocab.pyx @@ -335,6 +335,7 @@ cdef class Vocab: else: width = self.vectors.shape[1] self.vectors.resize((new_rows, width)) + lex = self[orth] # Adds worse to vocab self.vectors.add(orth, vector=vector) self.vectors.add(orth, vector=vector)