presage
0.8.7
|
#include <selector.h>
Public Member Functions | |
Selector (Configuration *, ContextTracker *) | |
~Selector () | |
std::vector< std::string > | select (Prediction) |
void | update () |
void | set_logger (const std::string &value) |
void | set_suggestions (const std::string &value) |
void | set_repeat_suggestions (const std::string &value) |
void | set_greedy_suggestion_threshold (const std::string &value) |
size_t | get_suggestions () const |
bool | get_repeat_suggestions () const |
size_t | get_greedy_suggestion_threshold () const |
virtual void | update (const Observable *variable) |
Static Public Attributes | |
static const char * | LOGGER = "Presage.Selector.LOGGER" |
static const char * | SUGGESTIONS = "Presage.Selector.SUGGESTIONS" |
static const char * | REPEAT_SUGGESTIONS = "Presage.Selector.REPEAT_SUGGESTIONS" |
static const char * | GREEDY_SUGGESTION_THRESHOLD = "Presage.Selector.GREEDY_SUGGESTION_THRESHOLD" |
Private Types | |
typedef void(Selector::* | mbr_func_ptr_t )(const std::string &) |
Private Member Functions | |
void | updateSuggestedWords (const std::vector< std::string > &) |
void | clearSuggestedWords () |
void | repetitionFilter (std::vector< std::string > &) |
void | thresholdFilter (std::vector< std::string > &) |
Private Attributes | |
std::map< std::string, mbr_func_ptr_t > | dispatch_map |
size_t | suggestions |
bool | repeat_suggestions |
size_t | greedy_suggestion_threshold |
StringSet | suggestedWords |
std::string | previous_prefix |
ContextTracker * | contextTracker |
Configuration * | config |
Logger< char > | logger |
Dispatcher< Selector > | dispatcher |
Selector selects which suggestions supplied by Predictor should be given to the user.
Suggestions selection is performed based on users preferences. Preferences are read from configuration and provided by Configuration.
Selected suggestions are returned to the outside world.
Customisable settings:
SUGGESTIONS: integer, number of suggestions to be selected
REPEAT_SUGGESTIONS: boolean, controls whether a predicted token should be suggested to the user once or multiple times, if its prediction occurs within the same predictive context. A predictive context corresponds to the set of suggestions computed when predicting the same word (token). Some users may fail to see the desired suggestion and might benefit from the fact that the same token will be suggested again if it ranks high in the prediction. If this option is enabled, Selector remembers which tokens have been suggested in the current token and filters out suggestions that have already been selected.
GREEDY_SUGGESTION_THRESHOLD: integer, only tokens whose completion is longer than the specified number of characters are selected. The rationale behind this option is that a user might prefer to be offered a longer word before a shorter word, because typing a longer word is more time-consuming.
For example, given a threshold=2 and prefix="automa", token "automatically" would be suggested, while "automatic" would not.
Definition at line 80 of file selector.h.
typedef void(Selector::* Selector::mbr_func_ptr_t)(const std::string &) [private] |
Definition at line 107 of file selector.h.
Selector::Selector | ( | Configuration * | configuration, |
ContextTracker * | ct | ||
) |
Definition at line 34 of file selector.cpp.
References config, contextTracker, dispatcher, Configuration::find(), ContextTracker::getPrefix(), GREEDY_SUGGESTION_THRESHOLD, LOGGER, Dispatcher< class_t >::map(), previous_prefix, REPEAT_SUGGESTIONS, set_greedy_suggestion_threshold(), set_logger(), set_repeat_suggestions(), set_suggestions(), and SUGGESTIONS.
Definition at line 50 of file selector.cpp.
void Selector::clearSuggestedWords | ( | ) | [private] |
Clear the set of previously selected suggestions.
Definition at line 148 of file selector.cpp.
References endl(), logger, and suggestedWords.
Referenced by select(), and update().
size_t Selector::get_greedy_suggestion_threshold | ( | ) | const |
Definition at line 273 of file selector.cpp.
References greedy_suggestion_threshold.
bool Selector::get_repeat_suggestions | ( | ) | const |
Definition at line 268 of file selector.cpp.
References repeat_suggestions.
size_t Selector::get_suggestions | ( | ) | const |
Definition at line 263 of file selector.cpp.
References suggestions.
Referenced by Presage::predict().
void Selector::repetitionFilter | ( | std::vector< std::string > & | v | ) | [private] |
Filters out suggestions that have previously been selected in the current context.
This filter removes the suggestions that have previously been selected. The set of suggestions that were previously selected is stored in suggestedWords. This filters removes the words that are contained in both
v | and suggestedWords. |
Definition at line 162 of file selector.cpp.
References endl(), logger, and suggestedWords.
Referenced by select().
std::vector< std::string > Selector::select | ( | Prediction | p | ) |
Definition at line 55 of file selector.cpp.
References clearSuggestedWords(), ContextTracker::contextChange(), contextTracker, endl(), Prediction::getSuggestion(), Suggestion::getWord(), greedy_suggestion_threshold, logger, repeat_suggestions, repetitionFilter(), Prediction::size(), suggestions, thresholdFilter(), and updateSuggestedWords().
Referenced by Presage::predict().
void Selector::set_greedy_suggestion_threshold | ( | const std::string & | value | ) |
Set SUGGESTION_THRESHOLD option.
Definition at line 250 of file selector.cpp.
References endl(), greedy_suggestion_threshold, logger, and Utility::toInt().
Referenced by Selector().
void Selector::set_logger | ( | const std::string & | value | ) |
Set LOGGER option.
Definition at line 211 of file selector.cpp.
References endl(), logger, and setlevel().
Referenced by Selector().
void Selector::set_repeat_suggestions | ( | const std::string & | value | ) |
Set REPEAT_SUGGESTION option.
Definition at line 238 of file selector.cpp.
References endl(), Utility::isYes(), logger, and repeat_suggestions.
Referenced by Selector().
void Selector::set_suggestions | ( | const std::string & | value | ) |
Set SUGGESTIONS option.
Definition at line 221 of file selector.cpp.
References endl(), logger, suggestions, and Utility::toInt().
Referenced by Selector().
void Selector::thresholdFilter | ( | std::vector< std::string > & | v | ) | [private] |
Filters out suggestions that could save fewer than THRESHOLD keystrokes.
Assuming prefix.size() == n, suggestion.size() == m, and THRESHOLD == t, then this filter removes those suggestions for which the following condition is true: (m - n) < t
Definition at line 187 of file selector.cpp.
References contextTracker, endl(), ContextTracker::getPrefix(), greedy_suggestion_threshold, and logger.
Referenced by select().
void Selector::update | ( | ) |
Trigger update of the suggested tokens cache
Definition at line 114 of file selector.cpp.
References clearSuggestedWords(), ContextTracker::contextChange(), and contextTracker.
void Selector::update | ( | const Observable * | variable | ) | [virtual] |
Implements Observer.
Definition at line 278 of file selector.cpp.
References Dispatcher< class_t >::dispatch(), dispatcher, endl(), Observable::get_name(), and logger.
void Selector::updateSuggestedWords | ( | const std::vector< std::string > & | v | ) | [private] |
Adds suggestions to the set of previously selected suggestions.
Definition at line 126 of file selector.cpp.
References endl(), logger, and suggestedWords.
Referenced by select().
Configuration* Selector::config [private] |
Definition at line 125 of file selector.h.
Referenced by Selector().
ContextTracker* Selector::contextTracker [private] |
Definition at line 124 of file selector.h.
Referenced by select(), Selector(), thresholdFilter(), and update().
std::map<std::string, mbr_func_ptr_t> Selector::dispatch_map [private] |
Definition at line 108 of file selector.h.
Dispatcher<Selector> Selector::dispatcher [private] |
Definition at line 128 of file selector.h.
Referenced by Selector(), and update().
const char * Selector::GREEDY_SUGGESTION_THRESHOLD = "Presage.Selector.GREEDY_SUGGESTION_THRESHOLD" [static] |
Definition at line 101 of file selector.h.
Referenced by Selector().
size_t Selector::greedy_suggestion_threshold [private] |
Definition at line 112 of file selector.h.
Referenced by get_greedy_suggestion_threshold(), select(), set_greedy_suggestion_threshold(), and thresholdFilter().
const char * Selector::LOGGER = "Presage.Selector.LOGGER" [static] |
Definition at line 98 of file selector.h.
Referenced by Selector().
Logger<char> Selector::logger [private] |
Definition at line 126 of file selector.h.
Referenced by clearSuggestedWords(), repetitionFilter(), select(), set_greedy_suggestion_threshold(), set_logger(), set_repeat_suggestions(), set_suggestions(), thresholdFilter(), update(), and updateSuggestedWords().
std::string Selector::previous_prefix [private] |
Definition at line 122 of file selector.h.
Referenced by Selector().
const char * Selector::REPEAT_SUGGESTIONS = "Presage.Selector.REPEAT_SUGGESTIONS" [static] |
Definition at line 100 of file selector.h.
Referenced by Selector().
bool Selector::repeat_suggestions [private] |
Definition at line 111 of file selector.h.
Referenced by get_repeat_suggestions(), select(), and set_repeat_suggestions().
StringSet Selector::suggestedWords [private] |
Definition at line 120 of file selector.h.
Referenced by clearSuggestedWords(), repetitionFilter(), and updateSuggestedWords().
const char * Selector::SUGGESTIONS = "Presage.Selector.SUGGESTIONS" [static] |
Definition at line 99 of file selector.h.
Referenced by Selector().
size_t Selector::suggestions [private] |
Definition at line 110 of file selector.h.
Referenced by get_suggestions(), select(), and set_suggestions().