presage
0.8.7
|
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_SELECTOR 00026 #define PRESAGE_SELECTOR 00027 00028 #ifdef HAVE_CONFIG_H 00029 #include "config.h" 00030 #endif 00031 00032 #include "suggestion.h" 00033 #include "prediction.h" 00034 #include "context_tracker/contextTracker.h" 00035 #include "logger.h" 00036 #include "dispatcher.h" 00037 00038 #include <string> 00039 #include <vector> 00040 #include <set> 00041 #include <stdlib.h> // needed for abort() 00042 00043 00044 typedef std::set< std::string, std::less<std::string> > StringSet; 00045 00046 00080 class Selector : public Observer { 00081 public: 00082 Selector(Configuration*, ContextTracker*); 00083 ~Selector(); 00084 00085 std::vector<std::string> select(Prediction); 00086 00087 void update(); 00088 00089 void set_logger(const std::string& value); 00090 void set_suggestions(const std::string& value); 00091 void set_repeat_suggestions(const std::string& value); 00092 void set_greedy_suggestion_threshold(const std::string& value); 00093 00094 size_t get_suggestions () const; 00095 bool get_repeat_suggestions () const; 00096 size_t get_greedy_suggestion_threshold () const; 00097 00098 static const char* LOGGER; 00099 static const char* SUGGESTIONS; 00100 static const char* REPEAT_SUGGESTIONS; 00101 static const char* GREEDY_SUGGESTION_THRESHOLD; 00102 00103 virtual void update (const Observable* variable); 00104 00105 private: 00106 // handle observable notifications 00107 typedef void (Selector::* mbr_func_ptr_t)(const std::string&); 00108 std::map<std::string, mbr_func_ptr_t> dispatch_map; 00109 00110 size_t suggestions; 00111 bool repeat_suggestions; 00112 size_t greedy_suggestion_threshold; 00113 00114 void updateSuggestedWords( const std::vector<std::string>& ); 00115 void clearSuggestedWords(); 00116 00117 void repetitionFilter( std::vector<std::string>& ); 00118 void thresholdFilter( std::vector<std::string>& ); 00119 00120 StringSet suggestedWords; 00121 00122 std::string previous_prefix; 00123 00124 ContextTracker* contextTracker; 00125 Configuration* config; 00126 Logger<char> logger; 00127 00128 Dispatcher<Selector> dispatcher; 00129 }; 00130 00131 00132 #endif // PRESAGE_SELECTOR