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
27 #include "featurevector.h"
28 #include "featuremanager.h"
34 #include "stringutils.h"
39 #include "safeerrno.h"
40 #include "safeunistd.h"
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
64 ifstream
myfile(qrel_file
.c_str(), ifstream::in
);
66 if (myfile
.is_open()) {
67 while (myfile
.good()) {
68 getline(myfile
, inLine
); //read a file line by line
71 x1
= const_cast<char*>(inLine
.c_str());
72 str
= strtok(x1
, " ,.-");
75 token
[i
] = str
; //store tokens in a string array
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())));
89 FeatureVector::set_did(const std::string
& did1
) {
94 FeatureVector::set_label(double label1
) {
99 FeatureVector::set_fvals(map
<int,double> fvals1
) {