Exemplo n.º 1
0
 def test_tfidf(self):
     # Assert tf-idf for documents not in a corpus.
     v = [[0.0, 0.1, 0.2], [0.2, 0.1, 0.0]]
     v = vector.tf_idf(v)
     self.assertAlmostEqual(v[0][2], 0.14, places=2)
     self.assertAlmostEqual(v[1][0], 0.14, places=2)
     print "pattern.vector.tf_idf()"
Exemplo n.º 2
0
 def test_tfidf(self):
     # Assert tf-idf for documents not in a corpus.
     v = [[0.0,0.1,0.2], [0.2,0.1,0.0]]
     v = vector.tf_idf(v)
     self.assertAlmostEqual(v[0][2], 0.14, places=2)
     self.assertAlmostEqual(v[1][0], 0.14, places=2)
     print "pattern.vector.tf_idf()"
Exemplo n.º 3
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()")
Exemplo n.º 4
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()")