jubatus_core  0.1.2
Jubatus: Online machine learning framework for distributed environment
key_matcher_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 
17 #include "key_matcher_factory.hpp"
18 
19 #include <string>
20 #include "exact_match.hpp"
21 #include "exception.hpp"
22 #include "key_matcher.hpp"
23 #include "match_all.hpp"
24 #include "prefix_match.hpp"
25 #include "regexp_match.hpp"
26 #include "suffix_match.hpp"
27 
28 using jubatus::util::lang::shared_ptr;
29 
30 namespace jubatus {
31 namespace core {
32 namespace fv_converter {
33 
34 shared_ptr<key_matcher> key_matcher_factory::create_matcher(
35  const std::string& matcher) {
36  if (matcher == "" || matcher == "*") {
37  return shared_ptr<key_matcher>(new match_all());
38  } else if (matcher[0] == '*') {
39  return shared_ptr<key_matcher>(new suffix_match(matcher.substr(1)));
40  } else if (matcher[matcher.size() - 1] == '*') {
41  return shared_ptr<key_matcher>(
42  new prefix_match(matcher.substr(0, matcher.size() - 1)));
43  } else if (matcher.size() >= 2 && matcher[0] == '/'
44  && matcher[matcher.size() - 1] == '/') {
45  return shared_ptr<key_matcher>(
46  new regexp_match(matcher.substr(1, matcher.size() - 2)));
47  } else {
48  return shared_ptr<key_matcher>(new exact_match(matcher));
49  }
50 }
51 
52 } // namespace fv_converter
53 } // namespace core
54 } // namespace jubatus
jubatus::util::lang::shared_ptr< key_matcher > create_matcher(const std::string &matcher)