presage 0.9.1
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
44typedef std::set< std::string, std::less<std::string> > StringSet;
45
46
80class Selector : public Observer {
81public:
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
105private:
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
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
Tracks user interaction and context.
Definition: logger.h:57
static const char * REPEAT_SUGGESTIONS
Definition: selector.h:100
void set_repeat_suggestions(const std::string &value)
Definition: selector.cpp:221
static const char * LOGGER
Definition: selector.h:98
std::map< std::string, mbr_func_ptr_t > dispatch_map
Definition: selector.h:108
StringSet suggestedWords
Definition: selector.h:120
size_t greedy_suggestion_threshold
Definition: selector.h:112
static const char * SUGGESTIONS
Definition: selector.h:99
void set_logger(const std::string &value)
Definition: selector.cpp:194
~Selector()
Definition: selector.cpp:50
static const char * GREEDY_SUGGESTION_THRESHOLD
Definition: selector.h:101
void thresholdFilter(std::vector< std::string > &)
Definition: selector.cpp:170
void clearSuggestedWords()
Definition: selector.cpp:131
ContextTracker * contextTracker
Definition: selector.h:124
bool repeat_suggestions
Definition: selector.h:111
void set_greedy_suggestion_threshold(const std::string &value)
Definition: selector.cpp:233
void updateSuggestedWords(const std::vector< std::string > &)
Definition: selector.cpp:109
Logger< char > logger
Definition: selector.h:126
bool get_repeat_suggestions() const
Definition: selector.cpp:251
Dispatcher< Selector > dispatcher
Definition: selector.h:128
void repetitionFilter(std::vector< std::string > &)
Definition: selector.cpp:145
std::string previous_prefix
Definition: selector.h:122
size_t suggestions
Definition: selector.h:110
void set_suggestions(const std::string &value)
Definition: selector.cpp:204
void(Selector::* mbr_func_ptr_t)(const std::string &)
Definition: selector.h:107
std::vector< std::string > select(Prediction)
Definition: selector.cpp:55
size_t get_greedy_suggestion_threshold() const
Definition: selector.cpp:256
void update()
Definition: selector.cpp:97
Configuration * config
Definition: selector.h:125
size_t get_suggestions() const
Definition: selector.cpp:246
std::set< std::string, std::less< std::string > > StringSet
Definition: selector.h:44