presage  0.8.7
predictor.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 
00025 #ifndef PRESAGE_PREDICTOR
00026 #define PRESAGE_PREDICTOR
00027 
00028 //PLUMP
00029 //#include "plump/src/pluginInterface.h"
00030 
00031 #include "../core/prediction.h"
00032 #include "../core/context_tracker/contextTracker.h"
00033 #include "../core/configuration.h"
00034 #include "../core/utility.h"
00035 
00036 #include <string>
00037 #include <vector>
00038 
00049 class Predictor {
00050 //PLUMP    : public plump::PluginInterface {
00051 public:
00052     Predictor(Configuration*  configuration,
00053               ContextTracker* contextTracker,
00054               const char*     predictorName    = "Predictor",
00055               const char*     shortDescription = "",
00056               const char*     longDescription  = "");
00057     virtual ~Predictor();
00058 
00065     virtual Prediction predict(const size_t size, const char** filter) const = 0;
00066 
00067     virtual void learn(const std::vector<std::string>& change) = 0;
00068 
00069     const std::string getName() const;
00070     const std::string getShortDescription() const;
00071     const std::string getLongDescription() const;
00072 
00073     virtual void set_logger (const std::string& level);
00074 
00075 
00076 protected:
00077     const std::string name;
00078     const std::string shortDescription; // predictor's descriptive name
00079     const std::string longDescription;  // predictor's exhaustive description
00080 
00081     ContextTracker* contextTracker;
00082 
00083     Configuration* configuration;
00084     
00085     Logger<char> logger;
00086 
00087 private:
00088 
00089 };
00090 
00092 // Excerpt taken from C++-dlopen HOWTO
00093 //
00094 // Loading classes is a bit more difficult because we need an instance
00095 // of a class, not just a pointer to a function.
00096 //
00097 // We cannot create the instance of the class using new because the
00098 // class is not defined in the executable, and because (under some
00099 // circumstances) we don't even know its name.
00100 //
00101 // The solution is achieved through polymorphism. We define a base,
00102 // interface class with virtual members in the executable, and a
00103 // derived, implementation class in the module. Generally the
00104 // interface class is abstract (a class is abstract if it has pure
00105 // virtual functions).
00106 //
00107 // As dynamic loading of classes is generally used for plug-ins which
00108 // must expose a clearly defined interface we would have had to define
00109 // an interface and derived implementation classes anyway.
00110 //
00111 // Next, while still in the module, we define two additional helper
00112 // functions, known as class factory functions. One of these functions
00113 // creates an instance of the class and returns a pointer to it. The
00114 // other function takes a pointer to a class created by the factory
00115 // and destroys it. These two functions are qualified as extern "C".
00116 //
00117 // To use the class from the module, load the two factory functions
00118 // using dlsym just as we loaded the the hello function; then, we can
00119 // create and destroy as many instances as we wish.
00120 
00121 // Class factory function types
00122 // typedef Predictor* create_t (HistoryTracker&, Profile*);
00123 // typedef void    destroy_t(Predictor*);
00124 
00125 
00126 #endif // PRESAGE_PREDICTOR