presage  0.9.2~beta
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 
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 
198  void learn(const std::string& text) const;
199 
200  virtual void update (const Observable* variable);
201 
202  void set_logger (const std::string& value);
203  void set_sliding_window_size (const std::string& value);
204  void set_lowercase_mode (const std::string& value);
205  void set_online_learning (const std::string& value);
206 
207  static const char* LOGGER;
208  static const char* SLIDING_WINDOW_SIZE;
209  static const char* LOWERCASE_MODE;
210  static const char* ONLINE_LEARNING;
211 
212 private:
213  std::string wordChars;
214  std::string separatorChars;
215  std::string blankspaceChars;
216  std::string controlChars;
217 
220 
221  // REVISIT: this was removed since a tokenizer is created with
222  // each method invocation that needs it
223  //ReverseTokenizer tokenizer;
224 
225  // utility functions
226  bool isWordChar (const char) const;
227  bool isSeparatorChar (const char) const;
228  bool isControlChar (const char) const;
229  bool isBlankspaceChar(const char) const;
230 
235 
237 };
238 
239 #endif // PRESAGE_CONTEXTTRACKER
const PresageCallback * context_tracker_callback
std::string blankspaceChars
static const char * LOGGER
ContextChangeDetector * contextChangeDetector
void learn(const std::string &text) const
Learn from text.
void set_online_learning(const std::string &value)
const char DEFAULT_BLANKSPACE_CHARS[]
Definition: charsets.h:211
PredictorRegistry * predictorRegistry
bool isBlankspaceChar(const char) const
static const char * ONLINE_LEARNING
std::string toString() const
std::string getControlChars() const
std::string getBlankspaceChars() const
std::string getPastStream() const
void set_lowercase_mode(const std::string &value)
const PresageCallback * callback(const PresageCallback *callback)
std::string controlChars
bool isControlChar(const char) const
bool isCompletionValid(const std::string &) const
std::string getSeparatorChars() const
void set_sliding_window_size(const std::string &value)
const char DEFAULT_WORD_CHARS[]
Definition: charsets.h:45
std::string config
Definition: presageDemo.cpp:70
std::string getFutureStream() const
std::string wordChars
ContextTracker(Configuration *config, PredictorRegistry *predictorRegistry, PresageCallback *callback, const char[]=DEFAULT_WORD_CHARS, const char[]=DEFAULT_SEPARATOR_CHARS, const char[]=DEFAULT_BLANKSPACE_CHARS, const char[]=DEFAULT_CONTROL_CHARS)
std::string getExtraTokenToLearn(const int index, const std::vector< std::string > &change) const
static const char * SLIDING_WINDOW_SIZE
static const char * LOWERCASE_MODE
Dispatcher< ContextTracker > dispatcher
bool isWordChar(const char) const
const char DEFAULT_CONTROL_CHARS[]
Definition: charsets.h:220
void set_logger(const std::string &value)
Tracks user interaction and context.
std::string separatorChars
std::string getPrefix() const
bool isSeparatorChar(const char) const
Logger< char > logger
std::string getWordChars() const
std::string getToken(const int) const
const char DEFAULT_SEPARATOR_CHARS[]
Definition: charsets.h:176