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

#include <dejavuPredictor.h>

Inheritance diagram for DejavuPredictor:
Inheritance graph
Collaboration diagram for DejavuPredictor:
Collaboration graph

Public Member Functions

 DejavuPredictor (Configuration *, ContextTracker *, const char *)
 
 ~DejavuPredictor ()
 
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 Types

typedef void(DejavuPredictor::* mbr_func_ptr_t) (const std::string &value)
 

Private Member Functions

bool init_memory_trigger (std::list< std::string > &) const
 
bool match (const std::list< std::string > &, const std::list< std::string > &) const
 
bool init_rolling_window (std::list< std::string > &, std::ifstream &) const
 
void update_rolling_window (std::list< std::string > &, const std::string &) const
 
void set_memory (const std::string &filename)
 
void set_trigger (const std::string &number)
 

Private Attributes

std::map< std::string, mbr_func_ptr_tdispatch_map
 
std::string LOGGER
 
std::string MEMORY
 
std::string TRIGGER
 
std::string memory
 
int trigger
 
Dispatcher< DejavuPredictordispatcher
 

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

Dejavu predictor learns and reproduces previously seen text tokens, once its memory is triggered by a known token sequence.

Dejavu predictor is able to learn and then later reproduce previously seen text sequences. The goal of dejavu predictor is to write a simple predictor that demonstrates how learning can be implemented in the presage system and exposes what functionality is required for learning predictors to work within the presage framework.

Definition at line 44 of file dejavuPredictor.h.

Member Typedef Documentation

◆ mbr_func_ptr_t

typedef void(DejavuPredictor::* DejavuPredictor::mbr_func_ptr_t) (const std::string &value)
private

Definition at line 56 of file dejavuPredictor.h.

Constructor & Destructor Documentation

◆ DejavuPredictor()

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

◆ ~DejavuPredictor()

DejavuPredictor::~DejavuPredictor ( )

Definition at line 56 of file dejavuPredictor.cpp.

Member Function Documentation

◆ init_memory_trigger()

bool DejavuPredictor::init_memory_trigger ( std::list< std::string > &  memory_trigger) const
private

Initialize memory trigger.

Parameters
memory_triggercontains tokens that will trigger a memory recollection
Returns
true if memory trigger has been populated with enough tokens to trigger a memory recollection, false otherwise

Definition at line 154 of file dejavuPredictor.cpp.

References Predictor::contextTracker, endl(), ContextTracker::getToken(), Predictor::logger, and trigger.

Referenced by predict().

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

◆ init_rolling_window()

bool DejavuPredictor::init_rolling_window ( std::list< std::string > &  rolling_window,
std::ifstream &  memory_file 
) const
private

Initialize rolling window.

Returns
true if initialized rolling window has been populated with enough tokens to trigger a memory recollection, false otherwise

Definition at line 182 of file dejavuPredictor.cpp.

References endl(), Predictor::logger, and trigger.

Referenced by predict().

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

◆ learn()

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

Implements Predictor.

Definition at line 116 of file dejavuPredictor.cpp.

References endl(), Predictor::logger, and memory.

Here is the call graph for this function:

◆ match()

bool DejavuPredictor::match ( const std::list< std::string > &  l1,
const std::list< std::string > &  l2 
) const
private

Tests two list arguments match.

Returns
true if lists contain the same tokens in the same order, false otherwise

Definition at line 140 of file dejavuPredictor.cpp.

Referenced by predict().

Here is the caller graph for this function:

◆ predict()

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

Generate prediction.

Parameters
sizedesired prediction size
filterfilter

Implements Predictor.

Definition at line 71 of file dejavuPredictor.cpp.

References Prediction::addSuggestion(), Predictor::contextTracker, endl(), ContextTracker::getPrefix(), init_memory_trigger(), init_rolling_window(), Predictor::logger, match(), memory, Predictor::token_satisfies_filter(), and update_rolling_window().

Here is the call graph for this function:

◆ set_memory()

void DejavuPredictor::set_memory ( const std::string &  filename)
private

Definition at line 59 of file dejavuPredictor.cpp.

References endl(), Predictor::logger, and memory.

Referenced by DejavuPredictor().

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

◆ set_trigger()

void DejavuPredictor::set_trigger ( const std::string &  number)
private

Definition at line 65 of file dejavuPredictor.cpp.

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

Referenced by DejavuPredictor().

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

◆ update()

void DejavuPredictor::update ( const Observable variable)
virtual

Implements Observer.

Definition at line 210 of file dejavuPredictor.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:

◆ update_rolling_window()

void DejavuPredictor::update_rolling_window ( std::list< std::string > &  rolling_window,
const std::string &  token 
) const
private

Update rolling window.

Pop front token and push back new token to list.

Definition at line 203 of file dejavuPredictor.cpp.

References endl(), and Predictor::logger.

Referenced by predict().

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

Member Data Documentation

◆ dispatch_map

std::map<std::string, mbr_func_ptr_t> DejavuPredictor::dispatch_map
private

Definition at line 57 of file dejavuPredictor.h.

◆ dispatcher

Dispatcher<DejavuPredictor> DejavuPredictor::dispatcher
private

Definition at line 74 of file dejavuPredictor.h.

Referenced by DejavuPredictor(), and update().

◆ LOGGER

std::string DejavuPredictor::LOGGER
private

Definition at line 67 of file dejavuPredictor.h.

Referenced by DejavuPredictor().

◆ MEMORY

std::string DejavuPredictor::MEMORY
private

Definition at line 68 of file dejavuPredictor.h.

Referenced by DejavuPredictor().

◆ memory

std::string DejavuPredictor::memory
private

Definition at line 71 of file dejavuPredictor.h.

Referenced by learn(), predict(), and set_memory().

◆ TRIGGER

std::string DejavuPredictor::TRIGGER
private

Definition at line 69 of file dejavuPredictor.h.

Referenced by DejavuPredictor().

◆ trigger

int DejavuPredictor::trigger
private

Definition at line 72 of file dejavuPredictor.h.

Referenced by init_memory_trigger(), init_rolling_window(), and set_trigger().


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