presage.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
#define PRESAGE
#include "presageException.h"
#include "presageCallback.h"
/********************************
* Presage C++ API starts here
*/
#ifdef __cplusplus
#ifndef _MSC_VER
#include <string>
#include <vector>
#include <map>
/* Forward declarations, not part of presage C++ API */
class Configuration;
class ProfileManager;
class Profile;
class ContextTracker;
class PredictorRegistry;
class PredictorActivator;
class Selector;
class Presage {
public:
Presage(PresageCallback* callback) noexcept(false);
Presage(PresageCallback* callback, const std::string config) noexcept(false);
~Presage();
std::vector<std::string> predict() noexcept(false);
std::multimap<double, std::string> predict(std::vector<std::string> filter) noexcept(false);
void learn(const std::string text) const noexcept(false);
PresageCallback* callback(PresageCallback* callback) noexcept(false);
std::string completion(std::string str) noexcept(false);
std::string context() const noexcept(false);
bool context_change() const noexcept(false);
std::string prefix() const noexcept(false);
std::string config(const std::string variable) const noexcept(false);
void config(const std::string variable, const std::string value) const noexcept(false);
void save_config() const noexcept(false);
/*
* Presage public API ends here
*/
private:
ProfileManager* profileManager;
Configuration* configuration;
PredictorRegistry* predictorRegistry;
ContextTracker* contextTracker;
PredictorActivator* predictorActivator;
Selector* selector;
};
#endif /* _MSC_VER */
#endif /* __cplusplus */
/*
* Presage C++ API ends here
*******************************/
/*******************************
* Presage C API starts here
*/
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _presage* presage_t;
presage_error_code_t presage_new (_presage_callback_get_past_stream past_stream_cb,
void* past_stream_cb_arg,
_presage_callback_get_future_stream future_stream_cb,
void* future_stream_cb_arg,
presage_t* result);
presage_error_code_t presage_new_with_config (_presage_callback_get_past_stream past,
void* past_stream_cb_arg,
_presage_callback_get_future_stream future_stream_cb,
void* future_stream_cb_arg,
const char* config,
presage_t* result);
void presage_free (presage_t prsg);
void presage_free_string (char* str);
void presage_free_string_array (char** str);
presage_error_code_t presage_predict (presage_t prsg,
char*** result);
presage_error_code_t presage_learn (presage_t prsg,
const char* text);
presage_error_code_t presage_completion (presage_t prsg,
const char* token,
char** result);
presage_error_code_t presage_context (presage_t prsg,
char** result);
presage_error_code_t presage_context_change (presage_t prsg,
int* result);
presage_error_code_t presage_prefix (presage_t prsg,
char** result);
presage_error_code_t presage_config (presage_t prsg,
const char* variable,
char** result);
presage_error_code_t presage_config_set (presage_t prsg,
const char* variable,
const char* value);
presage_error_code_t presage_save_config (presage_t prsg);
#ifdef __cplusplus
}
#endif
/*
* Presage C API ends here
****************************/
#endif /* PRESAGE */
Configuration
Definition configuration.h:36
ContextTracker
Tracks user interaction and context.
Definition contextTracker.h:155
PredictorActivator
Definition predictorActivator.h:62
PredictorRegistry
Definition predictorRegistry.h:46
PresageCallback
Definition presageCallback.h:66
Presage::callback
PresageCallback * callback(PresageCallback *callback) noexcept(false)
Callback getter/setter.
Definition presage.cpp:146
Presage::context
std::string context() const noexcept(false)
Returns the text entered so far.
Definition presage.cpp:200
Presage::configuration
Configuration * configuration
Definition presage.h:247
Presage::completion
std::string completion(std::string str) noexcept(false)
Request presage to return the completion string for the given predicted token.
Definition presage.cpp:152
Presage::prefix
std::string prefix() const noexcept(false)
Returns the current prefix.
Definition presage.cpp:212
Presage::config
std::string config(const std::string variable) const noexcept(false)
Gets the value of specified configuration variable.
Definition presage.cpp:218
Presage::predict
std::vector< std::string > predict() noexcept(false)
Obtain a prediction.
Definition presage.cpp:64
Presage::context_change
bool context_change() const noexcept(false)
Returns true if a context change occured.
Definition presage.cpp:206
Presage::selector
Selector * selector
Definition presage.h:251
Presage::contextTracker
ContextTracker * contextTracker
Definition presage.h:249
Presage::~Presage
~Presage()
Definition presage.cpp:55
Presage::predictorRegistry
PredictorRegistry * predictorRegistry
Definition presage.h:248
Presage::Presage
Presage(PresageCallback *callback) noexcept(false)
Definition presage.cpp:33
Presage::learn
void learn(const std::string text) const noexcept(false)
Learn from text offline.
Definition presage.cpp:139
Presage::save_config
void save_config() const noexcept(false)
Save current configuration to file.
Definition presage.cpp:230
Presage::profileManager
ProfileManager * profileManager
Definition presage.h:246
Presage::predictorActivator
PredictorActivator * predictorActivator
Definition presage.h:250
ProfileManager
Definition profileManager.h:51
Profile
Definition profile.h:56
Selector
Definition selector.h:80
presageCallback.h
_presage_callback_get_past_stream
const char *(* _presage_callback_get_past_stream)(void *)
Definition presageCallback.h:32
_presage_callback_get_future_stream
const char *(* _presage_callback_get_future_stream)(void *)
Definition presageCallback.h:33
config
std::string config
Definition presageDemo.cpp:70
presageException.h
presage_error_code_t
presage_error_code_t
Definition presageException.h:33
presage_prefix
presage_error_code_t presage_prefix(presage_t prsg, char **result)
Definition presage.cpp:431
presage_context
presage_error_code_t presage_context(presage_t prsg, char **result)
Definition presage.cpp:415
presage_completion
presage_error_code_t presage_completion(presage_t prsg, const char *token, char **result)
Definition presage.cpp:407
presage_t
struct _presage * presage_t
Definition presage.h:271
presage_predict
presage_error_code_t presage_predict(presage_t prsg, char ***result)
Definition presage.cpp:373
presage_learn
presage_error_code_t presage_learn(presage_t prsg, const char *text)
Definition presage.cpp:399
presage_free_string_array
void presage_free_string_array(char **str)
Definition presage.cpp:363
presage_new
presage_error_code_t presage_new(_presage_callback_get_past_stream past_stream_cb, void *past_stream_cb_arg, _presage_callback_get_future_stream future_stream_cb, void *future_stream_cb_arg, presage_t *result)
Definition presage.cpp:304
presage_config_set
presage_error_code_t presage_config_set(presage_t prsg, const char *variable, const char *value)
Definition presage.cpp:447
presage_context_change
presage_error_code_t presage_context_change(presage_t prsg, int *result)
Definition presage.cpp:423
presage_new_with_config
presage_error_code_t presage_new_with_config(_presage_callback_get_past_stream past, void *past_stream_cb_arg, _presage_callback_get_future_stream future_stream_cb, void *future_stream_cb_arg, const char *config, presage_t *result)
Definition presage.cpp:325
presage_config
presage_error_code_t presage_config(presage_t prsg, const char *variable, char **result)
Definition presage.cpp:439
presage_free
void presage_free(presage_t prsg)
Definition presage.cpp:347
presage_free_string
void presage_free_string(char *str)
Definition presage.cpp:358
presage_save_config
presage_error_code_t presage_save_config(presage_t prsg)
Definition presage.cpp:455
_presage
Definition presage.cpp:238