presage
0.9.2~beta
|
#include <smoothedNgramPredictor.h>
Public Member Functions | |
SmoothedNgramPredictor (Configuration *, ContextTracker *, const char *) | |
~SmoothedNgramPredictor () | |
virtual Prediction | predict (const size_t size, const char **filter) const |
Generate prediction. More... | |
virtual void | learn (const std::vector< std::string > &change) |
virtual void | update (const Observable *variable) |
Public Member Functions inherited from Predictor | |
Predictor (Configuration *configuration, ContextTracker *contextTracker, const char *predictorName="Predictor", const char *shortDescription="", const char *longDescription="") | |
virtual | ~Predictor () |
const std::string | getName () const |
const std::string | getShortDescription () const |
const std::string | getLongDescription () const |
Public Member Functions inherited from Observer | |
virtual | ~Observer () |
Private Member Functions | |
unsigned int | count (const std::vector< std::string > &tokens, int offset, int ngram_size) const |
Builds the required n-gram and returns its count. More... | |
void | check_learn_consistency (const Ngram &name) const |
void | set_dbfilename (const std::string &filename) |
void | set_deltas (const std::string &deltas) |
void | set_count_threshold (const std::string &value) |
void | set_database_logger_level (const std::string &level) |
void | set_learn (const std::string &learn_mode) |
void | init_database_connector_if_ready () |
Private Attributes | |
std::string | LOGGER |
std::string | DBFILENAME |
std::string | DELTAS |
std::string | COUNT_THRESHOLD |
std::string | LEARN |
std::string | DATABASE_LOGGER |
DatabaseConnector * | db |
std::string | dbfilename |
std::string | dbloglevel |
std::vector< double > | deltas |
int | count_threshold |
size_t | cardinality |
bool | learn_mode |
bool | learn_mode_set |
Dispatcher< SmoothedNgramPredictor > | dispatcher |
Additional Inherited Members | |
Protected Member Functions inherited from Predictor | |
virtual bool | token_satisfies_filter (const std::string &token, const std::string &prefix, const char **filter) const |
virtual void | set_logger (const std::string &level) |
Protected Member Functions inherited from Observer | |
Observer () | |
Protected Attributes inherited from Predictor | |
const std::string | name |
const std::string | shortDescription |
const std::string | longDescription |
const std::string | PREDICTORS |
ContextTracker * | contextTracker |
Configuration * | configuration |
Logger< char > | logger |
Smoothed n-gram statistical predictor.
Definition at line 47 of file smoothedNgramPredictor.h.
SmoothedNgramPredictor::SmoothedNgramPredictor | ( | Configuration * | config, |
ContextTracker * | ct, | ||
const char * | name | ||
) |
Definition at line 31 of file smoothedNgramPredictor.cpp.
References config, COUNT_THRESHOLD, DATABASE_LOGGER, DBFILENAME, DELTAS, dispatcher, LEARN, LOGGER, Dispatcher< class_t >::map(), Predictor::name, Predictor::PREDICTORS, set_count_threshold(), set_database_logger_level(), set_dbfilename(), set_deltas(), set_learn(), and Predictor::set_logger().
SmoothedNgramPredictor::~SmoothedNgramPredictor | ( | ) |
Definition at line 61 of file smoothedNgramPredictor.cpp.
References db.
|
private |
Definition at line 473 of file smoothedNgramPredictor.cpp.
References count(), db, endl(), DatabaseConnector::incrementNgramCount(), Predictor::logger, and Logger< _charT, _Traits >::shouldLog().
Referenced by learn().
|
private |
Builds the required n-gram and returns its count.
tokens | tokens[i] contains ContextTracker::getToken(i) |
offset | entry point into tokens, must be a non-positive number |
ngram_size | size of the ngram whose count is returned, must not be greater than tokens size |
Let tokens = [ "how", "are", "you", "today" ]; count(tokens, 0, 3) returns the count associated with 3-gram [ "are", "you", "today" ]. count(tokens, -1, 2) returns the count associated with 2-gram [ "are", "you" ]; *
Definition at line 181 of file smoothedNgramPredictor.cpp.
References db, endl(), DatabaseConnector::getNgramCount(), DatabaseConnector::getUnigramCountsSum(), Predictor::logger, and ngram_to_string().
Referenced by check_learn_consistency(), learn(), and predict().
|
private |
Definition at line 117 of file smoothedNgramPredictor.cpp.
References cardinality, db, dbfilename, dbloglevel, learn_mode, and learn_mode_set.
Referenced by set_dbfilename(), set_deltas(), and set_learn().
|
virtual |
Implements Predictor.
Definition at line 344 of file smoothedNgramPredictor.cpp.
References DatabaseConnector::beginTransaction(), cardinality, check_learn_consistency(), Predictor::contextTracker, count(), db, endl(), DatabaseConnector::endTransaction(), ContextTracker::getExtraTokenToLearn(), DatabaseConnector::getNgramCount(), ContextTracker::getToken(), DatabaseConnector::insertNgram(), learn_mode, Predictor::logger, ngram_to_string(), DatabaseConnector::rollbackTransaction(), DatabaseConnector::updateNgram(), and PresageException::what().
|
virtual |
Generate prediction.
size | desired prediction size |
filter | filter |
Implements Predictor.
Definition at line 201 of file smoothedNgramPredictor.cpp.
References Prediction::addSuggestion(), DatabaseConnector::beginTransaction(), cardinality, Predictor::contextTracker, count(), count_threshold, db, deltas, endl(), DatabaseConnector::endTransaction(), DatabaseConnector::getNgramLikeTable(), ContextTracker::getToken(), DatabaseConnector::getUnigramCountsSum(), Predictor::logger, and Logger< _charT, _Traits >::shouldLog().
|
private |
Definition at line 99 of file smoothedNgramPredictor.cpp.
References count_threshold, endl(), Predictor::logger, and Utility::toInt().
Referenced by SmoothedNgramPredictor().
|
private |
Definition at line 76 of file smoothedNgramPredictor.cpp.
References dbloglevel.
Referenced by SmoothedNgramPredictor().
|
private |
Definition at line 67 of file smoothedNgramPredictor.cpp.
References dbfilename, endl(), init_database_connector_if_ready(), and Predictor::logger.
Referenced by SmoothedNgramPredictor().
|
private |
Definition at line 82 of file smoothedNgramPredictor.cpp.
References cardinality, deltas, endl(), init_database_connector_if_ready(), Predictor::logger, and Utility::toDouble().
Referenced by SmoothedNgramPredictor().
|
private |
Definition at line 106 of file smoothedNgramPredictor.cpp.
References endl(), init_database_connector_if_ready(), Utility::isYes(), learn_mode, learn_mode_set, and Predictor::logger.
Referenced by SmoothedNgramPredictor().
|
virtual |
Implements Observer.
Definition at line 508 of file smoothedNgramPredictor.cpp.
References Dispatcher< class_t >::dispatch(), dispatcher, endl(), Observable::get_name(), Observable::get_value(), and Predictor::logger.
|
private |
Definition at line 82 of file smoothedNgramPredictor.h.
Referenced by init_database_connector_if_ready(), learn(), predict(), and set_deltas().
|
private |
Definition at line 62 of file smoothedNgramPredictor.h.
Referenced by SmoothedNgramPredictor().
|
private |
Definition at line 81 of file smoothedNgramPredictor.h.
Referenced by predict(), and set_count_threshold().
|
private |
Definition at line 64 of file smoothedNgramPredictor.h.
Referenced by SmoothedNgramPredictor().
|
private |
Definition at line 77 of file smoothedNgramPredictor.h.
Referenced by check_learn_consistency(), count(), init_database_connector_if_ready(), learn(), predict(), and ~SmoothedNgramPredictor().
|
private |
Definition at line 60 of file smoothedNgramPredictor.h.
Referenced by SmoothedNgramPredictor().
|
private |
Definition at line 78 of file smoothedNgramPredictor.h.
Referenced by init_database_connector_if_ready(), and set_dbfilename().
|
private |
Definition at line 79 of file smoothedNgramPredictor.h.
Referenced by init_database_connector_if_ready(), and set_database_logger_level().
|
private |
Definition at line 61 of file smoothedNgramPredictor.h.
Referenced by SmoothedNgramPredictor().
|
private |
Definition at line 80 of file smoothedNgramPredictor.h.
Referenced by predict(), and set_deltas().
|
private |
Definition at line 86 of file smoothedNgramPredictor.h.
Referenced by SmoothedNgramPredictor(), and update().
|
private |
Definition at line 63 of file smoothedNgramPredictor.h.
Referenced by SmoothedNgramPredictor().
|
private |
Definition at line 83 of file smoothedNgramPredictor.h.
Referenced by init_database_connector_if_ready(), learn(), and set_learn().
|
private |
Definition at line 84 of file smoothedNgramPredictor.h.
Referenced by init_database_connector_if_ready(), and set_learn().
|
private |
Definition at line 59 of file smoothedNgramPredictor.h.
Referenced by SmoothedNgramPredictor().