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

#include <ARPAPredictor.h>

Inheritance diagram for ARPAPredictor:
Inheritance graph
Collaboration diagram for ARPAPredictor:
Collaboration graph

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, ARPADataunigramMap
 
std::map< BigramKey, ARPADatabigramMap
 
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< ARPAPredictordispatcher
 

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 112 of file ARPAPredictor.h.

Constructor & Destructor Documentation

◆ ARPAPredictor()

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

◆ ~ARPAPredictor()

ARPAPredictor::~ARPAPredictor ( )

Definition at line 298 of file ARPAPredictor.cpp.

References bigramProg, trigramProg, and unigramProg.

Member Function Documentation

◆ addBigram()

void ARPAPredictor::addBigram ( std::string  row)
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().

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

◆ addTrigram()

void ARPAPredictor::addTrigram ( std::string  row)
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().

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

◆ addUnigram()

void ARPAPredictor::addUnigram ( std::string  row)
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().

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

◆ computeBigramBackoff()

float ARPAPredictor::computeBigramBackoff ( int  wd1,
int  wd2 
) const
inlineprivate

Computes P( wd2 | wd1 )

Definition at line 443 of file ARPAPredictor.cpp.

References bigramMap, and unigramMap.

Referenced by computeTrigramBackoff(), and predict().

Here is the caller graph for this function:

◆ computeTrigramBackoff()

float ARPAPredictor::computeTrigramBackoff ( int  wd1,
int  wd2,
int  wd3 
) const
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().

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

◆ createARPATable()

void ARPAPredictor::createARPATable ( )
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().

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

◆ learn()

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

Implements Predictor.

Definition at line 455 of file ARPAPredictor.cpp.

References endl(), and Predictor::logger.

Here is the call graph for this function:

◆ loadVocabulary()

void ARPAPredictor::loadVocabulary ( )
private

Definition at line 79 of file ARPAPredictor.cpp.

References endl(), Predictor::logger, vocabCode, vocabDecode, and vocabFilename.

Referenced by ARPAPredictor().

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

◆ matchesPrefixAndFilter()

bool ARPAPredictor::matchesPrefixAndFilter ( std::string  word,
std::string  prefix,
const char **  filter 
) const
private

Definition at line 305 of file ARPAPredictor.cpp.

Referenced by predict().

Here is the caller graph for this function:

◆ predict()

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

Generate prediction.

Parameters
sizedesired prediction size
filterfilter

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.

Here is the call graph for this function:

◆ set_arpa_filename()

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

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

◆ set_timeout()

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

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

◆ set_vocab_filename()

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

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

◆ update()

void ARPAPredictor::update ( const Observable variable)
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.

Here is the call graph for this function:

Member Data Documentation

◆ ARPAFILENAME

std::string ARPAPredictor::ARPAFILENAME
private

Definition at line 130 of file ARPAPredictor.h.

Referenced by ARPAPredictor().

◆ arpaFilename

std::string ARPAPredictor::arpaFilename
private

Definition at line 134 of file ARPAPredictor.h.

Referenced by createARPATable(), and set_arpa_filename().

◆ bigramCount

int ARPAPredictor::bigramCount
private

Definition at line 157 of file ARPAPredictor.h.

Referenced by addBigram(), and createARPATable().

◆ bigramMap

std::map<BigramKey,ARPAData> ARPAPredictor::bigramMap
private

Definition at line 142 of file ARPAPredictor.h.

Referenced by addBigram(), computeBigramBackoff(), and computeTrigramBackoff().

◆ bigramProg

ProgressBar<char>* ARPAPredictor::bigramProg
private

Definition at line 165 of file ARPAPredictor.h.

Referenced by addBigram(), createARPATable(), and ~ARPAPredictor().

◆ bigramTot

int ARPAPredictor::bigramTot
private

Definition at line 161 of file ARPAPredictor.h.

Referenced by addBigram(), and createARPATable().

◆ dispatcher

Dispatcher<ARPAPredictor> ARPAPredictor::dispatcher
private

Definition at line 168 of file ARPAPredictor.h.

Referenced by ARPAPredictor(), and update().

◆ LOGGER

std::string ARPAPredictor::LOGGER
private

Definition at line 129 of file ARPAPredictor.h.

Referenced by ARPAPredictor().

◆ TIMEOUT

std::string ARPAPredictor::TIMEOUT
private

Definition at line 132 of file ARPAPredictor.h.

Referenced by ARPAPredictor().

◆ timeout

int ARPAPredictor::timeout
private

Definition at line 136 of file ARPAPredictor.h.

Referenced by set_timeout().

◆ trigramCount

int ARPAPredictor::trigramCount
private

Definition at line 158 of file ARPAPredictor.h.

Referenced by addTrigram(), and createARPATable().

◆ trigramMap

std::map<TrigramKey,float> ARPAPredictor::trigramMap
private

Definition at line 143 of file ARPAPredictor.h.

Referenced by addTrigram(), and computeTrigramBackoff().

◆ trigramProg

ProgressBar<char>* ARPAPredictor::trigramProg
private

Definition at line 166 of file ARPAPredictor.h.

Referenced by addTrigram(), createARPATable(), and ~ARPAPredictor().

◆ trigramTot

int ARPAPredictor::trigramTot
private

Definition at line 162 of file ARPAPredictor.h.

Referenced by addTrigram(), and createARPATable().

◆ unigramCount

int ARPAPredictor::unigramCount
private

Definition at line 156 of file ARPAPredictor.h.

Referenced by addUnigram(), and createARPATable().

◆ unigramMap

std::map<int,ARPAData> ARPAPredictor::unigramMap
private

Definition at line 141 of file ARPAPredictor.h.

Referenced by addUnigram(), computeBigramBackoff(), and predict().

◆ unigramProg

ProgressBar<char>* ARPAPredictor::unigramProg
private

Definition at line 164 of file ARPAPredictor.h.

Referenced by addUnigram(), createARPATable(), and ~ARPAPredictor().

◆ unigramTot

int ARPAPredictor::unigramTot
private

Definition at line 160 of file ARPAPredictor.h.

Referenced by addUnigram(), and createARPATable().

◆ vocabCode

std::map<std::string,int> ARPAPredictor::vocabCode
private

Definition at line 138 of file ARPAPredictor.h.

Referenced by addBigram(), addTrigram(), addUnigram(), loadVocabulary(), and predict().

◆ vocabDecode

std::map<int,std::string> ARPAPredictor::vocabDecode
private

Definition at line 139 of file ARPAPredictor.h.

Referenced by computeTrigramBackoff(), loadVocabulary(), and predict().

◆ VOCABFILENAME

std::string ARPAPredictor::VOCABFILENAME
private

Definition at line 131 of file ARPAPredictor.h.

Referenced by ARPAPredictor().

◆ vocabFilename

std::string ARPAPredictor::vocabFilename
private

Definition at line 135 of file ARPAPredictor.h.

Referenced by loadVocabulary(), and set_vocab_filename().


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