| 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184 |
9x
2x
9x
2x
9x
2x
9x
2x
9x
2x
4x
9x
116x
9x
2x
9x
2x
9x
2x
9x
2x
9x
2x
| "use strict";
/**
* binary tf (1)
*
* @return {number} calculated score
*/
module.exports.binary = function ()
{
return 1;
};
/**
* raw term count
*
* @param {number} t number of times term occurs in document
* @param {number} sum_t sum of t for all terms in document
* @param {number} max_t maximum number of times any term occurs in document
* @param {number} sum_dt total number of terms in document
* @param {number} sum_all total number of terms in document collection
* @param {number} count_d total number of documents
* @param {number} count_dt total number of documents with term
* @param {number} max_dt maximum number of documents per term
* @return {number} calculated score
*/
module.exports.count = function (t, sum_t, max_t, sum_dt, sum_all, count_d, count_dt, max_dt)
{
return t;
};
/**
* term frequency (raw cunt / total raw count)
*
* @param {number} t number of times term occurs in document
* @param {number} sum_t sum of t for all terms in document
* @param {number} max_t maximum number of times any term occurs in document
* @param {number} sum_dt total number of terms in document
* @param {number} sum_all total number of terms in document collection
* @param {number} count_d total number of documents
* @param {number} count_dt total number of documents with term
* @param {number} max_dt maximum number of documents per term
* @return {number} calculated score
*/
module.exports.termFrequency = function (t, sum_t, max_t, sum_dt, sum_all, count_d, count_dt, max_dt)
{
return t / sum_t;
};
/**
* 1 + log(count)
*
* @param {number} t number of times term occurs in document
* @param {number} sum_t sum of t for all terms in document
* @param {number} max_t maximum number of times any term occurs in document
* @param {number} sum_dt total number of terms in document
* @param {number} sum_all total number of terms in document collection
* @param {number} count_d total number of documents
* @param {number} count_dt total number of documents with term
* @param {number} max_dt maximum number of documents per term
* @return {number} calculated score
*/
module.exports.logNormal = function (t, sum_t, max_t, sum_dt, sum_all, count_d, count_dt, max_dt)
{
return 1 + Math.log(t);
};
/**
* doouble normalisation score functon generator K + (1-K) (count / max count)
*
* @param {number} [K=0.5] augment weight
* @return {function} score function
*/
module.exports.augmented = function (K = 0.5)
{
return function (t, sum_t, max_t, sum_dt, sum_all, count_d, count_dt, max_dt)
{
return K + K * (t / max_t);
};
};
/**
* anonymous function - description
*
* @param {number} t number of times term occurs in document
* @param {number} sum_t sum of t for all terms in document
* @param {number} max_t maximum number of times any term occurs in document
* @param {number} sum_dt total number of terms in document
* @param {number} sum_all total number of terms in document collection
* @param {number} count_d total number of documents
* @param {number} count_dt total number of documents with term
* @param {number} max_dt maximum number of documents per term
* @return {number} calculated score
*/
module.exports.naiveBayes = function (t, sum_t, max_t, sum_dt, sum_all, count_d, count_dt, max_dt)
{
return sum_all / sum_t / count_d;
};
/**
* unary idf (1)
*
* @return {number} calculated score
*/
module.exports.unary = function ()
{
return 1;
};
/**
* idf - number of documents / number of documents with term
*
* @param {number} t number of times term occurs in document
* @param {number} sum_t sum of t for all terms in document
* @param {number} max_t maximum number of times any term occurs in document
* @param {number} sum_dt total number of terms in document
* @param {number} sum_all total number of terms in document collection
* @param {number} count_d total number of documents
* @param {number} count_dt total number of documents with term
* @param {number} max_dt maximum number of documents per term
* @return {number} calculated score
*/
module.exports.inverseDocumentFrequency = function (t, sum_t, max_t, sum_dt, sum_all, count_d, count_dt, max_dt)
{
return Math.log(count_d / count_dt);
};
/**
* idf smooth
*
* @param {number} t number of times term occurs in document
* @param {number} sum_t sum of t for all terms in document
* @param {number} max_t maximum number of times any term occurs in document
* @param {number} sum_dt total number of terms in document
* @param {number} sum_all total number of terms in document collection
* @param {number} count_d total number of documents
* @param {number} count_dt total number of documents with term
* @param {number} max_dt maximum number of documents per term
* @return {number} calculated score
*/
module.exports.inverseDocumentFrequencySmooth = function (t, sum_t, max_t, sum_dt, sum_all, count_d, count_dt, max_dt)
{
return Math.log(1 + count_d / count_dt);
};
/**
* idf max
*
* @param {number} t number of times term occurs in document
* @param {number} sum_t sum of t for all terms in document
* @param {number} max_t maximum number of times any term occurs in document
* @param {number} sum_dt total number of terms in document
* @param {number} sum_all total number of terms in document collection
* @param {number} count_d total number of documents
* @param {number} count_dt total number of documents with term
* @param {number} max_dt maximum number of documents per term
* @return {number} calculated score
*/
module.exports.inverseDocumentFrequencyMax = function (t, sum_t, max_t, sum_dt, sum_all, count_d, count_dt, max_dt)
{
// added a small constant here as 0 score is a special non-result case in the system
return Math.log(max_dt / (1 + count_dt) + 1e-10);
};
/**
* probailistic idf
*
* @param {number} t number of times term occurs in document
* @param {number} sum_t sum of t for all terms in document
* @param {number} max_t maximum number of times any term occurs in document
* @param {number} sum_dt total number of terms in document
* @param {number} sum_all total number of terms in document collection
* @param {number} count_d total number of documents
* @param {number} count_dt total number of documents with term
* @param {number} max_dt maximum number of documents per term
* @return {number} calculated score
*/
module.exports.probabilisticInverseDocumentFrequency = function (t, sum_t, max_t, sum_dt, sum_all, count_d, count_dt, max_dt)
{
// added a small constant here as 0 score is a special non-result case in the system
return Math.log((count_d - count_dt) / (count_dt) + 1e-10);
};
|