ModErn Text Analysis
META Enumerates Textual Applications
classifier_factory.h
Go to the documentation of this file.
1 
10 #ifndef META_CLASSIFIER_FACTORY_H_
11 #define META_CLASSIFIER_FACTORY_H_
12 
14 #include "util/factory.h"
15 #include "util/shim.h"
16 
17 namespace cpptoml
18 {
19 class table;
20 }
21 
22 namespace meta
23 {
24 namespace classify
25 {
26 
33  : public util::factory<classifier_factory, classifier,
34  const cpptoml::table&,
35  std::shared_ptr<index::forward_index>,
36  std::shared_ptr<index::inverted_index>>
37 {
38  friend base_factory;
39 
40  private:
45 
49  template <class Classifier>
50  void reg();
51 
55  template <class Classifier>
56  void reg_mi();
57 };
58 
72 std::unique_ptr<classifier>
73  make_classifier(const cpptoml::table& config,
74  std::shared_ptr<index::forward_index> idx,
75  std::shared_ptr<index::inverted_index> inv_idx = nullptr);
76 
90 template <class Classifier>
91 std::unique_ptr<classifier>
92  make_classifier(const cpptoml::table&,
93  std::shared_ptr<index::forward_index> idx)
94 {
95  return make_unique<Classifier>(idx);
96 }
97 
113 template <class Classifier>
114 std::unique_ptr<classifier>
115  make_multi_index_classifier(const cpptoml::table&,
116  std::shared_ptr<index::forward_index> idx,
117  std::shared_ptr<index::inverted_index> inv_idx)
118 {
119  return make_unique<Classifier>(idx, inv_idx);
120 }
121 
127 template <class Classifier>
129 {
130  // wrap the make_classifier function to make it appear like it takes
131  // two indexes, when we really only care about one.
132  classifier_factory::get().add(Classifier::id,
133  [](const cpptoml::table& config,
134  std::shared_ptr<index::forward_index> idx,
135  std::shared_ptr<index::inverted_index>)
136  {
137  return make_classifier<Classifier>(config, std::move(idx));
138  });
139 }
140 
146 template <class Classifier>
148 {
149  classifier_factory::get().add(Classifier::id,
150  make_multi_index_classifier<Classifier>);
151 }
152 }
153 }
154 #endif
void add(const std::string &identifier, Function &&fn)
Associates the given identifier with the given factory method.
Definition: factory.h:61
void register_multi_index_classifier()
Registration method for multi-index classifiers.
Definition: classifier_factory.h:147
Factory that is responsible for creating classifiers from configuration files.
Definition: classifier_factory.h:32
Generic factory that can be subclassed to create factories for specific types.
Definition: factory.h:27
std::unique_ptr< classifier > make_classifier(const cpptoml::table &config, std::shared_ptr< index::forward_index > idx, std::shared_ptr< index::inverted_index > inv_idx=nullptr)
Convenience method for creating a classifier using the factory.
Definition: classifier_factory.cpp:48
void reg()
Registers a single-index classifier.
Definition: classifier_factory.cpp:16
The ModErn Text Analysis toolkit is a suite of natural language processing, classification, information retreival, data mining, and other applications of text processing.
Definition: analyzer.h:24
classifier_factory()
Constructs the classifier_factory singleton.
Definition: classifier_factory.cpp:32
void reg_mi()
Registers a multi-index classifier.
Definition: classifier_factory.cpp:27
void register_classifier()
Registration method for classifiers.
Definition: classifier_factory.h:128
std::unique_ptr< classifier > make_multi_index_classifier(const cpptoml::table &, std::shared_ptr< index::forward_index > idx, std::shared_ptr< index::inverted_index > inv_idx)
Factory method for creating a classifier that takes both index types.
Definition: classifier_factory.h:115
Definition: analyzer.h:19