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_CONTEXTTRACKER 00026 #define PRESAGE_CONTEXTTRACKER 00027 00028 #ifdef HAVE_CONFIG_H 00029 #include "config.h" 00030 #endif 00031 00032 #include <iostream> 00033 #include <sstream> 00034 #include <string> 00035 #include <vector> 00036 #include <assert.h> 00037 00038 #include "contextChangeDetector.h" 00039 00040 #include "../tokenizer/reverseTokenizer.h" 00041 #include "../charsets.h" 00042 #include "../configuration.h" 00043 #include "../logger.h" 00044 #include "../dispatcher.h" 00045 00046 #include "../../presageCallback.h" 00047 00048 class PredictorRegistry; 00049 00155 class ContextTracker : public Observer { 00156 public: 00157 ContextTracker(Configuration* config, 00158 PredictorRegistry* predictorRegistry, 00159 PresageCallback* callback, 00160 const char[]=DEFAULT_WORD_CHARS, 00161 const char[]=DEFAULT_SEPARATOR_CHARS, 00162 const char[]=DEFAULT_BLANKSPACE_CHARS, 00163 const char[]=DEFAULT_CONTROL_CHARS ); 00164 ~ContextTracker(); 00165 00166 const PresageCallback* callback(const PresageCallback* callback); 00167 00168 bool contextChange(); 00169 00170 std::string getPrefix() const; 00171 std::string getToken (const int) const; 00172 00173 std::string getSlidingWindowToken(const int index) const; 00174 00175 std::string getFutureStream() const; 00176 std::string getPastStream () const; 00177 00178 bool isCompletionValid(const std::string&) const; 00179 00180 //eliminate after testing phase 00181 std::string getWordChars() const; 00182 std::string getSeparatorChars() const; 00183 std::string getBlankspaceChars() const; 00184 std::string getControlChars() const; 00185 00186 std::string toString() const; 00187 00188 void update(); 00189 00190 virtual void update (const Observable* variable); 00191 00192 void set_logger (const std::string& value); 00193 void set_sliding_window_size (const std::string& value); 00194 00195 static const char* LOGGER; 00196 static const char* SLIDING_WINDOW_SIZE; 00197 00198 private: 00199 std::string wordChars; 00200 std::string separatorChars; 00201 std::string blankspaceChars; 00202 std::string controlChars; 00203 00204 // REVISIT: this was removed since a tokenizer is created with 00205 // each method invocation that needs it 00206 //ReverseTokenizer tokenizer; 00207 00208 // utility functions 00209 bool isWordChar (const char) const; 00210 bool isSeparatorChar (const char) const; 00211 bool isControlChar (const char) const; 00212 bool isBlankspaceChar(const char) const; 00213 00214 const PresageCallback* context_tracker_callback; 00215 PredictorRegistry* predictorRegistry; 00216 ContextChangeDetector* contextChangeDetector; 00217 Logger<char> logger; 00218 00219 Dispatcher<ContextTracker> dispatcher; 00220 }; 00221 00222 #endif // PRESAGE_CONTEXTTRACKER