presage  0.8.8
contextTracker.h
Go to the documentation of this file.
1 
2 /******************************************************
3  * Presage, an extensible predictive text entry system
4  * ---------------------------------------------------
5  *
6  * Copyright (C) 2008 Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License along
19  with this program; if not, write to the Free Software Foundation, Inc.,
20  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  *
22  **********(*)*/
23 
24 
25 #ifndef PRESAGE_CONTEXTTRACKER
26 #define PRESAGE_CONTEXTTRACKER
27 
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31 
32 #include <iostream>
33 #include <sstream>
34 #include <string>
35 #include <vector>
36 #include <assert.h>
37 
38 #include "contextChangeDetector.h"
39 
40 #include "../tokenizer/reverseTokenizer.h"
41 #include "../charsets.h"
42 #include "../configuration.h"
43 #include "../logger.h"
44 #include "../dispatcher.h"
45 
46 #include "../../presageCallback.h"
47 
48 class PredictorRegistry;
49 
155 class ContextTracker : public Observer {
156 public:
160  const char[]=DEFAULT_WORD_CHARS,
161  const char[]=DEFAULT_SEPARATOR_CHARS,
162  const char[]=DEFAULT_BLANKSPACE_CHARS,
163  const char[]=DEFAULT_CONTROL_CHARS );
164  ~ContextTracker();
165 
166  const PresageCallback* callback(const PresageCallback* callback);
167 
168  bool contextChange();
169 
170  std::string getPrefix() const;
171  std::string getToken (const int) const;
172 
173  std::string getExtraTokenToLearn(const int index,
174  const std::vector<std::string>& change) const;
175 
176  std::string getFutureStream() const;
177  std::string getPastStream () const;
178 
179  bool isCompletionValid(const std::string&) const;
180 
181  //eliminate after testing phase
182  std::string getWordChars() const;
183  std::string getSeparatorChars() const;
184  std::string getBlankspaceChars() const;
185  std::string getControlChars() const;
186 
187  std::string toString() const;
188 
189  void update();
190 
191  virtual void update (const Observable* variable);
192 
193  void set_logger (const std::string& value);
194  void set_sliding_window_size (const std::string& value);
195  void set_lowercase_mode (const std::string& value);
196 
197  static const char* LOGGER;
198  static const char* SLIDING_WINDOW_SIZE;
199  static const char* LOWERCASE_MODE;
200 
201 private:
202  std::string wordChars;
203  std::string separatorChars;
204  std::string blankspaceChars;
205  std::string controlChars;
206 
208 
209  // REVISIT: this was removed since a tokenizer is created with
210  // each method invocation that needs it
211  //ReverseTokenizer tokenizer;
212 
213  // utility functions
214  bool isWordChar (const char) const;
215  bool isSeparatorChar (const char) const;
216  bool isControlChar (const char) const;
217  bool isBlankspaceChar(const char) const;
218 
223 
225 };
226 
227 #endif // PRESAGE_CONTEXTTRACKER