SmoothedNgramPredictor Class Reference

`#include <smoothedNgramPredictor.h>`

Inheritance diagram for SmoothedNgramPredictor:
Collaboration diagram for SmoothedNgramPredictor:

## 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_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 | LEARN
std::string | DATABASE_LOGGER
DatabaseConnector * | db
std::string | dbfilename
std::string | dbloglevel
std::vector< double > | deltas
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

## Detailed Description

Smoothed n-gram statistical predictor.

Definition at line 46 of file smoothedNgramPredictor.h.

## Constructor & Destructor Documentation

## SmoothedNgramPredictor()

SmoothedNgramPredictor::SmoothedNgramPredictor | ( | Configuration * | config,
|  | ContextTracker * | ct,
|  | const char * | name
| ) |  |

Definition at line 31 of file smoothedNgramPredictor.cpp.

References config, DATABASE_LOGGER, DBFILENAME, DELTAS, dispatcher, LEARN, LOGGER, Dispatcher< class_t >::map(), Predictor::name, Predictor::PREDICTORS, set_database_logger_level(), set_dbfilename(), set_deltas(), set_learn(), and Predictor::set_logger().

Here is the call graph for this function:

## ~SmoothedNgramPredictor()

SmoothedNgramPredictor::~SmoothedNgramPredictor | ( |  | ) |

Definition at line 58 of file smoothedNgramPredictor.cpp.

References db.

## Member Function Documentation

## check_learn_consistency()

void SmoothedNgramPredictor::check_learn_consistency | ( | const Ngram & | name | ) | const

private

Definition at line 464 of file smoothedNgramPredictor.cpp.

References count(), db, endl(), DatabaseConnector::incrementNgramCount(), Predictor::logger, and Logger< _charT, _Traits >::shouldLog().

Referenced by learn().

Here is the call graph for this function:
Here is the caller graph for this function:

## count()

unsigned int SmoothedNgramPredictor::count | ( | const std::vector< std::string > & | tokens,
|  | int | offset,
|  | int | ngram_size
| ) |  | const

private

Builds the required n-gram and returns its count.

Parameters

  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

Returns
  count of the ngram built based on tokens, offset and ngram_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 171 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().

Here is the call graph for this function:
Here is the caller graph for this function:

## init_database_connector_if_ready()

void SmoothedNgramPredictor::init_database_connector_if_ready | ( |  | ) |

private

Definition at line 107 of file smoothedNgramPredictor.cpp.

References cardinality, db, dbfilename, dbloglevel, learn_mode, and learn_mode_set.

Referenced by set_dbfilename(), set_deltas(), and set_learn().

Here is the caller graph for this function:

## learn()

void SmoothedNgramPredictor::learn | ( | const std::vector< std::string > & | change | ) |

virtual

Implements Predictor.

Definition at line 335 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().

Here is the call graph for this function:

## predict()

Prediction SmoothedNgramPredictor::predict | ( | const size_t | size,
|  | const char ** | filter
| ) |  | const

virtual

Generate prediction.

Parameters

  size | desired prediction size
  filter | filter

Implements Predictor.

Definition at line 191 of file smoothedNgramPredictor.cpp.

References Prediction::addSuggestion(), DatabaseConnector::beginTransaction(), cardinality, Predictor::contextTracker, count(), db, deltas, endl(), DatabaseConnector::endTransaction(), DatabaseConnector::getNgramLikeTable(), DatabaseConnector::getNgramLikeTableFiltered(), ContextTracker::getToken(), DatabaseConnector::getUnigramCountsSum(), Predictor::logger, and Logger< _charT, _Traits >::shouldLog().

Here is the call graph for this function:

## set_database_logger_level()

void SmoothedNgramPredictor::set_database_logger_level | ( | const std::string & | level | ) |

private

Definition at line 73 of file smoothedNgramPredictor.cpp.

References dbloglevel.

Referenced by SmoothedNgramPredictor().

Here is the caller graph for this function:

## set_dbfilename()

void SmoothedNgramPredictor::set_dbfilename | ( | const std::string & | filename | ) |

private

Definition at line 64 of file smoothedNgramPredictor.cpp.

References dbfilename, endl(), init_database_connector_if_ready(), and Predictor::logger.

Referenced by SmoothedNgramPredictor().

Here is the call graph for this function:
Here is the caller graph for this function:

## set_deltas()

void SmoothedNgramPredictor::set_deltas | ( | const std::string & | deltas | ) |

private

Definition at line 79 of file smoothedNgramPredictor.cpp.

References cardinality, deltas, endl(), init_database_connector_if_ready(), Predictor::logger, and Utility::toDouble().

Referenced by SmoothedNgramPredictor().

Here is the call graph for this function:
Here is the caller graph for this function:

## set_learn()

void SmoothedNgramPredictor::set_learn | ( | const std::string & | learn_mode | ) |

private

Definition at line 96 of file smoothedNgramPredictor.cpp.

References endl(), init_database_connector_if_ready(), Utility::isYes(), learn_mode, learn_mode_set, and Predictor::logger.

Referenced by SmoothedNgramPredictor().

Here is the call graph for this function:
Here is the caller graph for this function:

## update()

void SmoothedNgramPredictor::update | ( | const Observable * | variable | ) |

virtual

Implements Observer.

Definition at line 499 of file smoothedNgramPredictor.cpp.

References Dispatcher< class_t >::dispatch(), dispatcher, endl(), Observable::get_name(), Observable::get_value(), and Predictor::logger.

Here is the call graph for this function:

## Member Data Documentation

## cardinality

size_t SmoothedNgramPredictor::cardinality

private

Definition at line 97 of file smoothedNgramPredictor.h.

Referenced by init_database_connector_if_ready(), learn(), predict(), and set_deltas().

## DATABASE_LOGGER

std::string SmoothedNgramPredictor::DATABASE_LOGGER

private

Definition at line 81 of file smoothedNgramPredictor.h.

Referenced by SmoothedNgramPredictor().

## db

DatabaseConnector* SmoothedNgramPredictor::db

private

Definition at line 93 of file smoothedNgramPredictor.h.

Referenced by check_learn_consistency(), count(), init_database_connector_if_ready(), learn(), predict(), and ~SmoothedNgramPredictor().

## DBFILENAME

std::string SmoothedNgramPredictor::DBFILENAME

private

Definition at line 78 of file smoothedNgramPredictor.h.

Referenced by SmoothedNgramPredictor().

## dbfilename

std::string SmoothedNgramPredictor::dbfilename

private

Definition at line 94 of file smoothedNgramPredictor.h.

Referenced by init_database_connector_if_ready(), and set_dbfilename().

## dbloglevel

std::string SmoothedNgramPredictor::dbloglevel

private

Definition at line 95 of file smoothedNgramPredictor.h.

Referenced by init_database_connector_if_ready(), and set_database_logger_level().

## DELTAS

std::string SmoothedNgramPredictor::DELTAS

private

Definition at line 79 of file smoothedNgramPredictor.h.

Referenced by SmoothedNgramPredictor().

## deltas

std::vector<double> SmoothedNgramPredictor::deltas

private

Definition at line 96 of file smoothedNgramPredictor.h.

Referenced by predict(), and set_deltas().

## dispatcher

Dispatcher<SmoothedNgramPredictor> SmoothedNgramPredictor::dispatcher

private

Definition at line 101 of file smoothedNgramPredictor.h.

Referenced by SmoothedNgramPredictor(), and update().

## LEARN

std::string SmoothedNgramPredictor::LEARN

private

Definition at line 80 of file smoothedNgramPredictor.h.

Referenced by SmoothedNgramPredictor().

## learn_mode

bool SmoothedNgramPredictor::learn_mode

private

Definition at line 98 of file smoothedNgramPredictor.h.

Referenced by init_database_connector_if_ready(), learn(), and set_learn().

## learn_mode_set

bool SmoothedNgramPredictor::learn_mode_set

private

Definition at line 99 of file smoothedNgramPredictor.h.

Referenced by init_database_connector_if_ready(), and set_learn().

## LOGGER

std::string SmoothedNgramPredictor::LOGGER

private

Definition at line 77 of file smoothedNgramPredictor.h.

Referenced by SmoothedNgramPredictor().

The documentation for this class was generated from the following files:

- /build/presage-hvZ4Ld/presage-0.9.1/src/lib/predictors/smoothedNgramPredictor.h
- /build/presage-hvZ4Ld/presage-0.9.1/src/lib/predictors/smoothedNgramPredictor.cpp