2 * @brief TfFeature class
4 /* Copyright (C) 2012 Parth Gupta
5 * Copyright (C) 2016 Ayush Tomar
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "xapian-letor/feature.h"
27 #include "stringutils.h"
34 TfFeature::name() const
39 /** A helper function for feature->get_value()
41 * Checks if the term belongs to the title or is stemmed from the title.
44 is_title_term(const std::string
& term
)
46 return startswith(term
, 'S') || startswith(term
, "ZS");
50 TfFeature::get_values() const
52 LOGCALL(API
, vector
<double>, "TfFeature::get_values", NO_ARGS
);
54 vector
<double> values
;
57 for (Xapian::TermIterator qt
= feature_query
.get_unique_terms_begin();
58 qt
!= feature_query
.get_terms_end(); ++qt
) {
59 if (is_title_term((*qt
))) {
60 auto tf_iterator
= termfreq
.find(*qt
);
61 if (tf_iterator
!= termfreq
.end())
62 value
+= log10(1 + tf_iterator
->second
);
65 values
.push_back(value
);
68 for (Xapian::TermIterator qt
= feature_query
.get_unique_terms_begin();
69 qt
!= feature_query
.get_terms_end(); ++qt
) {
70 if (!is_title_term((*qt
))) {
71 auto tf_iterator
= termfreq
.find(*qt
);
72 if (tf_iterator
!= termfreq
.end())
73 value
+= log10(1 + tf_iterator
->second
);
76 values
.push_back(value
);
79 for (Xapian::TermIterator qt
= feature_query
.get_unique_terms_begin();
80 qt
!= feature_query
.get_terms_end(); ++qt
) {
81 auto tf_iterator
= termfreq
.find(*qt
);
82 if (tf_iterator
!= termfreq
.end())
83 value
+= log10(1 + tf_iterator
->second
);
85 values
.push_back(value
);