Ejemplo n.º 1
0
 def test_tfidf(self):
     # Assert tf-idf for documents not in a model.
     v = [[0.0, 0.4, 0.6], [0.6, 0.4, 0.0]]
     v = [dict(enumerate(v)) for v in v]
     m = vector.Model([vector.Document(x) for x in v], weight=vector.TFIDF)
     v = [vector.sparse(v) for v in vector.tf_idf(v)]
     self.assertEqual(sorted(m[0].vector.items()), sorted(v[0].items()))
     self.assertAlmostEqual(v[0][2], 0.42, places=2)
     self.assertAlmostEqual(v[1][0], 0.42, places=2)
     print("pattern.vector.tf_idf()")
Ejemplo n.º 2
0
 def test_tfidf(self):
     # Assert tf-idf for documents not in a model.
     v = [[0.0, 0.4, 0.6], [0.6, 0.4, 0.0]]
     v = [dict(enumerate(v)) for v in v]
     m = vector.Model([vector.Document(x) for x in v], weight=vector.TFIDF)
     v = [vector.sparse(v) for v in vector.tf_idf(v)]
     self.assertEqual(sorted(m[0].vector.items()), sorted(v[0].items()))
     self.assertAlmostEqual(v[0][2], 0.42, places=2)
     self.assertAlmostEqual(v[1][0], 0.42, places=2)
     print("pattern.vector.tf_idf()")