Make sure EOF is defined
[xapian.git] / xapian-letor / api / featurevector.cc
blob9b9d33615bec7aad8cc66c534cb8d2a52cc860a1
1 /** @file featurevector.cc
2 * @brief The file responsible for transforming the document into the feature space.
3 */
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
20 * USA
23 #include <config.h>
25 #include "xapian-letor/featurevector.h"
26 #include "featurevector_internal.h"
28 #include "debuglog.h"
30 #include <vector>
32 using namespace Xapian;
34 FeatureVector::FeatureVector() : internal(new FeatureVector::Internal)
36 LOGCALL_CTOR(API, "FeatureVector", NO_ARGS);
39 FeatureVector::FeatureVector(const Xapian::docid & did,
40 const std::vector<double> & fvals)
41 : internal(new FeatureVector::Internal)
43 LOGCALL_CTOR(API, "FeatureVector", did | fvals);
44 internal->did_ = did;
45 internal->fvals_ = fvals;
48 FeatureVector::FeatureVector(const FeatureVector & o) : internal(o.internal)
50 LOGCALL_CTOR(API, "FeatureVector", o);
53 FeatureVector &
54 FeatureVector::operator=(const FeatureVector & o)
56 LOGCALL(API, FeatureVector &, "FeatureVector::operator=", o);
57 internal = o.internal;
58 return *this;
61 FeatureVector::~FeatureVector()
63 LOGCALL_DTOR(API, "FeatureVector");
66 void
67 FeatureVector::set_did(Xapian::docid did)
69 LOGCALL_VOID(API, "FeatureVector::set_did", did);
70 internal->did_ = did;
73 void
74 FeatureVector::set_label(double label)
76 LOGCALL_VOID(API, "FeatureVector::set_label", label);
77 internal->label_ = label;
80 void
81 FeatureVector::set_score(double score)
83 LOGCALL_VOID(API, "FeatureVector::set_score", score);
84 internal->score_ = score;
87 void
88 FeatureVector::set_fvals(const std::vector<double> & fvals)
90 LOGCALL_VOID(API, "FeatureVector::set_fvals", fvals);
91 internal->fvals_ = fvals;
94 void
95 FeatureVector::set_feature_value(int index, double value)
97 LOGCALL_VOID(API, "FeatureVector::set_feature_value", index | value);
98 internal->fvals_[index] = value;
102 FeatureVector::get_fcount() const
104 LOGCALL(API, int, "FeatureVector::get_fcount", NO_ARGS);
105 return internal->fvals_.size();
108 double
109 FeatureVector::get_score() const
111 LOGCALL(API, double, "FeatureVector::get_score", NO_ARGS);
112 return internal->score_;
115 double
116 FeatureVector::get_label() const
118 LOGCALL(API, double, "FeatureVector::get_label", NO_ARGS);
119 return internal->label_;
122 std::vector<double>
123 FeatureVector::get_fvals() const
125 LOGCALL(API, std::vector<double>, "FeatureVector::get_fvals", NO_ARGS);
126 return internal->fvals_;
129 Xapian::docid
130 FeatureVector::get_did() const
132 LOGCALL(API, Xapian::docid, "FeatureVector::get_did", NO_ARGS);
133 return internal->did_;
136 double
137 FeatureVector::get_feature_value(int index) const
139 LOGCALL(API, double, "FeatureVector::get_feature_value", index);
140 return internal->fvals_[index];