37 #ifndef RERANKER_FEATURE_VECTOR_WRITER_H_
38 #define RERANKER_FEATURE_VECTOR_WRITER_H_
42 #include "../proto/model.pb.h"
48 using confusion_learning::FeatureMessage;
49 using confusion_learning::FeatureVecMessage;
50 using confusion_learning::FeatureMessage_FeatureType;
59 template <
typename FV>
76 const typename FV::mapped_type &value,
77 FeatureMessage_FeatureType feature_type,
78 FeatureMessage *feature_message,
79 Symbols *symbols = NULL)
const {
80 feature_message->set_id(uid);
81 feature_message->set_type(feature_type);
82 feature_message->set_value(value);
83 if (symbols != NULL) {
84 const string &name = symbols->GetSymbol(uid);
86 feature_message->set_name(name);
105 FeatureMessage_FeatureType feature_type,
106 FeatureVecMessage *fv_message,
107 Symbols *symbols = NULL)
const {
108 for (
typename FV::const_iterator feature_it = features.begin();
109 feature_it != features.end();
111 FeatureMessage *feature_message = fv_message->add_feature();
123 template <
typename V>
127 confusion_learning::FeatureMessage_FeatureType feature_type,
128 FeatureVecMessage *fv_message)
const {
130 for (const_iterator feature_it = features.
begin();
131 feature_it != features.
end();
133 FeatureMessage *feature_message = fv_message->add_feature();
136 feature_message->set_name(feature_it->first);
137 feature_message->set_type(feature_type);
138 feature_message->set_value(feature_it->second);
A class to serialize FeatureVector instances to FeatureVecMessage instances.
Provides the reranker::Symbols interface as well as the reranker::StaticSymbolTable implementation...
const_iterator end() const
Returns a const iterator pointing to the end of the feature-value pairs of this feature vector...
const_iterator begin() const
Returns a const iterator pointing to the first of the feature-value pairs of this feature vector...
FeatureMap::const_iterator const_iterator
The type of const iterator for the feature-weight pairs in this vector.
An interface specifying a converter from symbols (strings) to int indices.
Defines the reranker::FeatureVector class, which, as it happens, is used to store feature vectors...
void SerializeFeature(const typename FV::key_type &uid, const typename FV::mapped_type &value, FeatureMessage_FeatureType feature_type, FeatureMessage *feature_message, Symbols *symbols=NULL) const
Serializes a single feature-value pair to a FeatureMessage.
void Write(const FV &features, FeatureMessage_FeatureType feature_type, FeatureVecMessage *fv_message, Symbols *symbols=NULL) const
Serializes the specified feature vector to the specified FeatureVecMessage protocol buffer message...
A class to represent a feature vector, where features are represented by unique identifiers, and feature values are represented by the template type.
void Write(const FeatureVector< string, V > &features, confusion_learning::FeatureMessage_FeatureType feature_type, FeatureVecMessage *fv_message) const