presage  0.8.7
dejavuPredictor.h
Go to the documentation of this file.
00001 
00002 /******************************************************
00003  *  Presage, an extensible predictive text entry system
00004  *  ---------------------------------------------------
00005  *
00006  *  Copyright (C) 2008  Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License along
00019     with this program; if not, write to the Free Software Foundation, Inc.,
00020     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00021                                                                              *
00022                                                                 **********(*)*/
00023 
00024 #ifndef PRESAGE_DEJAVUPREDICTOR
00025 #define PRESAGE_DEJAVUPREDICTOR
00026 
00027 #include "predictor.h"
00028 #include "../core/dispatcher.h"
00029 
00030 #include <list>
00031 #include <string>
00032 #include <fstream>
00033 
00034 
00044 class DejavuPredictor : public Predictor, public Observer {
00045 public:
00046     DejavuPredictor(Configuration*, ContextTracker*);
00047     ~DejavuPredictor();
00048 
00049     virtual Prediction predict(const size_t size, const char** filter) const;
00050 
00051     virtual void learn(const std::vector<std::string>& change);
00052 
00053     virtual void update (const Observable* variable);
00054 
00055 private:
00056     typedef void (DejavuPredictor::* mbr_func_ptr_t) (const std::string& value);
00057     std::map<std::string, mbr_func_ptr_t> dispatch_map;
00058 
00059     bool init_memory_trigger(std::list<std::string>&) const;
00060     bool match(const std::list<std::string>&, const std::list<std::string>&) const;
00061     bool init_rolling_window(std::list<std::string>&, std::ifstream&) const;
00062     void update_rolling_window(std::list<std::string>&, const std::string&) const;
00063 
00064     void set_memory  (const std::string& filename);
00065     void set_trigger (const std::string& number);
00066 
00067     static const char* LOGGER;
00068     static const char* MEMORY;
00069     static const char* TRIGGER;
00070 
00071     std::string memory;
00072     int trigger;
00073 
00074     Dispatcher<DejavuPredictor> dispatcher;
00075 };
00076 
00077 #endif // SOOTH_DEJAVUPREDICTOR