21 #include "jubatus/util/data/string/utility.h"
22 #include "jubatus/util/lang/cast.h"
25 using jubatus::util::data::string::starts_with;
29 namespace fv_converter {
32 for (
size_t i = 0; i < fv.size(); ++i) {
33 std::pair<std::string, float> num_value;
34 std::pair<std::string, std::string> string_value;
44 const std::pair<std::string, float>& feature,
45 std::pair<std::string, float>& num_value) {
50 const std::string& key = feature.first;
51 float value = feature.second;
52 size_t at = key.rfind(
'@');
53 if (at == std::string::npos) {
56 std::string num_value_key(key.substr(0, at));
57 std::string feature_value(key.substr(at + 1));
58 const std::string str_prefix =
"str$";
59 if (feature_value ==
"num") {
60 num_value.first.swap(num_value_key);
61 num_value.second = value;
63 }
else if (starts_with(feature_value, str_prefix)) {
64 std::string val_string(feature_value.substr(str_prefix.size()));
66 float val = jubatus::util::lang::lexical_cast<
float>(val_string);
67 num_value.first.swap(num_value_key);
68 num_value.second = val;
70 }
catch (
const std::bad_cast&) {
79 const std::pair<std::string, float>& feature,
80 std::pair<std::string, std::string>& string_value) {
83 const std::string& f = feature.first;
84 size_t sharp = f.rfind(
'#');
85 if (sharp == std::string::npos) {
88 size_t at = f.rfind(
'@', sharp);
89 if (at == std::string::npos) {
92 size_t dollar = f.find(
'$');
93 if (dollar == std::string::npos) {
96 if (f.substr(at + 1, sharp - at - 1) !=
"str") {
100 std::string key(f.substr(0, dollar));
101 std::string value(f.substr(dollar + 1, at - dollar - 1));
103 string_value.first.swap(key);
104 string_value.second.swap(value);
void revert_feature(const common::sfv_t &fv, fv_converter::datum &data)
std::vector< std::pair< std::string, float > > sfv_t
bool revert_string_value(const std::pair< std::string, float > &feature, std::pair< std::string, std::string > &string_value)
bool revert_num_value(const std::pair< std::string, float > &feature, std::pair< std::string, float > &num_value)