Improve @param docs for Database::compact()
[xapian.git] / xapian-letor / featurevector.cc
blobd168d1f2a8b55c315140607c2cd199398f24043e
1 /* featurevector.cc: The file responsible for transforming the document into the feature space.
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
23 #include <config.h>
25 #include <xapian.h>
27 #include "featurevector.h"
28 #include "featuremanager.h"
30 #include <list>
31 #include <map>
33 #include "str.h"
34 #include "stringutils.h"
36 #include <cstdio>
37 #include <cstdlib>
38 #include <cstring>
39 #include "safeerrno.h"
40 #include "safeunistd.h"
41 #include <iostream>
42 #include <fstream>
43 #include <sstream>
44 #include <string>
47 using namespace std;
49 using namespace Xapian;
51 FeatureVector::FeatureVector() {
54 FeatureVector::FeatureVector(const FeatureVector & /*o*/) {
57 map<string, map<string, int> >
58 FeatureVector::load_relevance(const std::string & qrel_file) {
59 typedef map<string, int> Map1; //docid and relevance judjement 0/1
60 typedef map<string, Map1> Map2; // qid and map1
61 Map2 qrel;
63 string inLine;
64 ifstream myfile(qrel_file.c_str(), ifstream::in);
65 string token[4];
66 if (myfile.is_open()) {
67 while (myfile.good()) {
68 getline(myfile, inLine); //read a file line by line
69 char * str;
70 char * x1;
71 x1 = const_cast<char*>(inLine.c_str());
72 str = strtok(x1, " ,.-");
73 int i = 0;
74 while (str != NULL) {
75 token[i] = str; //store tokens in a string array
76 ++i;
77 str = strtok(NULL, " ,.-");
80 qrel.insert(make_pair(token[0], Map1()));
81 qrel[token[0]].insert(make_pair(token[2], atoi(token[3].c_str())));
83 myfile.close();
85 return qrel;
88 void
89 FeatureVector::set_did(const std::string & did1) {
90 this->did=did1;
93 void
94 FeatureVector::set_label(double label1) {
95 this->label=label1;
98 void
99 FeatureVector::set_fvals(map<int,double> fvals1) {
100 this->fvals=fvals1;