41 "DejavuPredictor, a parrot predictor",
42 "DejavuPredictor is a parrot predictor.\n" 43 "It always returns what it has heard before.\n"),
62 logger << INFO <<
"MEMORY: " << filename <<
endl;
68 logger << INFO <<
"TRIGGER: " << number <<
endl;
75 std::list<std::string> memory_trigger;
77 std::ifstream memory_file(
memory.c_str());
82 logger << INFO <<
"Memory trigger init'ed" <<
endl;
84 std::list<std::string> rolling_window;
86 logger << INFO <<
"Rolling window init'ed" <<
endl;
89 while (memory_file >> token) {
90 logger << INFO <<
"Analyzing token: " << token <<
endl;
92 if (
match(memory_trigger, rolling_window)) {
93 logger << INFO <<
"Token triggered memory: " << token <<
endl;
95 logger << INFO <<
"Adding suggestion: " << token <<
endl;
104 logger << INFO <<
"Rolling window initialization failed." <<
endl;
107 logger << INFO <<
"Memory trigger initialization failed." <<
endl;
119 for (std::vector<std::string>::const_iterator it = change.begin();
123 std::string new_token = *it;
124 logger << INFO <<
"Committing new token to memory: " << new_token <<
endl;
125 std::ofstream memory_file(
memory.c_str(), std::ios::app);
142 return equal(l1.begin(), l1.end(), l2.begin());
160 for (
int i =
trigger; i > 0; i--) {
167 if (memory_trigger.end() == find(memory_trigger.begin(), memory_trigger.end(),
"")) {
171 logger << INFO <<
"Memory trigger valid: " << result <<
endl;
190 while (count < trigger && memory_file >> token) {
191 logger << INFO <<
"Rolling window list: " << token <<
endl;
192 rolling_window.push_back(token);
205 rolling_window.pop_front();
206 logger << INFO <<
"Pushing back on memory list: " << token <<
endl;
207 rolling_window.push_back(token);
void set_memory(const std::string &filename)
static int toInt(const std::string)
void dispatch(const Observable *var)
DejavuPredictor(Configuration *, ContextTracker *, const char *)
bool match(const std::list< std::string > &, const std::list< std::string > &) const
bool init_memory_trigger(std::list< std::string > &) const
virtual void update(const Observable *variable)
virtual void set_logger(const std::string &level)
const std::string PREDICTORS
Dispatcher< DejavuPredictor > dispatcher
virtual std::string get_name() const =0
void map(Observable *var, const mbr_func_ptr_t &ptr)
ContextTracker * contextTracker
virtual void learn(const std::vector< std::string > &change)
void set_trigger(const std::string &number)
void addSuggestion(Suggestion)
virtual Prediction predict(const size_t size, const char **filter) const
Generate prediction.
Tracks user interaction and context.
void update_rolling_window(std::list< std::string > &, const std::string &) const
virtual std::string get_value() const =0
std::string getPrefix() const
bool init_rolling_window(std::list< std::string > &, std::ifstream &) const
virtual bool token_satisfies_filter(const std::string &token, const std::string &prefix, const char **filter) const
const Logger< _charT, _Traits > & endl(const Logger< _charT, _Traits > &lgr)
std::string getToken(const int) const