ModErn Text Analysis
META Enumerates Textual Applications
filter_factory.h
Go to the documentation of this file.
1 
10 #ifndef META_FILTER_FACTORY_H_
11 #define META_FILTER_FACTORY_H_
12 
13 #include "analyzers/token_stream.h"
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 analyzers
25 {
26 
33  : public util::factory<filter_factory, token_stream,
34  std::unique_ptr<token_stream>, const cpptoml::table&>
35 {
37  friend base_factory;
38 
39  private:
44 
49  template <class Tokenizer>
50  void register_tokenizer();
51 
56  template <class Filter>
57  void register_filter();
58 };
59 
60 namespace tokenizers
61 {
66 template <class Tokenizer>
67 std::unique_ptr<token_stream> make_tokenizer(const cpptoml::table&)
68 {
69  return make_unique<Tokenizer>();
70 }
71 }
72 
73 namespace filters
74 {
79 template <class Filter>
80 std::unique_ptr<token_stream> make_filter(std::unique_ptr<token_stream> source,
81  const cpptoml::table&)
82 {
83  return make_unique<Filter>(std::move(source));
84 }
85 }
86 
91 template <class Tokenizer>
93 {
95  Tokenizer::id,
96  [](std::unique_ptr<token_stream> source, const cpptoml::table& config)
97  {
98  if (source)
99  throw typename Tokenizer::token_stream_exception{
100  "tokenizers must be the first filter"};
101  return tokenizers::make_tokenizer<Tokenizer>(config);
102  });
103 }
104 
109 template <class Filter>
111 {
112  filter_factory::get().add(Filter::id, filters::make_filter<Filter>);
113 }
114 }
115 }
116 #endif
std::unique_ptr< token_stream > make_tokenizer(const cpptoml::table &)
Factory method for creating a tokenizer.
Definition: filter_factory.h:67
void add(const std::string &identifier, Function &&fn)
Associates the given identifier with the given factory method.
Definition: factory.h:61
void register_filter()
Adds (registers) a filter with this factory so it is able to be created.
Definition: filter_factory.cpp:42
friend base_factory
friend the base factory
Definition: filter_factory.h:37
Generic factory that can be subclassed to create factories for specific types.
Definition: factory.h:27
std::unique_ptr< token_stream > make_filter(std::unique_ptr< token_stream > source, const cpptoml::table &)
Factory method for creating a filter.
Definition: filter_factory.h:80
void register_filter()
Registration method for filters.
Definition: filter_factory.h:110
void register_tokenizer()
Registration method for tokenizers.
Definition: filter_factory.h:92
void register_tokenizer()
Adds (registers) a tokenizer with this factory so it is able to be created.
Definition: filter_factory.cpp:29
static filter_factory & get()
Obtains the singleton.
Definition: factory.h:48
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
Factory that is responsible for creating filters during analyzer construction.
Definition: filter_factory.h:32
filter_factory()
Constructor.
Definition: filter_factory.cpp:47
Definition: analyzer.h:19