presage
0.9.2~beta
|
#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) |
Public Member Functions inherited from Observer | |
virtual | ~Observer () |
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 |
Additional Inherited Members | |
Protected Member Functions inherited from Observer | |
Observer () | |
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.
|
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.
Selector::~Selector | ( | ) |
Definition at line 50 of file selector.cpp.
|
private |
Clear the set of previously selected suggestions.
Definition at line 131 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 256 of file selector.cpp.
References greedy_suggestion_threshold.
bool Selector::get_repeat_suggestions | ( | ) | const |
Definition at line 251 of file selector.cpp.
References repeat_suggestions.
size_t Selector::get_suggestions | ( | ) | const |
Definition at line 246 of file selector.cpp.
References suggestions.
Referenced by Presage::predict().
|
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 145 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 233 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 194 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 221 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 204 of file selector.cpp.
References endl(), logger, suggestions, and Utility::toInt().
Referenced by Selector().
|
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 170 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 97 of file selector.cpp.
References clearSuggestedWords(), ContextTracker::contextChange(), and contextTracker.
|
virtual |
Implements Observer.
Definition at line 261 of file selector.cpp.
References Dispatcher< class_t >::dispatch(), dispatcher, endl(), Observable::get_name(), and logger.
|
private |
Adds suggestions to the set of previously selected suggestions.
Definition at line 109 of file selector.cpp.
References endl(), logger, and suggestedWords.
Referenced by select().
|
private |
Definition at line 125 of file selector.h.
Referenced by Selector().
|
private |
Definition at line 124 of file selector.h.
Referenced by select(), Selector(), thresholdFilter(), and update().
|
private |
Definition at line 108 of file selector.h.
|
private |
Definition at line 128 of file selector.h.
Referenced by Selector(), and update().
|
static |
Definition at line 101 of file selector.h.
Referenced by Selector().
|
private |
Definition at line 112 of file selector.h.
Referenced by get_greedy_suggestion_threshold(), select(), set_greedy_suggestion_threshold(), and thresholdFilter().
|
static |
Definition at line 98 of file selector.h.
Referenced by Selector().
|
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().
|
private |
Definition at line 122 of file selector.h.
Referenced by Selector().
|
static |
Definition at line 100 of file selector.h.
Referenced by Selector().
|
private |
Definition at line 111 of file selector.h.
Referenced by get_repeat_suggestions(), select(), and set_repeat_suggestions().
|
private |
Definition at line 120 of file selector.h.
Referenced by clearSuggestedWords(), repetitionFilter(), and updateSuggestedWords().
|
static |
Definition at line 99 of file selector.h.
Referenced by Selector().
|
private |
Definition at line 110 of file selector.h.
Referenced by get_suggestions(), select(), and set_suggestions().