presage
0.9.1
src
lib
core
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
"
34
#include "
context_tracker/contextTracker.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
:
82
Selector
(
Configuration
*,
ContextTracker
*);
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
;
111
bool
repeat_suggestions
;
112
size_t
greedy_suggestion_threshold
;
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
120
StringSet
suggestedWords
;
121
122
std::string
previous_prefix
;
123
124
ContextTracker
*
contextTracker
;
125
Configuration
*
config
;
126
Logger<char>
logger
;
127
128
Dispatcher<Selector>
dispatcher
;
129
};
130
131
132
#endif // PRESAGE_SELECTOR
Selector
Definition:
selector.h:80
Selector::dispatch_map
std::map< std::string, mbr_func_ptr_t > dispatch_map
Definition:
selector.h:108
Observer
Definition:
observer.h:34
StringSet
std::set< std::string, std::less< std::string > > StringSet
Definition:
selector.h:44
Selector::logger
Logger< char > logger
Definition:
selector.h:126
Selector::get_suggestions
size_t get_suggestions() const
Definition:
selector.cpp:246
logger.h
contextTracker.h
Selector::set_greedy_suggestion_threshold
void set_greedy_suggestion_threshold(const std::string &value)
Definition:
selector.cpp:233
Selector::thresholdFilter
void thresholdFilter(std::vector< std::string > &)
Definition:
selector.cpp:170
Selector::config
Configuration * config
Definition:
selector.h:125
dispatcher.h
suggestion.h
Selector::clearSuggestedWords
void clearSuggestedWords()
Definition:
selector.cpp:131
Selector::repeat_suggestions
bool repeat_suggestions
Definition:
selector.h:111
Prediction
Definition:
prediction.h:47
Selector::dispatcher
Dispatcher< Selector > dispatcher
Definition:
selector.h:128
Selector::GREEDY_SUGGESTION_THRESHOLD
static const char * GREEDY_SUGGESTION_THRESHOLD
Definition:
selector.h:101
Selector::get_repeat_suggestions
bool get_repeat_suggestions() const
Definition:
selector.cpp:251
Selector::Selector
Selector(Configuration *, ContextTracker *)
Definition:
selector.cpp:34
ContextTracker
Tracks user interaction and context.
Definition:
contextTracker.h:155
Selector::REPEAT_SUGGESTIONS
static const char * REPEAT_SUGGESTIONS
Definition:
selector.h:100
Selector::get_greedy_suggestion_threshold
size_t get_greedy_suggestion_threshold() const
Definition:
selector.cpp:256
Selector::updateSuggestedWords
void updateSuggestedWords(const std::vector< std::string > &)
Definition:
selector.cpp:109
Selector::contextTracker
ContextTracker * contextTracker
Definition:
selector.h:124
prediction.h
Selector::set_suggestions
void set_suggestions(const std::string &value)
Definition:
selector.cpp:204
Selector::set_logger
void set_logger(const std::string &value)
Definition:
selector.cpp:194
Selector::suggestedWords
StringSet suggestedWords
Definition:
selector.h:120
Selector::LOGGER
static const char * LOGGER
Definition:
selector.h:98
Selector::repetitionFilter
void repetitionFilter(std::vector< std::string > &)
Definition:
selector.cpp:145
Configuration
Definition:
configuration.h:36
Selector::update
void update()
Definition:
selector.cpp:97
Selector::set_repeat_suggestions
void set_repeat_suggestions(const std::string &value)
Definition:
selector.cpp:221
Selector::~Selector
~Selector()
Definition:
selector.cpp:50
Logger< char >
Observable
Definition:
observable.h:37
Selector::select
std::vector< std::string > select(Prediction)
Definition:
selector.cpp:55
Dispatcher< Selector >
Selector::previous_prefix
std::string previous_prefix
Definition:
selector.h:122
Selector::mbr_func_ptr_t
void(Selector::* mbr_func_ptr_t)(const std::string &)
Definition:
selector.h:107
Selector::suggestions
size_t suggestions
Definition:
selector.h:110
Selector::SUGGESTIONS
static const char * SUGGESTIONS
Definition:
selector.h:99
Selector::greedy_suggestion_threshold
size_t greedy_suggestion_threshold
Definition:
selector.h:112
Generated on Thu Dec 17 2020 16:34:30 for presage by
1.8.20