ContextTracker Class Reference

Tracks user interaction and context. More...

`#include <contextTracker.h>`

Inheritance diagram for ContextTracker:
Collaboration diagram for ContextTracker:

## Public Member Functions

| 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
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
| Learn from text. More...
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)
Public Member Functions inherited from Observer
virtual | ~Observer ()

## Static Public Attributes

static const char * | LOGGER = "Presage.ContextTracker.LOGGER"
static const char * | SLIDING_WINDOW_SIZE = "Presage.ContextTracker.SLIDING_WINDOW_SIZE"
static const char * | LOWERCASE_MODE = "Presage.ContextTracker.LOWERCASE_MODE"
static const char * | ONLINE_LEARNING = "Presage.ContextTracker.ONLINE_LEARNING"

## 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
bool | lowercase_mode
bool | online_learning
const PresageCallback * | context_tracker_callback
PredictorRegistry * | predictorRegistry
ContextChangeDetector * | contextChangeDetector
Logger< char > | logger
Dispatcher< ContextTracker > | dispatcher

## Additional Inherited Members

Protected Member Functions inherited from Observer
| Observer ()

## Detailed Description

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 154 of file contextTracker.h.

## Constructor & Destructor Documentation

## ContextTracker()

ContextTracker::ContextTracker | ( | Configuration * | config,
|  | PredictorRegistry * | predictorRegistry,
|  | PresageCallback * | callback,
|  | const unsigned 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 37 of file contextTracker.cpp.

References blankspaceChars, callback(), config, context_tracker_callback, contextChangeDetector, controlChars, dispatcher, LOGGER, LOWERCASE_MODE, lowercase_mode, Dispatcher< class_t >::map(), ONLINE_LEARNING, predictorRegistry, PRESAGE_INVALID_CALLBACK_ERROR, separatorChars, set_logger(), set_lowercase_mode(), set_online_learning(), set_sliding_window_size(), PredictorRegistry::setContextTracker(), SLIDING_WINDOW_SIZE, and wordChars.

Here is the call graph for this function:

## ~ContextTracker()

ContextTracker::~ContextTracker | ( |  | ) |

Definition at line 80 of file contextTracker.cpp.

References contextChangeDetector.

## Member Function Documentation

## callback()

const PresageCallback * ContextTracker::callback | ( | const PresageCallback * | callback | ) |

Definition at line 109 of file contextTracker.cpp.

References context_tracker_callback.

Referenced by ContextTracker().

Here is the caller graph for this function:

## contextChange()

bool ContextTracker::contextChange | ( |  | ) |

Returns true if a context change occured.

Definition at line 121 of file contextTracker.cpp.

References ContextChangeDetector::context_change(), contextChangeDetector, and getPastStream().

Referenced by Presage::context_change(), Selector::select(), and Selector::update().

Here is the call graph for this function:
Here is the caller graph for this function:

## getBlankspaceChars()

std::string ContextTracker::getBlankspaceChars | ( |  | ) | const

Definition at line 326 of file contextTracker.cpp.

References blankspaceChars.

## getControlChars()

std::string ContextTracker::getControlChars | ( |  | ) | const

Definition at line 331 of file contextTracker.cpp.

References controlChars.

## getExtraTokenToLearn()

std::string ContextTracker::getExtraTokenToLearn | ( | const int | index,
|  | const std::vector< std::string > & | change
| ) |  | const

Definition at line 231 of file contextTracker.cpp.

References getToken().

Referenced by SmoothedNgramPredictor::learn().

Here is the call graph for this function:
Here is the caller graph for this function:

## getFutureStream()

std::string ContextTracker::getFutureStream | ( |  | ) | const

Definition at line 260 of file contextTracker.cpp.

References context_tracker_callback, and PresageCallback::get_future_stream().

Here is the call graph for this function:

## getPastStream()

std::string ContextTracker::getPastStream | ( |  | ) | const

Definition at line 265 of file contextTracker.cpp.

References context_tracker_callback, and PresageCallback::get_past_stream().

Referenced by Presage::context(), contextChange(), and update().

Here is the call graph for this function:
Here is the caller graph for this function:

## getPrefix()

std::string ContextTracker::getPrefix | ( |  | ) | const

Definition at line 186 of file contextTracker.cpp.

References getToken().

Referenced by isCompletionValid(), DictionaryPredictor::predict(), DejavuPredictor::predict(), AbbreviationExpansionPredictor::predict(), RecencyPredictor::predict(), Presage::prefix(), Selector::Selector(), and Selector::thresholdFilter().

Here is the call graph for this function:
Here is the caller graph for this function:

## getSeparatorChars()

std::string ContextTracker::getSeparatorChars | ( |  | ) | const

Definition at line 321 of file contextTracker.cpp.

References separatorChars.

## getToken()

std::string ContextTracker::getToken | ( | const int | index | ) | const

Definition at line 191 of file contextTracker.cpp.

References blankspaceChars, context_tracker_callback, PresageCallback::get_past_stream(), lowercase_mode, and separatorChars.

Referenced by getExtraTokenToLearn(), getPrefix(), DejavuPredictor::init_memory_trigger(), SmoothedNgramPredictor::learn(), PredictorActivator::parse_internal_commands(), SmoothedNgramPredictor::predict(), RecencyPredictor::predict(), and ARPAPredictor::predict().

Here is the call graph for this function:
Here is the caller graph for this function:

## getWordChars()

std::string ContextTracker::getWordChars | ( |  | ) | const

Definition at line 316 of file contextTracker.cpp.

References wordChars.

## isBlankspaceChar()

bool ContextTracker::isBlankspaceChar | ( | const char | c | ) | const

private

Definition at line 300 of file contextTracker.cpp.

References blankspaceChars.

## isCompletionValid()

bool ContextTracker::isCompletionValid | ( | const std::string & | completion | ) | const

Definition at line 271 of file contextTracker.cpp.

References getPrefix(), and Utility::strtolower().

Here is the call graph for this function:

## isControlChar()

bool ContextTracker::isControlChar | ( | const char | c | ) | const

private

Definition at line 308 of file contextTracker.cpp.

References controlChars.

## isSeparatorChar()

bool ContextTracker::isSeparatorChar | ( | const char | c | ) | const

private

Definition at line 292 of file contextTracker.cpp.

References separatorChars.

## isWordChar()

bool ContextTracker::isWordChar | ( | const char | c | ) | const

private

Definition at line 284 of file contextTracker.cpp.

References wordChars.

## learn()

void ContextTracker::learn | ( | const std::string & | text | ) | const

Learn from text.

Train the predictors on

Parameters

  text. | Each active predictor will apply their machine learning algorithm to learn from the
  text. |

Definition at line 140 of file contextTracker.cpp.

References blankspaceChars, endl(), ForwardTokenizer::hasMoreTokens(), PredictorRegistry::Iterator::hasNext(), PredictorRegistry::iterator(), Predictor::learn(), logger, lowercase_mode, Tokenizer::lowercaseMode(), PredictorRegistry::Iterator::next(), ForwardTokenizer::nextToken(), predictorRegistry, and separatorChars.

Referenced by update().

Here is the call graph for this function:
Here is the caller graph for this function:

## set_logger()

void ContextTracker::set_logger | ( | const std::string & | value | ) |

Definition at line 85 of file contextTracker.cpp.

References endl(), logger, and setlevel().

Referenced by ContextTracker().

Here is the call graph for this function:
Here is the caller graph for this function:

## set_lowercase_mode()

void ContextTracker::set_lowercase_mode | ( | const std::string & | value | ) |

Definition at line 97 of file contextTracker.cpp.

References endl(), Utility::isYes(), logger, and lowercase_mode.

Referenced by ContextTracker().

Here is the call graph for this function:
Here is the caller graph for this function:

## set_online_learning()

void ContextTracker::set_online_learning | ( | const std::string & | value | ) |

Definition at line 103 of file contextTracker.cpp.

References endl(), Utility::isYes(), logger, and online_learning.

Referenced by ContextTracker().

Here is the call graph for this function:
Here is the caller graph for this function:

## set_sliding_window_size()

void ContextTracker::set_sliding_window_size | ( | const std::string & | value | ) |

Definition at line 91 of file contextTracker.cpp.

References contextChangeDetector, endl(), logger, and ContextChangeDetector::set_sliding_window_size().

Referenced by ContextTracker().

Here is the call graph for this function:
Here is the caller graph for this function:

## toString()

std::string ContextTracker::toString | ( |  | ) | const

Definition at line 336 of file contextTracker.cpp.

References context_tracker_callback, PresageCallback::get_future_stream(), and PresageCallback::get_past_stream().

Here is the call graph for this function:

## update() [1/2]

void ContextTracker::update | ( |  | ) |

Definition at line 126 of file contextTracker.cpp.

References ContextChangeDetector::change(), contextChangeDetector, getPastStream(), learn(), online_learning, and ContextChangeDetector::update_sliding_window().

Referenced by Presage::predict().

Here is the call graph for this function:
Here is the caller graph for this function:

## update() [2/2]

void ContextTracker::update | ( | const Observable * | variable | ) |

virtual

Implements Observer.

Definition at line 341 of file contextTracker.cpp.

References Dispatcher< class_t >::dispatch(), dispatcher, endl(), Observable::get_name(), Observable::get_value(), and logger.

Here is the call graph for this function:

## Member Data Documentation

## blankspaceChars

std::string ContextTracker::blankspaceChars

private

Definition at line 214 of file contextTracker.h.

Referenced by ContextTracker(), getBlankspaceChars(), getToken(), isBlankspaceChar(), and learn().

## context_tracker_callback

const PresageCallback* ContextTracker::context_tracker_callback

private

Definition at line 230 of file contextTracker.h.

Referenced by callback(), ContextTracker(), getFutureStream(), getPastStream(), getToken(), and toString().

## contextChangeDetector

ContextChangeDetector* ContextTracker::contextChangeDetector

private

Definition at line 232 of file contextTracker.h.

Referenced by contextChange(), ContextTracker(), set_sliding_window_size(), update(), and ~ContextTracker().

## controlChars

std::string ContextTracker::controlChars

private

Definition at line 215 of file contextTracker.h.

Referenced by ContextTracker(), getControlChars(), and isControlChar().

## dispatcher

Dispatcher<ContextTracker> ContextTracker::dispatcher

private

Definition at line 235 of file contextTracker.h.

Referenced by ContextTracker(), and update().

## LOGGER

const char * ContextTracker::LOGGER = "Presage.ContextTracker.LOGGER"

static

Definition at line 206 of file contextTracker.h.

Referenced by ContextTracker().

## logger

Logger<char> ContextTracker::logger

private

Definition at line 233 of file contextTracker.h.

Referenced by learn(), set_logger(), set_lowercase_mode(), set_online_learning(), set_sliding_window_size(), and update().

## LOWERCASE_MODE

const char * ContextTracker::LOWERCASE_MODE = "Presage.ContextTracker.LOWERCASE_MODE"

static

Definition at line 208 of file contextTracker.h.

Referenced by ContextTracker().

## lowercase_mode

bool ContextTracker::lowercase_mode

private

Definition at line 217 of file contextTracker.h.

Referenced by ContextTracker(), getToken(), learn(), and set_lowercase_mode().

## ONLINE_LEARNING

const char * ContextTracker::ONLINE_LEARNING = "Presage.ContextTracker.ONLINE_LEARNING"

static

Definition at line 209 of file contextTracker.h.

Referenced by ContextTracker().

## online_learning

bool ContextTracker::online_learning

private

Definition at line 218 of file contextTracker.h.

Referenced by set_online_learning(), and update().

## predictorRegistry

PredictorRegistry* ContextTracker::predictorRegistry

private

Definition at line 231 of file contextTracker.h.

Referenced by ContextTracker(), and learn().

## separatorChars

std::string ContextTracker::separatorChars

private

Definition at line 213 of file contextTracker.h.

Referenced by ContextTracker(), getSeparatorChars(), getToken(), isSeparatorChar(), and learn().

## SLIDING_WINDOW_SIZE

const char * ContextTracker::SLIDING_WINDOW_SIZE = "Presage.ContextTracker.SLIDING_WINDOW_SIZE"

static

Definition at line 207 of file contextTracker.h.

Referenced by ContextTracker().

## wordChars

std::string ContextTracker::wordChars

private

Definition at line 212 of file contextTracker.h.

Referenced by ContextTracker(), getWordChars(), and isWordChar().

The documentation for this class was generated from the following files:

- /build/presage-hvZ4Ld/presage-0.9.1/src/lib/core/context_tracker/contextTracker.h
- /build/presage-hvZ4Ld/presage-0.9.1/src/lib/core/context_tracker/contextTracker.cpp