presage
0.9.2~beta
|
#include <ARPAPredictor.h>
Public Member Functions | |
ARPAPredictor (Configuration *, ContextTracker *, const char *) | |
~ARPAPredictor () | |
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) |
void | set_vocab_filename (const std::string &value) |
void | set_arpa_filename (const std::string &value) |
void | set_timeout (const std::string &value) |
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 | |
void | loadVocabulary () |
void | createARPATable () |
bool | matchesPrefixAndFilter (std::string, std::string, const char **) const |
void | addUnigram (std::string) |
void | addBigram (std::string) |
void | addTrigram (std::string) |
float | computeTrigramBackoff (int, int, int) const |
float | computeBigramBackoff (int, int) const |
Private Attributes | |
std::string | LOGGER |
std::string | ARPAFILENAME |
std::string | VOCABFILENAME |
std::string | TIMEOUT |
std::string | arpaFilename |
std::string | vocabFilename |
int | timeout |
std::map< std::string, int > | vocabCode |
std::map< int, std::string > | vocabDecode |
std::map< int, ARPAData > | unigramMap |
std::map< BigramKey, ARPAData > | bigramMap |
std::map< TrigramKey, float > | trigramMap |
int | unigramCount |
int | bigramCount |
int | trigramCount |
int | unigramTot |
int | bigramTot |
int | trigramTot |
ProgressBar< char > * | unigramProg |
ProgressBar< char > * | bigramProg |
ProgressBar< char > * | trigramProg |
Dispatcher< ARPAPredictor > | 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 112 of file ARPAPredictor.h.
ARPAPredictor::ARPAPredictor | ( | Configuration * | config, |
ContextTracker * | ct, | ||
const char * | name | ||
) |
Definition at line 37 of file ARPAPredictor.cpp.
References ARPAFILENAME, config, createARPATable(), dispatcher, loadVocabulary(), LOGGER, Dispatcher< class_t >::map(), Predictor::name, Predictor::PREDICTORS, set_arpa_filename(), Predictor::set_logger(), set_timeout(), set_vocab_filename(), TIMEOUT, and VOCABFILENAME.
ARPAPredictor::~ARPAPredictor | ( | ) |
Definition at line 298 of file ARPAPredictor.cpp.
References bigramProg, trigramProg, and unigramProg.
|
private |
Definition at line 241 of file ARPAPredictor.cpp.
References bigramCount, bigramMap, bigramProg, bigramTot, endl(), Predictor::logger, OOV, ProgressBar< _charT, _Traits >::update(), and vocabCode.
Referenced by createARPATable().
|
private |
Definition at line 268 of file ARPAPredictor.cpp.
References endl(), Predictor::logger, OOV, trigramCount, trigramMap, trigramProg, trigramTot, ProgressBar< _charT, _Traits >::update(), and vocabCode.
Referenced by createARPATable().
|
private |
Definition at line 214 of file ARPAPredictor.cpp.
References endl(), Predictor::logger, OOV, unigramCount, unigramMap, unigramProg, unigramTot, ProgressBar< _charT, _Traits >::update(), and vocabCode.
Referenced by createARPATable().
|
inlineprivate |
Computes P( wd2 | wd1 )
Definition at line 443 of file ARPAPredictor.cpp.
References bigramMap, and unigramMap.
Referenced by computeTrigramBackoff(), and predict().
|
inlineprivate |
Computes P(wd3 | wd1 wd2)
Definition at line 409 of file ARPAPredictor.cpp.
References bigramMap, computeBigramBackoff(), endl(), Predictor::logger, trigramMap, and vocabDecode.
Referenced by predict().
|
private |
Definition at line 106 of file ARPAPredictor.cpp.
References addBigram(), addTrigram(), addUnigram(), arpaFilename, bigramCount, bigramProg, bigramTot, endl(), Predictor::logger, trigramCount, trigramProg, trigramTot, unigramCount, unigramProg, and unigramTot.
Referenced by ARPAPredictor().
|
virtual |
Implements Predictor.
Definition at line 455 of file ARPAPredictor.cpp.
References endl(), and Predictor::logger.
|
private |
Definition at line 79 of file ARPAPredictor.cpp.
References endl(), Predictor::logger, vocabCode, vocabDecode, and vocabFilename.
Referenced by ARPAPredictor().
|
private |
Definition at line 305 of file ARPAPredictor.cpp.
Referenced by predict().
|
virtual |
Generate prediction.
size | desired prediction size |
filter | filter |
note if we have not tokens to compute 3-gram probabilities we compute 2-gram or 1-gram probabilities. the following code might be repetitive but more efficient than having the main loop outside.
Implements Predictor.
Definition at line 320 of file ARPAPredictor.cpp.
References Prediction::addSuggestion(), computeBigramBackoff(), computeTrigramBackoff(), Predictor::contextTracker, endl(), ContextTracker::getToken(), Predictor::logger, matchesPrefixAndFilter(), Utility::strtolower(), unigramMap, vocabCode, and vocabDecode.
void ARPAPredictor::set_arpa_filename | ( | const std::string & | value | ) |
Definition at line 67 of file ARPAPredictor.cpp.
References arpaFilename, endl(), and Predictor::logger.
Referenced by ARPAPredictor().
void ARPAPredictor::set_timeout | ( | const std::string & | value | ) |
Definition at line 73 of file ARPAPredictor.cpp.
References endl(), Predictor::logger, and timeout.
Referenced by ARPAPredictor().
void ARPAPredictor::set_vocab_filename | ( | const std::string & | value | ) |
Definition at line 61 of file ARPAPredictor.cpp.
References endl(), Predictor::logger, and vocabFilename.
Referenced by ARPAPredictor().
|
virtual |
Implements Observer.
Definition at line 461 of file ARPAPredictor.cpp.
References Dispatcher< class_t >::dispatch(), dispatcher, endl(), Observable::get_name(), Observable::get_value(), and Predictor::logger.
|
private |
Definition at line 130 of file ARPAPredictor.h.
Referenced by ARPAPredictor().
|
private |
Definition at line 134 of file ARPAPredictor.h.
Referenced by createARPATable(), and set_arpa_filename().
|
private |
Definition at line 157 of file ARPAPredictor.h.
Referenced by addBigram(), and createARPATable().
Definition at line 142 of file ARPAPredictor.h.
Referenced by addBigram(), computeBigramBackoff(), and computeTrigramBackoff().
|
private |
Definition at line 165 of file ARPAPredictor.h.
Referenced by addBigram(), createARPATable(), and ~ARPAPredictor().
|
private |
Definition at line 161 of file ARPAPredictor.h.
Referenced by addBigram(), and createARPATable().
|
private |
Definition at line 168 of file ARPAPredictor.h.
Referenced by ARPAPredictor(), and update().
|
private |
Definition at line 129 of file ARPAPredictor.h.
Referenced by ARPAPredictor().
|
private |
Definition at line 132 of file ARPAPredictor.h.
Referenced by ARPAPredictor().
|
private |
Definition at line 136 of file ARPAPredictor.h.
Referenced by set_timeout().
|
private |
Definition at line 158 of file ARPAPredictor.h.
Referenced by addTrigram(), and createARPATable().
|
private |
Definition at line 143 of file ARPAPredictor.h.
Referenced by addTrigram(), and computeTrigramBackoff().
|
private |
Definition at line 166 of file ARPAPredictor.h.
Referenced by addTrigram(), createARPATable(), and ~ARPAPredictor().
|
private |
Definition at line 162 of file ARPAPredictor.h.
Referenced by addTrigram(), and createARPATable().
|
private |
Definition at line 156 of file ARPAPredictor.h.
Referenced by addUnigram(), and createARPATable().
|
private |
Definition at line 141 of file ARPAPredictor.h.
Referenced by addUnigram(), computeBigramBackoff(), and predict().
|
private |
Definition at line 164 of file ARPAPredictor.h.
Referenced by addUnigram(), createARPATable(), and ~ARPAPredictor().
|
private |
Definition at line 160 of file ARPAPredictor.h.
Referenced by addUnigram(), and createARPATable().
|
private |
Definition at line 138 of file ARPAPredictor.h.
Referenced by addBigram(), addTrigram(), addUnigram(), loadVocabulary(), and predict().
|
private |
Definition at line 139 of file ARPAPredictor.h.
Referenced by computeTrigramBackoff(), loadVocabulary(), and predict().
|
private |
Definition at line 131 of file ARPAPredictor.h.
Referenced by ARPAPredictor().
|
private |
Definition at line 135 of file ARPAPredictor.h.
Referenced by loadVocabulary(), and set_vocab_filename().