2 * @brief The file responsible for transforming the document into the feature space.
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
25 #include "xapian-letor/featurevector.h"
26 #include "featurevector_internal.h"
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
);
45 internal
->fvals_
= fvals
;
48 FeatureVector::FeatureVector(const FeatureVector
& o
) : internal(o
.internal
)
50 LOGCALL_CTOR(API
, "FeatureVector", o
);
54 FeatureVector::operator=(const FeatureVector
& o
)
56 LOGCALL(API
, FeatureVector
&, "FeatureVector::operator=", o
);
57 internal
= o
.internal
;
61 FeatureVector::~FeatureVector()
63 LOGCALL_DTOR(API
, "FeatureVector");
67 FeatureVector::set_did(Xapian::docid did
)
69 LOGCALL_VOID(API
, "FeatureVector::set_did", did
);
74 FeatureVector::set_label(double label
)
76 LOGCALL_VOID(API
, "FeatureVector::set_label", label
);
77 internal
->label_
= label
;
81 FeatureVector::set_score(double score
)
83 LOGCALL_VOID(API
, "FeatureVector::set_score", score
);
84 internal
->score_
= score
;
88 FeatureVector::set_fvals(const std::vector
<double> & fvals
)
90 LOGCALL_VOID(API
, "FeatureVector::set_fvals", fvals
);
91 internal
->fvals_
= fvals
;
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();
109 FeatureVector::get_score() const
111 LOGCALL(API
, double, "FeatureVector::get_score", NO_ARGS
);
112 return internal
->score_
;
116 FeatureVector::get_label() const
118 LOGCALL(API
, double, "FeatureVector::get_label", NO_ARGS
);
119 return internal
->label_
;
123 FeatureVector::get_fvals() const
125 LOGCALL(API
, std::vector
<double>, "FeatureVector::get_fvals", NO_ARGS
);
126 return internal
->fvals_
;
130 FeatureVector::get_did() const
132 LOGCALL(API
, Xapian::docid
, "FeatureVector::get_did", NO_ARGS
);
133 return internal
->did_
;
137 FeatureVector::get_feature_value(int index
) const
139 LOGCALL(API
, double, "FeatureVector::get_feature_value", index
);
140 return internal
->fvals_
[index
];