jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
test_util.hpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2013 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 #ifndef JUBATUS_CORE_DRIVER_TEST_UTIL_HPP_
18 #define JUBATUS_CORE_DRIVER_TEST_UTIL_HPP_
19 
20 #include <string>
21 #include <sstream>
22 #include <vector>
23 
24 #include "jubatus/util/math/random.h"
25 #include "../fv_converter/converter_config.hpp"
26 #include "../fv_converter/datum_to_fv_converter.hpp"
27 #include "../fv_converter/datum.hpp"
28 #include "../framework/mixable.hpp"
29 
30 
31 jubatus::util::lang::shared_ptr<jubatus::core::fv_converter::datum_to_fv_converter> // NOLINT
33  jubatus::util::lang::shared_ptr<jubatus::core::fv_converter::datum_to_fv_converter> // NOLINT
34  converter(
36 
38  str_rule.key = "*";
39  str_rule.type = "str";
40  str_rule.sample_weight = "bin";
41  str_rule.global_weight = "bin";
43  num_rule.key = "*";
44  num_rule.type = "num";
45 
47  c.string_rules = std::vector<jubatus::core::fv_converter::string_rule>();
48  c.string_rules->push_back(str_rule);
49  c.num_rules = std::vector<jubatus::core::fv_converter::num_rule>();
50  c.num_rules->push_back(num_rule);
51 
53  return converter;
54 }
55 
56 std::string generate_random_string(jubatus::util::math::random::mtrand& rand,
57  int length) {
58  static const std::string alphabets =
59  "abcdefghijklmnopqrstuvwxyz"
60  "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
61  std::string ret(length, 'a');
62  for (int i = 0; i < length; ++i) {
63  ret[i] = alphabets[rand.next_int(alphabets.length())];
64  }
65  return ret;
66 }
67 
69  jubatus::util::math::random::mtrand& rand,
70  int datum_length) {
72  std::string value = generate_random_string(rand, datum_length);
73  d.string_values_.push_back(std::make_pair("key", value));
74  return d;
75 }
76 
77 jubatus::util::lang::shared_ptr<jubatus::core::fv_converter::datum_to_fv_converter> // NOLINT
79  jubatus::util::lang::shared_ptr<jubatus::core::fv_converter::datum_to_fv_converter> // NOLINT
80  converter(
82 
84  str_rule.key = "*";
85  str_rule.type = "space";
86  str_rule.sample_weight = "tf";
87  str_rule.global_weight = "idf";
88 
90  c.string_rules = std::vector<jubatus::core::fv_converter::string_rule>();
91  c.string_rules->push_back(str_rule);
92 
94  return converter;
95 }
96 
97 #endif // JUBATUS_CORE_DRIVER_TEST_UTIL_HPP_
void initialize_converter(const converter_config &config, datum_to_fv_converter &conv, const factory_extender *ext)
jubatus::util::lang::shared_ptr< jubatus::core::fv_converter::datum_to_fv_converter > make_fv_converter()
Definition: test_util.hpp:32
jubatus::util::data::optional< std::vector< num_rule > > num_rules
jubatus::util::lang::shared_ptr< jubatus::core::fv_converter::datum_to_fv_converter > make_tf_idf_fv_converter()
Definition: test_util.hpp:78
jubatus::util::data::optional< std::vector< string_rule > > string_rules
std::string generate_random_string(jubatus::util::math::random::mtrand &rand, int length)
Definition: test_util.hpp:56
jubatus::core::fv_converter::datum generate_random_datum(jubatus::util::math::random::mtrand &rand, int datum_length)
Definition: test_util.hpp:68