predictor.cpp
Go to the documentation of this file.
/******************************************************
* Presage, an extensible predictive text entry system
* ---------------------------------------------------
*
* Copyright (C) 2008 Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
**********(*)*/
#include "predictor.h"
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
Predictor::Predictor(Configuration* config,
ContextTracker* ct,
const char* predictorName,
const char* shortDesc,
const char* longDesc)
: name (predictorName),
shortDescription(shortDesc ),
longDescription (longDesc ),
contextTracker (ct ),
configuration (config ),
PREDICTORS ("Presage.Predictors."),
logger (predictorName, std::cerr)
{
// NOTE: predictor implementations deriving from this class should
// use profile to query the value of needed configuration
// variables.
}
Predictor::~Predictor()
{}
const std::string Predictor::getName() const
{
return name;
}
const std::string Predictor::getShortDescription() const
{
return shortDescription;
}
const std::string Predictor::getLongDescription() const
{
return longDescription;
}
void Predictor::set_logger (const std::string& level)
{
logger << setlevel (level);
logger << INFO << "LOGGER: " << level << endl;
}
bool Predictor::token_satisfies_filter (const std::string& token,
const std::string& prefix,
const char** filter) const
{
bool result = false;
if (filter) {
// filter is not empty, examine each filter token
int i = 0;
while (filter[i] && !result) {
std::string candidate = prefix + filter[i];
// if token starts with candidate
if (token.find (candidate) == 0) {
result = true;
}
i++;
}
} else {
// filter is empty, token matches
result = true;
}
return result;
}
predictor.h
Predictor::logger
Logger< char > logger
Definition: predictor.h:87
Predictor::getShortDescription
const std::string getShortDescription() const
Definition: predictor.cpp:74
setlevel
_SetLevel setlevel(std::string __l)
Manipulator for level.
Definition: logger.h:46
Predictor::set_logger
virtual void set_logger(const std::string &level)
Definition: predictor.cpp:88
config
std::string config
Definition: presageDemo.cpp:70
Predictor::longDescription
const std::string longDescription
Definition: predictor.h:79
Predictor::name
const std::string name
Definition: predictor.h:77
Predictor::Predictor
Predictor(Configuration *configuration, ContextTracker *contextTracker, const char *predictorName="Predictor", const char *shortDescription="", const char *longDescription="")
Definition: predictor.cpp:39
Predictor::getLongDescription
const std::string getLongDescription() const
Definition: predictor.cpp:82
Configuration
Definition: configuration.h:36
Predictor::token_satisfies_filter
virtual bool token_satisfies_filter(const std::string &token, const std::string &prefix, const char **filter) const
Definition: predictor.cpp:95
Predictor::shortDescription
const std::string shortDescription
Definition: predictor.h:78
ContextTracker
Tracks user interaction and context.
Definition: contextTracker.h:155
Predictor::getName
const std::string getName() const
Definition: predictor.cpp:66
Predictor::~Predictor
virtual ~Predictor()
Definition: predictor.cpp:60
endl
const Logger< _charT, _Traits > & endl(const Logger< _charT, _Traits > &lgr)
Definition: logger.h:278