presage 0.9.1
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
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
61{}
62
66const std::string Predictor::getName() const
67{
68 return name;
69}
70
74const std::string Predictor::getShortDescription() const
75{
76 return shortDescription;
77}
78
82const std::string Predictor::getLongDescription() const
83{
84 return longDescription;
85}
86
87
88void Predictor::set_logger (const std::string& level)
89{
90 logger << setlevel (level);
91 logger << INFO << "LOGGER: " << level << endl;
92}
93
94
95bool 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}
Tracks user interaction and context.
virtual ~Predictor()
Definition: predictor.cpp:60
const std::string getShortDescription() const
Definition: predictor.cpp:74
const std::string longDescription
Definition: predictor.h:79
virtual void set_logger(const std::string &level)
Definition: predictor.cpp:88
Predictor(Configuration *configuration, ContextTracker *contextTracker, const char *predictorName="Predictor", const char *shortDescription="", const char *longDescription="")
Definition: predictor.cpp:39
const std::string getLongDescription() const
Definition: predictor.cpp:82
Logger< char > logger
Definition: predictor.h:87
const std::string getName() const
Definition: predictor.cpp:66
const std::string name
Definition: predictor.h:77
const std::string shortDescription
Definition: predictor.h:78
virtual bool token_satisfies_filter(const std::string &token, const std::string &prefix, const char **filter) const
Definition: predictor.cpp:95
_SetLevel setlevel(std::string __l)
Manipulator for level.
Definition: logger.h:46
const Logger< _charT, _Traits > & endl(const Logger< _charT, _Traits > &lgr)
Definition: logger.h:278
std::string config
Definition: presageDemo.cpp:70