Example #1
0
 def test_gets(self):
     from wordvector import WordVector
     dictionary = {
         'the': 0,
         'quick': 1,
         'brown': 2,
         'fox': 3,
         'jumped': 4,
         'over': 5
     }
     embed_matrix = np.array([[1.0, 1.01], [2.0, 2.0], [2.0, 2.1],
                              [1.0, 0.0], [0, 1.01], [-1.0, 0.0]])
     word_embedding = WordVector(embed_matrix, dictionary)
     d = word_embedding.get_dict()
     dr = word_embedding.get_reverse_dict()
     em = word_embedding.get_embed()
     d.pop('the')  # mutate, check that copies were returned
     dr.pop(1)
     em[0, 0] = 10
     d = word_embedding.get_dict()
     dr = word_embedding.get_reverse_dict()
     em = word_embedding.get_embed()
     self.assertEqual(6, len(d), 'wrong dictionary length')
     self.assertEqual(6, len(dr), 'wrong dictionary length')
     self.assertEqual(1.0, em[0, 0], 'wrong value in embed matrix')
     self.assertEqual(3, d['fox'], 'wrong value from dictionary')
     self.assertEqual('jumped', dr[4],
                      'wrong value from reverse dictionary')