| 126 | // ---------------------------------------------------------------------------------------- |
| 127 | |
| 128 | void test_edge_cases() |
| 129 | { |
| 130 | tfidf_transformer<sparse_type> tfidf; |
| 131 | tfidf.train(corpus()); |
| 132 | |
| 133 | // Zero counts and terms unseen in training are ignored. |
| 134 | const sparse_type r = tfidf({{0,0}, {1,1}, {9,5}}); |
| 135 | DLIB_TEST(r.size() == 1 && r[0].first == 1 && near(r[0].second, 1)); |
| 136 | |
| 137 | DLIB_TEST(tfidf(sparse_type()).empty()); |
| 138 | |
| 139 | // A term whose only counts are zero is not kept. |
| 140 | tfidf.train({{{0,1}, {5,0}}, {{0,2}}}); |
| 141 | DLIB_TEST(tfidf.vocabulary() == std::vector<unsigned long>({0})); |
| 142 | |
| 143 | tfidf.train({}); |
| 144 | DLIB_TEST(tfidf.vocabulary_size() == 0); |
| 145 | DLIB_TEST(tfidf(corpus()[0]).empty()); |
| 146 | } |
| 147 | |
| 148 | // ---------------------------------------------------------------------------------------- |
| 149 |
no test coverage detected