presage  0.9.2~beta
Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | List of all members
Selector Class Reference

#include <selector.h>

Inheritance diagram for Selector:
Inheritance graph
Collaboration diagram for Selector:
Collaboration graph

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_tdispatch_map
 
size_t suggestions
 
bool repeat_suggestions
 
size_t greedy_suggestion_threshold
 
StringSet suggestedWords
 
std::string previous_prefix
 
ContextTrackercontextTracker
 
Configurationconfig
 
Logger< char > logger
 
Dispatcher< Selectordispatcher
 

Additional Inherited Members

- Protected Member Functions inherited from Observer
 Observer ()
 

Detailed Description

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.

Member Typedef Documentation

◆ mbr_func_ptr_t

typedef void(Selector::* Selector::mbr_func_ptr_t) (const std::string &)
private

Definition at line 107 of file selector.h.

Constructor & Destructor Documentation

◆ Selector()

Selector::Selector ( Configuration configuration,
ContextTracker ct 
)

◆ ~Selector()

Selector::~Selector ( )

Definition at line 50 of file selector.cpp.

Member Function Documentation

◆ clearSuggestedWords()

void Selector::clearSuggestedWords ( )
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().

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

◆ get_greedy_suggestion_threshold()

size_t Selector::get_greedy_suggestion_threshold ( ) const

Definition at line 256 of file selector.cpp.

References greedy_suggestion_threshold.

◆ get_repeat_suggestions()

bool Selector::get_repeat_suggestions ( ) const

Definition at line 251 of file selector.cpp.

References repeat_suggestions.

◆ get_suggestions()

size_t Selector::get_suggestions ( ) const

Definition at line 246 of file selector.cpp.

References suggestions.

Referenced by Presage::predict().

Here is the caller graph for this function:

◆ repetitionFilter()

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

Parameters
vand suggestedWords.

Definition at line 145 of file selector.cpp.

References endl(), logger, and suggestedWords.

Referenced by select().

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

◆ select()

std::vector< std::string > Selector::select ( Prediction  p)

◆ set_greedy_suggestion_threshold()

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().

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

◆ set_logger()

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().

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

◆ set_repeat_suggestions()

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().

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

◆ set_suggestions()

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().

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

◆ thresholdFilter()

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 170 of file selector.cpp.

References contextTracker, endl(), ContextTracker::getPrefix(), greedy_suggestion_threshold, and logger.

Referenced by select().

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

◆ update() [1/2]

void Selector::update ( )

Trigger update of the suggested tokens cache

Definition at line 97 of file selector.cpp.

References clearSuggestedWords(), ContextTracker::contextChange(), and contextTracker.

Here is the call graph for this function:

◆ update() [2/2]

void Selector::update ( const Observable variable)
virtual

Implements Observer.

Definition at line 261 of file selector.cpp.

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

Here is the call graph for this function:

◆ updateSuggestedWords()

void Selector::updateSuggestedWords ( const std::vector< std::string > &  v)
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().

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

Member Data Documentation

◆ config

Configuration* Selector::config
private

Definition at line 125 of file selector.h.

Referenced by Selector().

◆ contextTracker

ContextTracker* Selector::contextTracker
private

Definition at line 124 of file selector.h.

Referenced by select(), Selector(), thresholdFilter(), and update().

◆ dispatch_map

std::map<std::string, mbr_func_ptr_t> Selector::dispatch_map
private

Definition at line 108 of file selector.h.

◆ dispatcher

Dispatcher<Selector> Selector::dispatcher
private

Definition at line 128 of file selector.h.

Referenced by Selector(), and update().

◆ GREEDY_SUGGESTION_THRESHOLD

const char * Selector::GREEDY_SUGGESTION_THRESHOLD = "Presage.Selector.GREEDY_SUGGESTION_THRESHOLD"
static

Definition at line 101 of file selector.h.

Referenced by Selector().

◆ greedy_suggestion_threshold

size_t Selector::greedy_suggestion_threshold
private

◆ LOGGER

const char * Selector::LOGGER = "Presage.Selector.LOGGER"
static

Definition at line 98 of file selector.h.

Referenced by Selector().

◆ logger

Logger<char> Selector::logger
private

◆ previous_prefix

std::string Selector::previous_prefix
private

Definition at line 122 of file selector.h.

Referenced by Selector().

◆ REPEAT_SUGGESTIONS

const char * Selector::REPEAT_SUGGESTIONS = "Presage.Selector.REPEAT_SUGGESTIONS"
static

Definition at line 100 of file selector.h.

Referenced by Selector().

◆ repeat_suggestions

bool Selector::repeat_suggestions
private

Definition at line 111 of file selector.h.

Referenced by get_repeat_suggestions(), select(), and set_repeat_suggestions().

◆ suggestedWords

StringSet Selector::suggestedWords
private

Definition at line 120 of file selector.h.

Referenced by clearSuggestedWords(), repetitionFilter(), and updateSuggestedWords().

◆ SUGGESTIONS

const char * Selector::SUGGESTIONS = "Presage.Selector.SUGGESTIONS"
static

Definition at line 99 of file selector.h.

Referenced by Selector().

◆ suggestions

size_t Selector::suggestions
private

Definition at line 110 of file selector.h.

Referenced by get_suggestions(), select(), and set_suggestions().


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