presage  0.9.2~beta
Public Member Functions | Private Member Functions | Private Attributes | List of all members
SmoothedNgramPredictor Class Reference

#include <smoothedNgramPredictor.h>

Inheritance diagram for SmoothedNgramPredictor:
Inheritance graph
Collaboration diagram for SmoothedNgramPredictor:
Collaboration graph

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
 
DatabaseConnectordb
 
std::string dbfilename
 
std::string dbloglevel
 
std::vector< double > deltas
 
int count_threshold
 
size_t cardinality
 
bool learn_mode
 
bool learn_mode_set
 
Dispatcher< SmoothedNgramPredictordispatcher
 

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
 
ContextTrackercontextTracker
 
Configurationconfiguration
 
Logger< char > logger
 

Detailed Description

Smoothed n-gram statistical predictor.

Definition at line 47 of file smoothedNgramPredictor.h.

Constructor & Destructor Documentation

◆ SmoothedNgramPredictor()

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

◆ ~SmoothedNgramPredictor()

SmoothedNgramPredictor::~SmoothedNgramPredictor ( )

Definition at line 61 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 473 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
tokenstokens[i] contains ContextTracker::getToken(i)
offsetentry point into tokens, must be a non-positive number
ngram_sizesize 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 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().

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 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().

Here is the caller graph for this function:

◆ learn()

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

◆ predict()

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

◆ set_count_threshold()

void SmoothedNgramPredictor::set_count_threshold ( const std::string &  value)
private

Definition at line 99 of file smoothedNgramPredictor.cpp.

References count_threshold, endl(), Predictor::logger, and Utility::toInt().

Referenced by SmoothedNgramPredictor().

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

◆ set_database_logger_level()

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

Definition at line 76 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 67 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 82 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 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().

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 508 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

◆ COUNT_THRESHOLD

std::string SmoothedNgramPredictor::COUNT_THRESHOLD
private

Definition at line 62 of file smoothedNgramPredictor.h.

Referenced by SmoothedNgramPredictor().

◆ count_threshold

int SmoothedNgramPredictor::count_threshold
private

Definition at line 81 of file smoothedNgramPredictor.h.

Referenced by predict(), and set_count_threshold().

◆ DATABASE_LOGGER

std::string SmoothedNgramPredictor::DATABASE_LOGGER
private

Definition at line 64 of file smoothedNgramPredictor.h.

Referenced by SmoothedNgramPredictor().

◆ db

DatabaseConnector* SmoothedNgramPredictor::db
private

◆ DBFILENAME

std::string SmoothedNgramPredictor::DBFILENAME
private

Definition at line 60 of file smoothedNgramPredictor.h.

Referenced by SmoothedNgramPredictor().

◆ dbfilename

std::string SmoothedNgramPredictor::dbfilename
private

Definition at line 78 of file smoothedNgramPredictor.h.

Referenced by init_database_connector_if_ready(), and set_dbfilename().

◆ dbloglevel

std::string SmoothedNgramPredictor::dbloglevel
private

◆ DELTAS

std::string SmoothedNgramPredictor::DELTAS
private

Definition at line 61 of file smoothedNgramPredictor.h.

Referenced by SmoothedNgramPredictor().

◆ deltas

std::vector<double> SmoothedNgramPredictor::deltas
private

Definition at line 80 of file smoothedNgramPredictor.h.

Referenced by predict(), and set_deltas().

◆ dispatcher

Dispatcher<SmoothedNgramPredictor> SmoothedNgramPredictor::dispatcher
private

Definition at line 86 of file smoothedNgramPredictor.h.

Referenced by SmoothedNgramPredictor(), and update().

◆ LEARN

std::string SmoothedNgramPredictor::LEARN
private

Definition at line 63 of file smoothedNgramPredictor.h.

Referenced by SmoothedNgramPredictor().

◆ learn_mode

bool SmoothedNgramPredictor::learn_mode
private

Definition at line 83 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 84 of file smoothedNgramPredictor.h.

Referenced by init_database_connector_if_ready(), and set_learn().

◆ LOGGER

std::string SmoothedNgramPredictor::LOGGER
private

Definition at line 59 of file smoothedNgramPredictor.h.

Referenced by SmoothedNgramPredictor().


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