presage
0.8.7
|
Tracks user interaction and context. More...
#include <contextTracker.h>
Public Member Functions | |
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) | |
~ContextTracker () | |
const PresageCallback * | callback (const PresageCallback *callback) |
bool | contextChange () |
std::string | getPrefix () const |
std::string | getToken (const int) const |
std::string | getSlidingWindowToken (const int index) const |
std::string | getFutureStream () const |
std::string | getPastStream () const |
bool | isCompletionValid (const std::string &) const |
std::string | getWordChars () const |
std::string | getSeparatorChars () const |
std::string | getBlankspaceChars () const |
std::string | getControlChars () const |
std::string | toString () const |
void | update () |
virtual void | update (const Observable *variable) |
void | set_logger (const std::string &value) |
void | set_sliding_window_size (const std::string &value) |
Static Public Attributes | |
static const char * | LOGGER = "Presage.ContextTracker.LOGGER" |
static const char * | SLIDING_WINDOW_SIZE = "Presage.ContextTracker.SLIDING_WINDOW_SIZE" |
Private Member Functions | |
bool | isWordChar (const char) const |
bool | isSeparatorChar (const char) const |
bool | isControlChar (const char) const |
bool | isBlankspaceChar (const char) const |
Private Attributes | |
std::string | wordChars |
std::string | separatorChars |
std::string | blankspaceChars |
std::string | controlChars |
const PresageCallback * | context_tracker_callback |
PredictorRegistry * | predictorRegistry |
ContextChangeDetector * | contextChangeDetector |
Logger< char > | logger |
Dispatcher< ContextTracker > | dispatcher |
Tracks user interaction and context.
ContextTracker job is to track the history of user input and track context changes.
History is the sequence of characters input by the user. Context is defined by the token the system is attempting to predict. Context changes occur when certain characters are input.
Tracking user input history and context changes can be trickier than one would think. To ease this operation, characters are classified into these categories:
word characters blankspace characters separator characters control characters
Word characters become part of the current prefix. Word characters do not trigger a change in context.
Blankspace and separator characters trigger a context change and mark the end of the current prediction token.
Control characters are non-printable characters such up, down, left, right arrows and function keys.
Use-cases:
Full sentence: Yesterday I went to the market to buy an apple.
History:Yesterday I went to the| wi-2 "went" wi-1 "to" prefix "" postfix ""
: 'SPC' (space) History:Yesterday I went to the| wi-2 "to" wi-1 "the" prefix "" postfix ""
: 'm' History:Yesterday I went to the m| wi-2 "to" wi-1 "the" prefix "m" postfix ""
: 'a' History:Yesterday I went to the ma| wi-2 "to" wi-1 "the" prefix "ma" postfix ""
: 'rket' History:Yesterday I went to the market| wi-2 "to" wi-1 "the" prefix "market" postfix ""
: 'SPC' History:Yesterday I went to the market | wi-2 "the" wi-1 "market" prefix "" postfix ""
: 't' History:Yesterday I went to the market t| wi-2 "the" wi-1 "market" prefix "t" postfix ""
: 'LEFT_ARROW' History:Yesterday I went to the market |t wi-2 "the" wi-1 "market" prefix "" postfix ""
: 'LEFT_ARROW' History:Yesterday I went to the market| t wi-2 "to" wi-1 "the" prefix "market" postfix ""
: 's' History:Yesterday I went to the markets| t wi-2 "to" wi-1 "the" prefix "markets" postfix ""
Definition at line 155 of file contextTracker.h.
ContextTracker::ContextTracker | ( | Configuration * | config, |
PredictorRegistry * | predictorRegistry, | ||
PresageCallback * | callback, | ||
const char | wChars[] = DEFAULT_WORD_CHARS , |
||
const char | tChars[] = DEFAULT_SEPARATOR_CHARS , |
||
const char | bChars[] = DEFAULT_BLANKSPACE_CHARS , |
||
const char | cChars[] = DEFAULT_CONTROL_CHARS |
||
) |
Definition at line 35 of file contextTracker.cpp.
References blankspaceChars, callback(), context_tracker_callback, contextChangeDetector, controlChars, dispatcher, Configuration::find(), LOGGER, Dispatcher< class_t >::map(), predictorRegistry, PRESAGE_INVALID_CALLBACK_ERROR, separatorChars, set_logger(), set_sliding_window_size(), PredictorRegistry::setContextTracker(), SLIDING_WINDOW_SIZE, and wordChars.
Definition at line 75 of file contextTracker.cpp.
References contextChangeDetector.
const PresageCallback * ContextTracker::callback | ( | const PresageCallback * | callback | ) |
Definition at line 92 of file contextTracker.cpp.
References context_tracker_callback.
Referenced by ContextTracker().
bool ContextTracker::contextChange | ( | ) |
Returns true if a context change occured.
Definition at line 104 of file contextTracker.cpp.
References ContextChangeDetector::context_change(), contextChangeDetector, and getPastStream().
Referenced by Presage::context_change(), Selector::select(), and Selector::update().
std::string ContextTracker::getBlankspaceChars | ( | ) | const |
Definition at line 299 of file contextTracker.cpp.
References blankspaceChars.
std::string ContextTracker::getControlChars | ( | ) | const |
Definition at line 304 of file contextTracker.cpp.
References controlChars.
std::string ContextTracker::getFutureStream | ( | ) | const |
Definition at line 233 of file contextTracker.cpp.
References context_tracker_callback, and PresageCallback::get_future_stream().
std::string ContextTracker::getPastStream | ( | ) | const |
Definition at line 238 of file contextTracker.cpp.
References context_tracker_callback, and PresageCallback::get_past_stream().
Referenced by Presage::context(), contextChange(), and update().
std::string ContextTracker::getPrefix | ( | ) | const |
Definition at line 172 of file contextTracker.cpp.
References getToken().
Referenced by isCompletionValid(), DictionaryPredictor::predict(), AbbreviationExpansionPredictor::predict(), RecencyPredictor::predict(), Presage::prefix(), Selector::Selector(), and Selector::thresholdFilter().
std::string ContextTracker::getSeparatorChars | ( | ) | const |
Definition at line 294 of file contextTracker.cpp.
References separatorChars.
std::string ContextTracker::getSlidingWindowToken | ( | const int | index | ) | const |
Definition at line 215 of file contextTracker.cpp.
References blankspaceChars, contextChangeDetector, ContextChangeDetector::get_sliding_window(), and separatorChars.
Referenced by SmoothedNgramPredictor::learn().
std::string ContextTracker::getToken | ( | const int | index | ) | const |
Definition at line 177 of file contextTracker.cpp.
References blankspaceChars, context_tracker_callback, PresageCallback::get_past_stream(), and separatorChars.
Referenced by getPrefix(), DejavuPredictor::init_memory_trigger(), PredictorActivator::parse_internal_commands(), SmoothedNgramPredictor::predict(), RecencyPredictor::predict(), and ARPAPredictor::predict().
std::string ContextTracker::getWordChars | ( | ) | const |
Definition at line 289 of file contextTracker.cpp.
References wordChars.
bool ContextTracker::isBlankspaceChar | ( | const char | c | ) | const [private] |
Definition at line 273 of file contextTracker.cpp.
References blankspaceChars.
bool ContextTracker::isCompletionValid | ( | const std::string & | completion | ) | const |
Definition at line 244 of file contextTracker.cpp.
References getPrefix(), and Utility::strtolower().
bool ContextTracker::isControlChar | ( | const char | c | ) | const [private] |
Definition at line 281 of file contextTracker.cpp.
References controlChars.
bool ContextTracker::isSeparatorChar | ( | const char | c | ) | const [private] |
Definition at line 265 of file contextTracker.cpp.
References separatorChars.
bool ContextTracker::isWordChar | ( | const char | c | ) | const [private] |
Definition at line 257 of file contextTracker.cpp.
References wordChars.
void ContextTracker::set_logger | ( | const std::string & | value | ) |
Definition at line 80 of file contextTracker.cpp.
References endl(), logger, and setlevel().
Referenced by ContextTracker().
void ContextTracker::set_sliding_window_size | ( | const std::string & | value | ) |
Definition at line 86 of file contextTracker.cpp.
References contextChangeDetector, endl(), logger, and ContextChangeDetector::set_sliding_window_size().
Referenced by ContextTracker().
std::string ContextTracker::toString | ( | ) | const |
Definition at line 309 of file contextTracker.cpp.
References context_tracker_callback, PresageCallback::get_future_stream(), and PresageCallback::get_past_stream().
void ContextTracker::update | ( | ) |
Definition at line 109 of file contextTracker.cpp.
References blankspaceChars, ContextChangeDetector::change(), contextChangeDetector, endl(), ContextChangeDetector::get_sliding_window(), getPastStream(), ForwardTokenizer::hasMoreTokens(), PredictorRegistry::Iterator::hasNext(), PredictorRegistry::iterator(), Predictor::learn(), logger, PredictorRegistry::Iterator::next(), ReverseTokenizer::nextToken(), ForwardTokenizer::nextToken(), predictorRegistry, separatorChars, and ContextChangeDetector::update_sliding_window().
Referenced by Presage::predict().
void ContextTracker::update | ( | const Observable * | variable | ) | [virtual] |
Implements Observer.
Definition at line 314 of file contextTracker.cpp.
References Dispatcher< class_t >::dispatch(), dispatcher, endl(), Observable::get_name(), Observable::get_value(), and logger.
std::string ContextTracker::blankspaceChars [private] |
Definition at line 201 of file contextTracker.h.
Referenced by ContextTracker(), getBlankspaceChars(), getSlidingWindowToken(), getToken(), isBlankspaceChar(), and update().
const PresageCallback* ContextTracker::context_tracker_callback [private] |
Definition at line 214 of file contextTracker.h.
Referenced by callback(), ContextTracker(), getFutureStream(), getPastStream(), getToken(), and toString().
Definition at line 216 of file contextTracker.h.
Referenced by contextChange(), ContextTracker(), getSlidingWindowToken(), set_sliding_window_size(), update(), and ~ContextTracker().
std::string ContextTracker::controlChars [private] |
Definition at line 202 of file contextTracker.h.
Referenced by ContextTracker(), getControlChars(), and isControlChar().
Dispatcher<ContextTracker> ContextTracker::dispatcher [private] |
Definition at line 219 of file contextTracker.h.
Referenced by ContextTracker(), and update().
const char * ContextTracker::LOGGER = "Presage.ContextTracker.LOGGER" [static] |
Definition at line 195 of file contextTracker.h.
Referenced by ContextTracker().
Logger<char> ContextTracker::logger [private] |
Definition at line 217 of file contextTracker.h.
Referenced by set_logger(), set_sliding_window_size(), and update().
Definition at line 215 of file contextTracker.h.
Referenced by ContextTracker(), and update().
std::string ContextTracker::separatorChars [private] |
Definition at line 200 of file contextTracker.h.
Referenced by ContextTracker(), getSeparatorChars(), getSlidingWindowToken(), getToken(), isSeparatorChar(), and update().
const char * ContextTracker::SLIDING_WINDOW_SIZE = "Presage.ContextTracker.SLIDING_WINDOW_SIZE" [static] |
Definition at line 196 of file contextTracker.h.
Referenced by ContextTracker().
std::string ContextTracker::wordChars [private] |
Definition at line 199 of file contextTracker.h.
Referenced by ContextTracker(), getWordChars(), and isWordChar().