selector.h
Go to the documentation of this file.
/******************************************************
* Presage, an extensible predictive text entry system
* ---------------------------------------------------
*
* Copyright (C) 2008 Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
**********(*)*/
#ifndef PRESAGE_SELECTOR
#define PRESAGE_SELECTOR
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "suggestion.h"
#include "prediction.h"
#include "context_tracker/contextTracker.h"
#include "logger.h"
#include "dispatcher.h"
#include <string>
#include <vector>
#include <set>
#include <stdlib.h> // needed for abort()
typedef std::set< std::string, std::less<std::string> > StringSet;
class Selector : public Observer {
public:
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;
static const char* LOGGER;
static const char* SUGGESTIONS;
static const char* REPEAT_SUGGESTIONS;
static const char* GREEDY_SUGGESTION_THRESHOLD;
virtual void update (const Observable* variable);
private:
// handle observable notifications
typedef void (Selector::* mbr_func_ptr_t)(const std::string&);
std::map<std::string, mbr_func_ptr_t> dispatch_map;
size_t suggestions;
bool repeat_suggestions;
size_t greedy_suggestion_threshold;
void updateSuggestedWords( const std::vector<std::string>& );
void clearSuggestedWords();
void repetitionFilter( std::vector<std::string>& );
void thresholdFilter( std::vector<std::string>& );
StringSet suggestedWords;
std::string previous_prefix;
ContextTracker* contextTracker;
Configuration* config;
Logger<char> logger;
Dispatcher<Selector> dispatcher;
};
#endif // PRESAGE_SELECTOR
Logger< char >
Prediction
Definition: prediction.h:47
Selector::set_greedy_suggestion_threshold
void set_greedy_suggestion_threshold(const std::string &value)
Definition: selector.cpp:233
Dispatcher< Selector >
Selector::greedy_suggestion_threshold
size_t greedy_suggestion_threshold
Definition: selector.h:112
Selector::get_greedy_suggestion_threshold
size_t get_greedy_suggestion_threshold() const
Definition: selector.cpp:256
Selector::dispatcher
Dispatcher< Selector > dispatcher
Definition: selector.h:128
Selector::GREEDY_SUGGESTION_THRESHOLD
static const char * GREEDY_SUGGESTION_THRESHOLD
Definition: selector.h:101
Selector::config
Configuration * config
Definition: selector.h:125
Selector::mbr_func_ptr_t
void(Selector::* mbr_func_ptr_t)(const std::string &)
Definition: selector.h:107
Selector::Selector
Selector(Configuration *, ContextTracker *)
Definition: selector.cpp:34
Selector::clearSuggestedWords
void clearSuggestedWords()
Definition: selector.cpp:131
suggestion.h
contextTracker.h
Selector::thresholdFilter
void thresholdFilter(std::vector< std::string > &)
Definition: selector.cpp:170
Selector::repeat_suggestions
bool repeat_suggestions
Definition: selector.h:111
Selector::set_logger
void set_logger(const std::string &value)
Definition: selector.cpp:194
Selector::suggestedWords
StringSet suggestedWords
Definition: selector.h:120
Selector::get_repeat_suggestions
bool get_repeat_suggestions() const
Definition: selector.cpp:251
Selector::previous_prefix
std::string previous_prefix
Definition: selector.h:122
Selector::repetitionFilter
void repetitionFilter(std::vector< std::string > &)
Definition: selector.cpp:145
Selector
Definition: selector.h:80
Observer
Definition: observer.h:34
Selector::REPEAT_SUGGESTIONS
static const char * REPEAT_SUGGESTIONS
Definition: selector.h:100
dispatcher.h
prediction.h
Selector::SUGGESTIONS
static const char * SUGGESTIONS
Definition: selector.h:99
Configuration
Definition: configuration.h:36
StringSet
std::set< std::string, std::less< std::string > > StringSet
Definition: selector.h:44
Selector::updateSuggestedWords
void updateSuggestedWords(const std::vector< std::string > &)
Definition: selector.cpp:109
Selector::contextTracker
ContextTracker * contextTracker
Definition: selector.h:124
Selector::set_suggestions
void set_suggestions(const std::string &value)
Definition: selector.cpp:204
Selector::LOGGER
static const char * LOGGER
Definition: selector.h:98
Selector::~Selector
~Selector()
Definition: selector.cpp:50
logger.h
Selector::suggestions
size_t suggestions
Definition: selector.h:110
Selector::get_suggestions
size_t get_suggestions() const
Definition: selector.cpp:246
Selector::select
std::vector< std::string > select(Prediction)
Definition: selector.cpp:55
ContextTracker
Tracks user interaction and context.
Definition: contextTracker.h:155
Selector::logger
Logger< char > logger
Definition: selector.h:126
Selector::set_repeat_suggestions
void set_repeat_suggestions(const std::string &value)
Definition: selector.cpp:221
Selector::dispatch_map
std::map< std::string, mbr_func_ptr_t > dispatch_map
Definition: selector.h:108
Observable
Definition: observable.h:37
Selector::update
void update()
Definition: selector.cpp:97