presage  0.8.7
predictorActivator.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_PREDICTORACTIVATOR
00026 #define PRESAGE_PREDICTORACTIVATOR
00027 
00028 #ifdef HAVE_CONFIG_H
00029 # include "config.h"
00030 #endif
00031 
00032 // PLUMP
00033 // REVISIT uncomment this when reenabling plump
00034 //#include "plump/src/plump.h"
00035 //namespace plump { typedef int Plump; }
00036 
00037 #include "configuration.h"
00038 #include "predictorRegistry.h"
00039 #include "context_tracker/contextTracker.h"
00040 #include "prediction.h"
00041 #include "logger.h"
00042 #include "dispatcher.h"
00043 
00044 #include "combiner.h"
00045 #include "meritocracyCombiner.h"
00046 
00047 #include "predictors/predictor.h"
00048 
00049 
00050 #ifdef STDC_HEADERS
00051 # include <stdlib.h>  // needed for abort function
00052 #endif
00053 
00054 //#include <dlfcn.h>   // needed for shared library dynamic loading
00055 
00056 
00069 class PredictorActivator : public Observer {
00070 public:
00071 //PLUMP    PredictorActivator(HistoryTracker&,
00072 //PLUMP              plump::Plump&);
00073 
00084     PredictorActivator(Configuration* config, PredictorRegistry* registry, ContextTracker* contextTracker);
00085 
00089     ~PredictorActivator();
00090 
00099     Prediction predict(unsigned int multiplier, const char** filter);
00100 
00105     void setPredictors(const std::string& predictorList);
00106 
00111     void addPredictor(const std::string& predictorName);
00112 
00116     void removePredictors();
00117 
00125     int getPredictTime() const;
00126     
00132     void setPredictTime(const std::string& predictTime);
00133 
00142     std::string getCombinationPolicy() const;
00143 
00155     void setCombinationPolicy(const std::string& policy);
00156 
00161     void setMaxPartialPredictionSize (const std::string& size);
00162 
00167     void setLogger (const std::string& level);
00168 
00169     void parse_internal_commands (Prediction& pred);
00170 
00171     virtual void update (const Observable* variable);
00172 
00173     static const char* LOGGER;
00174     static const char* PREDICT_TIME;
00175     static const char* MAX_PARTIAL_PREDICTION_SIZE;
00176     static const char* COMBINATION_POLICY;
00177 
00178 private:
00179     // PLUMP
00180     //plump::Plump& plump;
00181 
00182 
00183     // execute predictor function (invoked in thread)
00184     void *execute(void *);
00185 
00186 
00187     Configuration*  config;
00188     PredictorRegistry* predictorRegistry;
00189     ContextTracker* contextTracker;
00190 
00191     Logger<char>    logger;
00192 
00193     Combiner*       combiner;
00194     std::string     combinationPolicy;
00195 
00196     int max_partial_prediction_size;
00197 
00198     std::vector<Prediction> predictions; // predictions computed by each predictor are returned here
00199 
00200     int predict_time;
00201 
00202     Dispatcher<PredictorActivator> dispatcher;
00203 };
00204 
00205 #endif // PRESAGE_PREDICTORACTIVATOR