presage  0.9.2~beta
selector.h
Go to the documentation of this file.
1 
2 /******************************************************
3  * Presage, an extensible predictive text entry system
4  * ---------------------------------------------------
5  *
6  * Copyright (C) 2008 Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License along
19  with this program; if not, write to the Free Software Foundation, Inc.,
20  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  *
22  **********(*)*/
23 
24 
25 #ifndef PRESAGE_SELECTOR
26 #define PRESAGE_SELECTOR
27 
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31 
32 #include "suggestion.h"
33 #include "prediction.h"
35 #include "logger.h"
36 #include "dispatcher.h"
37 
38 #include <string>
39 #include <vector>
40 #include <set>
41 #include <stdlib.h> // needed for abort()
42 
43 
44 typedef std::set< std::string, std::less<std::string> > StringSet;
45 
46 
80 class Selector : public Observer {
81 public:
83  ~Selector();
84 
85  std::vector<std::string> select(Prediction);
86 
87  void update();
88 
89  void set_logger(const std::string& value);
90  void set_suggestions(const std::string& value);
91  void set_repeat_suggestions(const std::string& value);
92  void set_greedy_suggestion_threshold(const std::string& value);
93 
94  size_t get_suggestions () const;
95  bool get_repeat_suggestions () const;
96  size_t get_greedy_suggestion_threshold () const;
97 
98  static const char* LOGGER;
99  static const char* SUGGESTIONS;
100  static const char* REPEAT_SUGGESTIONS;
101  static const char* GREEDY_SUGGESTION_THRESHOLD;
102 
103  virtual void update (const Observable* variable);
104 
105 private:
106  // handle observable notifications
107  typedef void (Selector::* mbr_func_ptr_t)(const std::string&);
108  std::map<std::string, mbr_func_ptr_t> dispatch_map;
109 
110  size_t suggestions;
113 
114  void updateSuggestedWords( const std::vector<std::string>& );
115  void clearSuggestedWords();
116 
117  void repetitionFilter( std::vector<std::string>& );
118  void thresholdFilter( std::vector<std::string>& );
119 
121 
122  std::string previous_prefix;
123 
127 
129 };
130 
131 
132 #endif // PRESAGE_SELECTOR
bool get_repeat_suggestions() const
Definition: selector.cpp:251
void set_greedy_suggestion_threshold(const std::string &value)
Definition: selector.cpp:233
size_t greedy_suggestion_threshold
Definition: selector.h:112
Dispatcher< Selector > dispatcher
Definition: selector.h:128
static const char * GREEDY_SUGGESTION_THRESHOLD
Definition: selector.h:101
Configuration * config
Definition: selector.h:125
Selector(Configuration *, ContextTracker *)
Definition: selector.cpp:34
void clearSuggestedWords()
Definition: selector.cpp:131
void(Selector::* mbr_func_ptr_t)(const std::string &)
Definition: selector.h:107
void thresholdFilter(std::vector< std::string > &)
Definition: selector.cpp:170
bool repeat_suggestions
Definition: selector.h:111
void set_logger(const std::string &value)
Definition: selector.cpp:194
StringSet suggestedWords
Definition: selector.h:120
size_t get_greedy_suggestion_threshold() const
Definition: selector.cpp:256
std::string previous_prefix
Definition: selector.h:122
void repetitionFilter(std::vector< std::string > &)
Definition: selector.cpp:145
static const char * REPEAT_SUGGESTIONS
Definition: selector.h:100
static const char * SUGGESTIONS
Definition: selector.h:99
std::set< std::string, std::less< std::string > > StringSet
Definition: selector.h:44
void updateSuggestedWords(const std::vector< std::string > &)
Definition: selector.cpp:109
ContextTracker * contextTracker
Definition: selector.h:124
void set_suggestions(const std::string &value)
Definition: selector.cpp:204
static const char * LOGGER
Definition: selector.h:98
~Selector()
Definition: selector.cpp:50
size_t suggestions
Definition: selector.h:110
std::vector< std::string > select(Prediction)
Definition: selector.cpp:55
Tracks user interaction and context.
Logger< char > logger
Definition: selector.h:126
size_t get_suggestions() const
Definition: selector.cpp:246
void set_repeat_suggestions(const std::string &value)
Definition: selector.cpp:221
std::map< std::string, mbr_func_ptr_t > dispatch_map
Definition: selector.h:108
void update()
Definition: selector.cpp:97