smoothedNgramPredictor.h
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.
*
**********(*)*/
#ifndef PRESAGE_SMOOTHEDNGRAMPREDICTOR
#define PRESAGE_SMOOTHEDNGRAMPREDICTOR
#include "predictor.h"
#include "../core/logger.h"
#include "../core/dispatcher.h"
#include "dbconnector/sqliteDatabaseConnector.h"
#include <assert.h>
#if defined(HAVE_SQLITE3_H)
# include <sqlite3.h>
#elif defined(HAVE_SQLITE_H)
# include <sqlite.h>
#else
# error "SQLite is required. Please install SQLite."
#endif
class SmoothedNgramPredictor : public Predictor, public Observer {
public:
SmoothedNgramPredictor(Configuration*, ContextTracker*, const char*);
~SmoothedNgramPredictor();
virtual Prediction predict(const size_t size, const char** filter) const;
virtual void learn(const std::vector<std::string>& change);
virtual void update (const Observable* variable);
private:
std::string LOGGER;
std::string DBFILENAME;
std::string DELTAS;
std::string LEARN;
std::string DATABASE_LOGGER;
unsigned int count(const std::vector<std::string>& tokens, int offset, int ngram_size) const;
void check_learn_consistency(const Ngram& name) const;
void set_dbfilename (const std::string& filename);
void set_deltas (const std::string& deltas);
void set_database_logger_level (const std::string& level);
void set_learn (const std::string& learn_mode);
void init_database_connector_if_ready ();
DatabaseConnector* db;
std::string dbfilename;
std::string dbloglevel;
std::vector<double> deltas;
size_t cardinality; // cardinality == what is the n in n-gram?
bool learn_mode;
bool learn_mode_set;
Dispatcher<SmoothedNgramPredictor> dispatcher;
};
#endif // PRESAGE_SMOOTHEDNGRAMPREDICTOR
SmoothedNgramPredictor::DBFILENAME
std::string DBFILENAME
Definition: smoothedNgramPredictor.h:80
SmoothedNgramPredictor::set_database_logger_level
void set_database_logger_level(const std::string &level)
Definition: smoothedNgramPredictor.cpp:73
predictor.h
SmoothedNgramPredictor::DATABASE_LOGGER
std::string DATABASE_LOGGER
Definition: smoothedNgramPredictor.h:83
Observer
Definition: observer.h:34
SmoothedNgramPredictor::learn_mode_set
bool learn_mode_set
Definition: smoothedNgramPredictor.h:101
SmoothedNgramPredictor::db
DatabaseConnector * db
Definition: smoothedNgramPredictor.h:95
SmoothedNgramPredictor::set_deltas
void set_deltas(const std::string &deltas)
Definition: smoothedNgramPredictor.cpp:79
SmoothedNgramPredictor::~SmoothedNgramPredictor
~SmoothedNgramPredictor()
Definition: smoothedNgramPredictor.cpp:58
SmoothedNgramPredictor::deltas
std::vector< double > deltas
Definition: smoothedNgramPredictor.h:98
SmoothedNgramPredictor::init_database_connector_if_ready
void init_database_connector_if_ready()
Definition: smoothedNgramPredictor.cpp:107
SmoothedNgramPredictor::set_dbfilename
void set_dbfilename(const std::string &filename)
Definition: smoothedNgramPredictor.cpp:64
Ngram
Definition: ngram.h:33
SmoothedNgramPredictor::update
virtual void update(const Observable *variable)
Definition: smoothedNgramPredictor.cpp:499
Prediction
Definition: prediction.h:47
SmoothedNgramPredictor::LOGGER
std::string LOGGER
Definition: smoothedNgramPredictor.h:79
Predictor::name
const std::string name
Definition: predictor.h:97
Predictor
Definition: predictor.h:46
SmoothedNgramPredictor::learn
virtual void learn(const std::vector< std::string > &change)
Definition: smoothedNgramPredictor.cpp:335
SmoothedNgramPredictor::SmoothedNgramPredictor
SmoothedNgramPredictor(Configuration *, ContextTracker *, const char *)
Definition: smoothedNgramPredictor.cpp:31
SmoothedNgramPredictor::dispatcher
Dispatcher< SmoothedNgramPredictor > dispatcher
Definition: smoothedNgramPredictor.h:103
ContextTracker
Tracks user interaction and context.
Definition: contextTracker.h:155
SmoothedNgramPredictor::DELTAS
std::string DELTAS
Definition: smoothedNgramPredictor.h:81
SmoothedNgramPredictor::count
unsigned int count(const std::vector< std::string > &tokens, int offset, int ngram_size) const
Builds the required n-gram and returns its count.
Definition: smoothedNgramPredictor.cpp:171
SmoothedNgramPredictor::cardinality
size_t cardinality
Definition: smoothedNgramPredictor.h:99
SmoothedNgramPredictor::check_learn_consistency
void check_learn_consistency(const Ngram &name) const
Definition: smoothedNgramPredictor.cpp:464
SmoothedNgramPredictor
Definition: smoothedNgramPredictor.h:47
DatabaseConnector
Definition: databaseConnector.h:44
SmoothedNgramPredictor::predict
virtual Prediction predict(const size_t size, const char **filter) const
Generate prediction.
Definition: smoothedNgramPredictor.cpp:191
SmoothedNgramPredictor::LEARN
std::string LEARN
Definition: smoothedNgramPredictor.h:82
Configuration
Definition: configuration.h:36
SmoothedNgramPredictor::learn_mode
bool learn_mode
Definition: smoothedNgramPredictor.h:100
SmoothedNgramPredictor::set_learn
void set_learn(const std::string &learn_mode)
Definition: smoothedNgramPredictor.cpp:96
sqliteDatabaseConnector.h
SmoothedNgramPredictor::dbfilename
std::string dbfilename
Definition: smoothedNgramPredictor.h:96
Observable
Definition: observable.h:37
Dispatcher< SmoothedNgramPredictor >
SmoothedNgramPredictor::dbloglevel
std::string dbloglevel
Definition: smoothedNgramPredictor.h:97