int ir_eval_tests()
{
    system("rm -rf ceeaus-inv");
    create_config("file");
    auto idx = index::make_index<index::inverted_index, caching::splay_cache>(
        "test-config.toml", uint32_t{10000});
    index::okapi_bm25 ranker;
    index::ir_eval eval{"test-config.toml"};

    int num_failed = 0;

    num_failed += testing::run_test("ir-eval", [&]()
    {
        for (size_t i = 0; i < 5; ++i)
        {
            corpus::document query{idx->doc_path(doc_id{i}), doc_id{0}};
            auto ranking = ranker.score(*idx, query);
            double f1 = eval.f1(ranking, query_id{i});
            double p = eval.precision(ranking, query_id{i});
            double r = eval.recall(ranking, query_id{i});
            ASSERT(f1 >= 0 && f1 <= 1);
            ASSERT(p >= 0 && p <= 1);
            ASSERT(r >= 0 && r <= 1);
        }
    });

    system("rm -rf ceeaus-inv test-config.toml");
    return num_failed;
}
Exemple #2
0
int ir_eval_bounds()
{
    return testing::run_test(
        "ir-eval-bounds", [&]()
        {
            system("rm -rf ceeaus-inv");
            create_config("file");
            auto idx = index::make_index<index::inverted_index,
                                         caching::splay_cache>(
                "test-config.toml", uint32_t{10000});
            index::okapi_bm25 ranker;
            index::ir_eval eval{"test-config.toml"};
            // sanity test bounds
            for (size_t i = 0; i < 5; ++i)
            {
                corpus::document query{idx->doc_path(doc_id{i}), doc_id{0}};
                auto ranking = ranker.score(*idx, query);
                auto f1 = eval.f1(ranking, query_id{i});
                auto p = eval.precision(ranking, query_id{i});
                auto r = eval.recall(ranking, query_id{i});
                auto avg_p = eval.avg_p(ranking, query_id{i});
                auto ndcg = eval.ndcg(ranking, query_id{i});
                ASSERT(f1 >= 0 && f1 <= 1);
                ASSERT(p >= 0 && p <= 1);
                ASSERT(r >= 0 && r <= 1);
                ASSERT(avg_p >= 0 && avg_p <= 1);
                ASSERT(ndcg >= 0 && ndcg <= 1);
            }

            auto map = eval.map();
            auto gmap = eval.gmap();
            ASSERT(map >= 0 && map <= 1);
            ASSERT(gmap >= 0 && gmap <= 1);
            system("rm -rf ceeaus-inv test-config.toml");
        });
}
Exemple #3
0
std::string disk_index::doc_name(doc_id d_id) const
{
    auto path = doc_path(d_id);
    return path.substr(path.find_last_of("/") + 1);
}