presage
0.8.8
Main Page
Classes
Files
File List
File Members
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
Generated on Thu Nov 7 2013 14:39:06 for presage by
1.8.4