presage
0.9.1
src
lib
predictors
predictor.cpp
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
#include "
predictor.h
"
26
27
#ifdef HAVE_STDLIB_H
28
# include <stdlib.h>
29
#endif
30
39
Predictor::Predictor
(
Configuration
*
config
,
40
ContextTracker
* ct,
41
const
char
* predictorName,
42
const
char
* shortDesc,
43
const
char
* longDesc)
44
: name (predictorName),
45
shortDescription(shortDesc ),
46
longDescription (longDesc ),
47
contextTracker (ct ),
48
configuration (
config
),
49
PREDICTORS (
"Presage.Predictors."
),
50
logger (predictorName, std::cerr)
51
{
52
// NOTE: predictor implementations deriving from this class should
53
// use profile to query the value of needed configuration
54
// variables.
55
}
56
60
Predictor::~Predictor
()
61
{}
62
66
const
std::string
Predictor::getName
()
const
67
{
68
return
name
;
69
}
70
74
const
std::string
Predictor::getShortDescription
()
const
75
{
76
return
shortDescription
;
77
}
78
82
const
std::string
Predictor::getLongDescription
()
const
83
{
84
return
longDescription
;
85
}
86
87
88
void
Predictor::set_logger
(
const
std::string& level)
89
{
90
logger
<<
setlevel
(level);
91
logger
<< INFO <<
"LOGGER: "
<< level <<
endl
;
92
}
93
94
95
bool
Predictor::token_satisfies_filter
(
const
std::string& token,
96
const
std::string& prefix,
97
const
char
** filter)
const
98
{
99
bool
result =
false
;
100
101
if
(filter) {
102
// filter is not empty, examine each filter token
103
int
i = 0;
104
while
(filter[i] && !result) {
105
std::string candidate = prefix + filter[i];
106
107
// if token starts with candidate
108
if
(token.find (candidate) == 0) {
109
result =
true
;
110
}
111
112
i++;
113
}
114
}
else
{
115
// filter is empty, token matches
116
result =
true
;
117
}
118
119
return
result;
120
}
predictor.h
Predictor::getShortDescription
const std::string getShortDescription() const
Definition:
predictor.cpp:73
Predictor::getLongDescription
const std::string getLongDescription() const
Definition:
predictor.cpp:81
Predictor::shortDescription
const std::string shortDescription
Definition:
predictor.h:96
Predictor::set_logger
virtual void set_logger(const std::string &level)
Definition:
predictor.cpp:87
Predictor::name
const std::string name
Definition:
predictor.h:95
Predictor::longDescription
const std::string longDescription
Definition:
predictor.h:97
ContextTracker
Tracks user interaction and context.
Definition:
contextTracker.h:154
config
std::string config
Definition:
presageDemo.cpp:69
endl
const Logger< _charT, _Traits > & endl(const Logger< _charT, _Traits > &lgr)
Definition:
logger.h:277
Predictor::~Predictor
virtual ~Predictor()
Definition:
predictor.cpp:59
Configuration
Definition:
configuration.h:35
Predictor::getName
const std::string getName() const
Definition:
predictor.cpp:65
Predictor::Predictor
Predictor(Configuration *configuration, ContextTracker *contextTracker, const char *predictorName="Predictor", const char *shortDescription="", const char *longDescription="")
Definition:
predictor.cpp:38
Predictor::token_satisfies_filter
virtual bool token_satisfies_filter(const std::string &token, const std::string &prefix, const char **filter) const
Definition:
predictor.cpp:94
Predictor::logger
Logger< char > logger
Definition:
predictor.h:105
setlevel
_SetLevel setlevel(std::string __l)
Manipulator for level.
Definition:
logger.h:45
Generated on Sat Jan 25 2020 09:31:19 for presage by
1.8.16