2 * @brief Internals of Feature class
4 /* Copyright (C) 2019 Vaibhav Kansagara
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
22 #ifndef XAPIAN_INCLUDED_FEATURE_INTERNAL_H
23 #define XAPIAN_INCLUDED_FEATURE_INTERNAL_H
25 #include "xapian-letor/feature.h"
26 #include "xapian-letor/featurelist.h"
32 /** Class defining internals of Feature class. */
33 class Feature::Internal
: public Xapian::Internal::intrusive_base
{
36 /// Xapian::Database using which features will be calculated.
39 /// Xapian::Query using which features will be calculated.
42 /// Xapian::Document using which features will be calculated.
45 /// Frequency of the Query Terms in the specified documents.
46 std::map
<std::string
, Xapian::termcount
> termfreq
;
48 /// Inverse Document Frequency of Query terms in the database.
49 std::map
<std::string
, double> inverse_doc_freq
;
51 /** Length of the document as number of terms for different parts like
52 * 'title', 'body' and 'whole'.
54 std::map
<std::string
, Xapian::termcount
> doc_length
;
56 /** Length of the collection in number of terms for different parts like
57 * 'title', 'body' and 'whole'.
59 std::map
<std::string
, Xapian::termcount
> collection_length
;
61 /// Frequency of the Query Terms in the whole database
62 std::map
<std::string
, Xapian::termcount
> collection_termfreq
;
65 /// Default constructor
68 /// Constructor creating an object instantiated with db,query and doc
69 Internal(const Xapian::Database
& db
, const Xapian::Query
& query
,
70 const Xapian::Document
& doc
)
71 : feature_db(db
), feature_query(query
), feature_doc(doc
) {}
74 Database
get_database() const {
79 Query
get_query() const {
84 Document
get_document() const {
89 Xapian::termcount
get_termfreq(const std::string
& term
) const;
91 /// Get inverse_doc_freq
92 double get_inverse_doc_freq(const std::string
& term
) const;
95 Xapian::termcount
get_doc_length(const std::string
& term
) const;
97 /// Get collection_length
98 Xapian::termcount
get_collection_length(const std::string
& term
) const;
100 /// Get collection_termfreq
101 Xapian::termcount
get_collection_termfreq(const std::string
& term
) const;
103 /// Set the term frequency to use for Feature building.
104 void set_termfreq(std::map
<std::string
, Xapian::termcount
>&& tf
) {
108 /// Set the inverse_doc_freq to use for Feature building.
109 void set_inverse_doc_freq(std::map
<std::string
, double>&& idf
) {
110 inverse_doc_freq
= idf
;
113 /** Set the doc_length to use for Feature building.
115 * This is used by Feature::Internal while populating Statistics.
117 void set_doc_length(std::map
<std::string
, Xapian::termcount
>&& doc_len
) {
118 doc_length
= doc_len
;
121 /// Set the collection_length to use for Feature building.
122 void set_collection_length(std::map
<std::string
,
123 Xapian::termcount
>&& collection_len
) {
124 collection_length
= collection_len
;
127 /// Set the collection_termfreq to use for Feature building.
128 void set_collection_termfreq(std::map
<std::string
,
129 Xapian::termcount
>&& collection_tf
) {
130 collection_termfreq
= collection_tf
;
136 #endif // XAPIAN_INCLUDED_FEATURE_INTERNAL_H