def test_bow(self): # test list words # one bag of words potentialbow = [(0, 0.4)] result = matutils.isbow(potentialbow) expected = True self.assertEqual(expected, result) # multiple bags potentialbow = [(0, 4.), (1, 2.), (2, 5.), (3, 8.)] result = matutils.isbow(potentialbow) expected = True self.assertEqual(expected, result) # checking empty input potentialbow = [] result = matutils.isbow(potentialbow) expected = True self.assertEqual(expected, result) # checking corpus; should return false potentialbow = [[(2, 1), (3, 1), (4, 1), (5, 1), (1, 1), (7, 1)]] result = matutils.isbow(potentialbow) expected = False self.assertEqual(expected, result) # not a bag of words, should return false potentialbow = [(1, 3, 6)] result = matutils.isbow(potentialbow) expected = False self.assertEqual(expected, result) # checking sparse matrix format bag of words potentialbow = csr_matrix([[1, 0.4], [0, 0.3], [2, 0.1]]) result = matutils.isbow(potentialbow) expected = True self.assertEqual(expected, result) # checking np array format bag of words potentialbow = np.array([[1, 0.4], [0, 0.2], [2, 0.2]]) result = matutils.isbow(potentialbow) expected = True self.assertEqual(expected, result)
def test_bow(self): # test list words # one bag of words potentialbow = [(0, 0.4)] result = matutils.isbow(potentialbow) expected = True self.assertEqual(expected, result) # multiple bags potentialbow = [(0, 4.), (1, 2.), (2, 5.), (3, 8.)] result = matutils.isbow(potentialbow) expected = True self.assertEqual(expected, result) # checking empty input potentialbow = [] result = matutils.isbow(potentialbow) expected = True self.assertEqual(expected, result) # checking corpus; should return false potentialbow = [[(2, 1), (3, 1), (4, 1), (5, 1), (1, 1), (7, 1)]] result = matutils.isbow(potentialbow) expected = False self.assertEqual(expected, result) # not a bag of words, should return false potentialbow = [(1, 3, 6)] result = matutils.isbow(potentialbow) expected = False self.assertEqual(expected, result) # checking sparse matrix format bag of words potentialbow = csr_matrix([[1, 0.4], [0, 0.3], [2, 0.1]]) result = matutils.isbow(potentialbow) expected = True self.assertEqual(expected, result) # checking numpy array format bag of words potentialbow = numpy.array([[1, 0.4], [0, 0.2], [2, 0.2]]) result = matutils.isbow(potentialbow) expected = True self.assertEqual(expected, result)
def is_bow(vec): """ Checks if a vector is in the sparse Gensim BoW format """ return matutils.isbow(vec)
def test_None(self): # test None result = matutils.isbow(None) expected = False self.assertEqual(expected, result)