contextTracker.h
Go to the documentation of this file.
/******************************************************
* Presage, an extensible predictive text entry system
* ---------------------------------------------------
*
* Copyright (C) 2008 Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
**********(*)*/
#ifndef PRESAGE_CONTEXTTRACKER
#define PRESAGE_CONTEXTTRACKER
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <assert.h>
#include "contextChangeDetector.h"
#include "../tokenizer/reverseTokenizer.h"
#include "../charsets.h"
#include "../configuration.h"
#include "../logger.h"
#include "../dispatcher.h"
#include "../../presageCallback.h"
class PredictorRegistry;
class ContextTracker : public Observer {
public:
ContextTracker(Configuration* config,
PredictorRegistry* predictorRegistry,
PresageCallback* callback,
const unsigned char[]=DEFAULT_WORD_CHARS,
const char[]=DEFAULT_SEPARATOR_CHARS,
const char[]=DEFAULT_BLANKSPACE_CHARS,
const char[]=DEFAULT_CONTROL_CHARS );
~ContextTracker();
const PresageCallback* callback(const PresageCallback* callback);
bool contextChange();
std::string getPrefix() const;
std::string getToken (const int) const;
std::string getExtraTokenToLearn(const int index,
const std::vector<std::string>& change) const;
std::string getFutureStream() const;
std::string getPastStream () const;
bool isCompletionValid(const std::string&) const;
//eliminate after testing phase
std::string getWordChars() const;
std::string getSeparatorChars() const;
std::string getBlankspaceChars() const;
std::string getControlChars() const;
std::string toString() const;
void update();
void learn(const std::string& text) const;
virtual void update (const Observable* variable);
void set_logger (const std::string& value);
void set_sliding_window_size (const std::string& value);
void set_lowercase_mode (const std::string& value);
void set_online_learning (const std::string& value);
static const char* LOGGER;
static const char* SLIDING_WINDOW_SIZE;
static const char* LOWERCASE_MODE;
static const char* ONLINE_LEARNING;
private:
std::string wordChars;
std::string separatorChars;
std::string blankspaceChars;
std::string controlChars;
bool lowercase_mode;
bool online_learning;
// REVISIT: this was removed since a tokenizer is created with
// each method invocation that needs it
//ReverseTokenizer tokenizer;
// utility functions
bool isWordChar (const char) const;
bool isSeparatorChar (const char) const;
bool isControlChar (const char) const;
bool isBlankspaceChar(const char) const;
const PresageCallback* context_tracker_callback;
PredictorRegistry* predictorRegistry;
ContextChangeDetector* contextChangeDetector;
Logger<char> logger;
Dispatcher<ContextTracker> dispatcher;
};
#endif // PRESAGE_CONTEXTTRACKER
charsets.h
DEFAULT_SEPARATOR_CHARS
const char DEFAULT_SEPARATOR_CHARS[]
Definition charsets.h:176
DEFAULT_CONTROL_CHARS
const char DEFAULT_CONTROL_CHARS[]
Definition charsets.h:219
DEFAULT_BLANKSPACE_CHARS
const char DEFAULT_BLANKSPACE_CHARS[]
Definition charsets.h:210
DEFAULT_WORD_CHARS
const unsigned char DEFAULT_WORD_CHARS[]
Definition charsets.h:45
Configuration
Definition configuration.h:36
ContextChangeDetector
Definition contextChangeDetector.h:36
ContextTracker::online_learning
bool online_learning
Definition contextTracker.h:219
ContextTracker::set_logger
void set_logger(const std::string &value)
Definition contextTracker.cpp:85
ContextTracker::LOWERCASE_MODE
static const char * LOWERCASE_MODE
Definition contextTracker.h:209
ContextTracker::blankspaceChars
std::string blankspaceChars
Definition contextTracker.h:215
ContextTracker::getExtraTokenToLearn
std::string getExtraTokenToLearn(const int index, const std::vector< std::string > &change) const
Definition contextTracker.cpp:231
ContextTracker::isControlChar
bool isControlChar(const char) const
Definition contextTracker.cpp:308
ContextTracker::LOGGER
static const char * LOGGER
Definition contextTracker.h:207
ContextTracker::isSeparatorChar
bool isSeparatorChar(const char) const
Definition contextTracker.cpp:292
ContextTracker::getControlChars
std::string getControlChars() const
Definition contextTracker.cpp:331
ContextTracker::lowercase_mode
bool lowercase_mode
Definition contextTracker.h:218
ContextTracker::~ContextTracker
~ContextTracker()
Definition contextTracker.cpp:80
ContextTracker::getPastStream
std::string getPastStream() const
Definition contextTracker.cpp:265
ContextTracker::logger
Logger< char > logger
Definition contextTracker.h:234
ContextTracker::contextChange
bool contextChange()
Definition contextTracker.cpp:121
ContextTracker::SLIDING_WINDOW_SIZE
static const char * SLIDING_WINDOW_SIZE
Definition contextTracker.h:208
ContextTracker::controlChars
std::string controlChars
Definition contextTracker.h:216
ContextTracker::set_online_learning
void set_online_learning(const std::string &value)
Definition contextTracker.cpp:103
ContextTracker::toString
std::string toString() const
Definition contextTracker.cpp:336
ContextTracker::isCompletionValid
bool isCompletionValid(const std::string &) const
Definition contextTracker.cpp:271
ContextTracker::getWordChars
std::string getWordChars() const
Definition contextTracker.cpp:316
ContextTracker::isWordChar
bool isWordChar(const char) const
Definition contextTracker.cpp:284
ContextTracker::ONLINE_LEARNING
static const char * ONLINE_LEARNING
Definition contextTracker.h:210
ContextTracker::getBlankspaceChars
std::string getBlankspaceChars() const
Definition contextTracker.cpp:326
ContextTracker::callback
const PresageCallback * callback(const PresageCallback *callback)
Definition contextTracker.cpp:109
ContextTracker::separatorChars
std::string separatorChars
Definition contextTracker.h:214
ContextTracker::contextChangeDetector
ContextChangeDetector * contextChangeDetector
Definition contextTracker.h:233
ContextTracker::getSeparatorChars
std::string getSeparatorChars() const
Definition contextTracker.cpp:321
ContextTracker::set_sliding_window_size
void set_sliding_window_size(const std::string &value)
Definition contextTracker.cpp:91
ContextTracker::isBlankspaceChar
bool isBlankspaceChar(const char) const
Definition contextTracker.cpp:300
ContextTracker::getToken
std::string getToken(const int) const
Definition contextTracker.cpp:191
ContextTracker::getPrefix
std::string getPrefix() const
Definition contextTracker.cpp:186
ContextTracker::ContextTracker
ContextTracker(Configuration *config, PredictorRegistry *predictorRegistry, PresageCallback *callback, const unsigned char[]=DEFAULT_WORD_CHARS, const char[]=DEFAULT_SEPARATOR_CHARS, const char[]=DEFAULT_BLANKSPACE_CHARS, const char[]=DEFAULT_CONTROL_CHARS)
Definition contextTracker.cpp:37
ContextTracker::predictorRegistry
PredictorRegistry * predictorRegistry
Definition contextTracker.h:232
ContextTracker::context_tracker_callback
const PresageCallback * context_tracker_callback
Definition contextTracker.h:231
ContextTracker::set_lowercase_mode
void set_lowercase_mode(const std::string &value)
Definition contextTracker.cpp:97
ContextTracker::learn
void learn(const std::string &text) const
Learn from text.
Definition contextTracker.cpp:140
ContextTracker::update
void update()
Definition contextTracker.cpp:126
ContextTracker::dispatcher
Dispatcher< ContextTracker > dispatcher
Definition contextTracker.h:236
ContextTracker::getFutureStream
std::string getFutureStream() const
Definition contextTracker.cpp:260
ContextTracker::wordChars
std::string wordChars
Definition contextTracker.h:213
Dispatcher
Definition dispatcher.h:42
Logger
Definition logger.h:57
Observable
Definition observable.h:37
Observer::Observer
Observer()
Definition observer.h:40
PredictorRegistry
Definition predictorRegistry.h:46
PresageCallback
Definition presageCallback.h:66
configuration.h
contextChangeDetector.h
dispatcher.h
logger.h
presageCallback.h
config
std::string config
Definition presageDemo.cpp:70
reverseTokenizer.h