jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
burst.cpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2014 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 "burst.hpp"
18 
19 #include <string>
20 #include <vector>
21 #include <map>
22 
23 #include "../framework/mixable.hpp"
24 
25 
26 namespace jubatus {
27 namespace core {
28 namespace driver {
29 
30 namespace {
31 
32 std::string keywords_to_string(const burst::keyword_list& keywords) {
33  size_t n = keywords.size();
34 
35  if (n == 0) {
36  return "";
37  }
38 
39  std::string result = keywords[0].keyword;
40 
41  for (size_t i = 1; i < n; ++i) {
42  result += ',';
43  result += keywords[i].keyword;
44  }
45 
46  return result;
47 }
48 
49 } // namespace
50 
51 void burst::init_() {
52  holder_ = mixable_holder(); // just to be safe
53 
55 }
56 
57 bool burst::add_keyword(const std::string& keyword,
58  const keyword_params& params,
59  bool processed_in_this_server) {
60  return burst_->add_keyword(keyword, params, processed_in_this_server);
61 }
62 bool burst::remove_keyword(const std::string& keyword) {
63  return burst_->remove_keyword(keyword);
64 }
66  return burst_->remove_all_keywords();
67 }
69  return burst_->get_all_keywords();
70 }
71 
72 bool burst::add_document(const std::string& str, double pos) {
73  return burst_->add_document(str, pos);
74 }
76  burst_->calculate_results();
77 }
78 burst::result_t burst::get_result(const std::string& keyword) const {
79  return burst_->get_result(keyword);
80 }
82  const std::string& keyword, double pos) const {
83  return burst_->get_result_at(keyword, pos);
84 }
86  return burst_->get_all_bursted_results();
87 }
89  return burst_->get_all_bursted_results_at(pos);
90 }
91 
92 void burst::get_status(std::map<std::string, std::string>& status) const {
93  status["all_keywords"] =
94  keywords_to_string(burst_->get_all_keywords());
95  status["processed_keywords"] =
96  keywords_to_string(burst_->get_processed_keywords());
97 }
98 
99 bool burst::has_been_mixed() const {
100  return burst_->has_been_mixed();
101 }
102 void burst::set_processed_keywords(const std::vector<std::string>& keywords) {
103  return burst_->set_processed_keywords(keywords);
104 }
105 
107  burst_->pack(pk);
108 }
109 void burst::unpack(msgpack::object o) {
110  burst_->unpack(o);
111 }
112 void burst::clear() {
113  burst_->clear();
114 }
115 
116 } // namespace driver
117 } // namespace core
118 } // namespace jubatus
result_map get_all_bursted_results_at(double pos) const
Definition: burst.cpp:88
bool add_keyword(const std::string &keyword, const keyword_params &params, bool processed_in_this_server)
Definition: burst.cpp:57
bool add_document(const std::string &str, double pos)
Definition: burst.cpp:72
void pack(framework::packer &pk) const
Definition: burst.cpp:106
core::burst::mixable_burst mixable_burst_
Definition: burst.hpp:76
keyword_list get_all_keywords() const
Definition: burst.cpp:68
model_t::result_map result_map
Definition: burst.hpp:35
void get_status(std::map< std::string, std::string > &status) const
Definition: burst.cpp:92
void unpack(msgpack::object o)
Definition: burst.cpp:109
bool remove_keyword(const std::string &keyword)
Definition: burst.cpp:62
result_map get_all_bursted_results() const
Definition: burst.cpp:85
jubatus::util::lang::shared_ptr< model_t > burst_
Definition: burst.hpp:75
void register_mixable(framework::mixable *mixable)
Definition: driver.cpp:242
void set_processed_keywords(const std::vector< std::string > &keywords)
Definition: burst.cpp:102
bool has_been_mixed() const
Definition: burst.cpp:99
model_t::keyword_list keyword_list
Definition: burst.hpp:37
result_t get_result_at(const std::string &keyword, double pos) const
Definition: burst.cpp:81
result_t get_result(const std::string &keyword) const
Definition: burst.cpp:78