jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
string_filter_factory.cpp
Go to the documentation of this file.
1 // Jubatus: Online machine learning framework for distributed environment
2 // Copyright (C) 2011 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 
18 
19 #include <string>
20 #include "exception.hpp"
21 #include "regexp_filter.hpp"
22 #include "string_filter.hpp"
23 #include "util.hpp"
24 
25 using jubatus::util::lang::shared_ptr;
26 
27 namespace jubatus {
28 namespace core {
29 namespace fv_converter {
30 
31 namespace {
32 
33 shared_ptr<regexp_filter> create_regexp_filter(
34  const param_t& params) {
35  const std::string& pattern = get_or_die(params, "pattern");
36  const std::string& replace = get_or_die(params, "replace");
37  return shared_ptr<regexp_filter>(new regexp_filter(pattern, replace));
38 }
39 
40 } // namespace
41 
42 shared_ptr<string_filter> string_filter_factory::create(
43  const std::string& name,
44  const param_t& params) const {
45  string_filter* p;
46  if (name == "regexp") {
47  return create_regexp_filter(params);
48  } else if (ext_ && (p = ext_(name, params))) {
49  return shared_ptr<string_filter>(p);
50  } else {
51  throw JUBATUS_EXCEPTION(
52  converter_exception("unknown filter name: " + name));
53  }
54 }
55 
56 } // namespace fv_converter
57 } // namespace core
58 } // namespace jubatus
std::map< std::string, std::string > param_t
Definition: type.hpp:28
#define JUBATUS_EXCEPTION(e)
Definition: exception.hpp:79
const std::string & get_or_die(const std::map< std::string, std::string > &params, const std::string &key)
Definition: util.cpp:28
jubatus::util::lang::shared_ptr< string_filter > create(const std::string &name, const param_t &params) const