jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
recommender_mock_util.cpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2012 Preferred Networks and Nippon Telegraph and Telephone Corporation.
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License version 2.1 as published by the Free Software Foundation.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 
17 #include <string>
18 #include <utility>
19 #include <vector>
20 #include "jubatus/util/data/string/utility.h"
21 #include "jubatus/util/lang/cast.h"
23 
24 using std::pair;
25 using std::string;
26 using std::vector;
27 using jubatus::util::data::string::split;
28 
29 namespace jubatus {
30 namespace core {
31 namespace recommender {
32 
33 common::sfv_t make_sfv(const string& repr) {
34  vector<string> elems = split(repr, ' ');
35  common::sfv_t sfv(elems.size());
36  for (size_t i = 0; i < elems.size(); ++i) {
37  vector<string> parts = split(elems[i], ':');
38  sfv[i] = make_pair(
39  parts[0],
40  jubatus::util::lang::lexical_cast<float>(parts[1]));
41  }
42  return sfv;
43 }
44 
45 vector<pair<string, float> > make_ids(const string& repr) {
46  return make_sfv(repr);
47 }
48 
49 } // namespace recommender
50 } // namespace core
51 } // namespace jubatus
vector< pair< string, float > > make_ids(const string &repr)
common::sfv_t make_sfv(const string &repr)
std::vector< std::pair< std::string, float > > sfv_t
Definition: type.hpp:29