Fix replication for files > 4GB on 32-bit platforms
[xapian.git] / xapian-letor / featuremanager.h
blob16f202677ea3de542ba9a266505370ddd0752fc0
1 /* featuremanager.h: The feature manager file.
3 * Copyright (C) 2012 Parth Gupta
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
18 * USA
21 #ifndef FEATURE_MANAGER_H
22 #define FEATURE_MANAGER_H
25 #include <xapian/letor.h>
26 #include "letor_features.h"
27 #include "featurevector.h"
28 #include "ranklist.h"
29 #include <map>
30 #include <string>
32 using namespace std;
34 namespace Xapian {
36 class RankList;
37 class FeatureVector;
39 class XAPIAN_VISIBILITY_DEFAULT FeatureManager {
41 public:
43 Xapian::Features f;
45 FeatureManager();
47 std::map<int,double> transform(const Document &doc, double &weight);
49 Xapian::RankList create_rank_list(const Xapian::MSet & mset,std::string & qid);
51 map<string, map<string,int> > load_relevance(const std::string & qrel_file);
53 Xapian::FeatureVector create_feature_vector(map<int,double> fvals, int &label, std::string & did);
55 std::string getdid(const Document &doc);
57 int getlabel(map<string, map<string, int> > qrel, const Document &doc, std::string & qid);
59 static const int fNum = 20;
61 virtual ~FeatureManager() {};
63 // accessors
64 inline void set_database(const Database &db) { letor_db = db; update_collection_level();}
65 inline const Database &get_database() const { return letor_db; }
66 inline void set_query(const Query &query) { letor_query = query; update_query_level();}
67 inline const Query &get_query() const { return letor_query; }
69 // fill "dest" with the corresponding values NOTE: dest should have size NUM_FEATURES (vector safer?)
70 // TODO: the definition of this should be generated (or the whole class inherited from this one)
71 // void compute(const Document &doc, double *dest);
75 private:
76 Database letor_db;
77 Query letor_query;
79 map<string,long int> coll_len;
80 map<string,long int> coll_tf;
81 map<string,double> idf;
83 map<string, map<string, int> > qrel;
85 // update collection-level measures
86 void update_collection_level();
88 // update query-level measures
89 void update_query_level();
97 #endif // FEATURE_MANAGER_H