2 * @brief CollTfCollLenFeature class
4 /* Copyright (C) 2012 Parth Gupta
5 * Copyright (C) 2016 Ayush Tomar
6 * Copyright (C) 2019 Vaibhav Kansagara
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "xapian-letor/feature.h"
26 #include "api/feature_internal.h"
29 #include "stringutils.h"
36 CollTfCollLenFeature::name() const
38 return "CollTfCollLenFeature";
41 /** A helper function for feature->get_value()
43 * Checks if the term belongs to the title or is stemmed from the title.
46 is_title_term(const std::string
& term
)
48 return startswith(term
, 'S') || startswith(term
, "ZS");
52 CollTfCollLenFeature::get_values() const
54 LOGCALL(API
, vector
<double>, "CollTfCollLenFeature::get_values", NO_ARGS
);
56 vector
<double> values
;
58 double coll_len
= internal
->get_collection_length("title");
60 Xapian::Query feature_query
= internal
->get_query();
61 for (Xapian::TermIterator qt
= feature_query
.get_unique_terms_begin();
62 qt
!= feature_query
.get_terms_end(); ++qt
) {
63 if (is_title_term((*qt
))) {
64 double tf
= internal
->get_collection_termfreq(*qt
);
65 value
+= log10(1 + (coll_len
/ (1 + tf
)));
68 values
.push_back(value
);
70 coll_len
= internal
->get_collection_length("body");
72 for (Xapian::TermIterator qt
= feature_query
.get_unique_terms_begin();
73 qt
!= feature_query
.get_terms_end(); ++qt
) {
74 if (!is_title_term((*qt
))) {
75 double tf
= internal
->get_collection_termfreq(*qt
);
76 value
+= log10(1 + (coll_len
/ (1 + tf
)));
79 values
.push_back(value
);
81 coll_len
= internal
->get_collection_length("whole");
83 for (Xapian::TermIterator qt
= feature_query
.get_unique_terms_begin();
84 qt
!= feature_query
.get_terms_end(); ++qt
) {
85 double tf
= internal
->get_collection_termfreq(*qt
);
86 value
+= log10(1 + (coll_len
/ (1 + tf
)));
88 values
.push_back(value
);