ModErn Text Analysis
META Enumerates Textual Applications
list_filter.h
Go to the documentation of this file.
1 
9 #ifndef META_LIST_FILTER_H_
10 #define META_LIST_FILTER_H_
11 
12 #include <memory>
13 #include <unordered_set>
14 
16 #include "util/clonable.h"
17 #include "util/optional.h"
18 
19 namespace cpptoml
20 {
21 class table;
22 }
23 
24 namespace meta
25 {
26 namespace analyzers
27 {
28 namespace filters
29 {
30 
34 class list_filter : public util::clonable<token_stream, list_filter>
35 {
36  public:
41  enum class type
42  {
43  ACCEPT,
44  REJECT
45  };
46 
58  list_filter(std::unique_ptr<token_stream> source,
59  const std::string& filename, type method = type::REJECT);
60 
65  list_filter(const list_filter& other);
66 
71  void set_content(const std::string& content) override;
72 
76  std::string next() override;
77 
81  operator bool() const override;
82 
84  const static std::string id;
85 
86  private:
90  void next_token();
91 
93  std::unique_ptr<token_stream> source_;
94 
97 
99  std::unordered_set<std::string> list_;
100 
103 };
104 
108 template <>
109 std::unique_ptr<token_stream>
110  make_filter<list_filter>(std::unique_ptr<token_stream>,
111  const cpptoml::table&);
112 }
113 }
114 }
115 #endif
std::unordered_set< std::string > list_
The set of tokens used for filtering.
Definition: list_filter.h:99
type
Strongly typed flag to indicate whether the list_filter rejects tokens in the list or only accepts to...
Definition: list_filter.h:41
Filter that either removes or keeps tokens from a given list.
Definition: list_filter.h:34
util::optional< std::string > token_
The next buffered token.
Definition: list_filter.h:96
void next_token()
Advances internal state to the next valid token.
Definition: list_filter.cpp:62
type method_
Whether or not this filter accepts or rejects tokens in the list.
Definition: list_filter.h:102
static const std::string id
Identifier for this filter.
Definition: list_filter.h:84
list_filter(std::unique_ptr< token_stream > source, const std::string &filename, type method=type::REJECT)
Creates a list_filter reading tokens from the given source and filtering based on the tokens specifie...
Definition: list_filter.cpp:19
Template class to facilitate polymorphic cloning.
Definition: clonable.h:28
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
std::unique_ptr< token_stream > source_
The source to read tokens from.
Definition: list_filter.h:93
Definition: analyzer.h:19
std::string next() override
Definition: list_filter.cpp:50
void set_content(const std::string &content) override
Sets the content for the beginning of the filter chain.
Definition: list_filter.cpp:43
std::unique_ptr< token_stream > make_filter< list_filter >(std::unique_ptr< token_stream >, const cpptoml::table &)
Specialization of the factory method used to create list_filters.
Definition: list_filter.cpp:99
std::string filename(const std::string &path)
Definition: unit_test.h:114