-
Notifications
You must be signed in to change notification settings - Fork 233
/
okapi_bm25.h
88 lines (75 loc) · 1.83 KB
/
okapi_bm25.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**
* @file okapi_bm25.h
* @author Sean Massung
*
* All files in META are released under the MIT license. For more details,
* consult the file LICENSE in the root of the project.
*/
#ifndef META_OKAPI_BM25_H_
#define META_OKAPI_BM25_H_
#include "meta/index/ranker/ranker.h"
#include "meta/index/ranker/ranker_factory.h"
namespace meta
{
namespace index
{
/**
* The Okapi BM25 scoring function.
*
* Required config parameters:
* ~~~toml
* [ranker]
* method = "bm25"
* ~~~
*
* Optional config parameters:
* ~~~toml
* k1 = 1.2
* b = 0.75
* k3 = 500.0
* ~~~
*/
class okapi_bm25 : public ranking_function
{
public:
/// The identifier for this ranker.
const static util::string_view id;
/// Default k1, doc term smoothing
const static constexpr float default_k1 = 1.2f;
/// Default b, length normalization
const static constexpr float default_b = 0.75f;
/// Default k3, query term smoothing
const static constexpr float default_k3 = 500.0f;
/**
* @param k1 Doc term smoothing
* @param b Length normalization
* @param k3 Query term smoothing
*/
okapi_bm25(float k1 = default_k1, float b = default_b,
float k3 = default_k3);
/**
* Loads an okapi_bm25 ranker from a stream.
* @param in The stream to read from
*/
okapi_bm25(std::istream& in);
/**
* @param sd score_data for the current query
*/
float score_one(const score_data& sd) override;
void save(std::ostream& out) const override;
private:
/// Doc term smoothing
const float k1_;
/// Length normalization
const float b_;
/// Query term smoothing
const float k3_;
};
/**
* Specialization of the factory method used to create okapi_bm25 rankers.
*/
template <>
std::unique_ptr<ranker> make_ranker<okapi_bm25>(const cpptoml::table&);
}
}
#endif