67 std::vector<std::string> result;
69 unsigned int multiplier = 1;
71 result =
selector->select(prediction);
74 while ((result.size() < (
selector->get_suggestions()))
81 result = selector->select(prediction);
82 previous_prediction = prediction;
93 std::multimap<double, std::string> result;
95 std::vector<std::string> selection;
96 const char** internal_filter = 0;
101 internal_filter =
new const char*[filter.size() + 1];
102 for (std::vector<std::string>::size_type i = 0; i < filter.size(); i++) {
103 internal_filter[i] = filter[i].c_str();
105 internal_filter[filter.size()] = 0;
108 unsigned int multiplier = 1;
110 selection =
selector->select(prediction);
113 while ((selection.size() < (
selector->get_suggestions()))
114 && (prediction =
predictorActivator->predict(multiplier++, internal_filter)).size() > previous_prediction.
size()) {
120 selection =
selector->select(prediction);
121 previous_prediction = prediction;
124 delete[] internal_filter;
126 for (std::vector<std::string>::const_iterator it = selection.begin();
127 it != selection.end();
171 std::string::size_type offset = str.find_first_not_of(
'\b');
179 result = str.substr(
prefix.size());
181 std::string message =
"[Presage] Error: token '";
183 message +=
"' does not match prefix: ";
273#define presage_exception_handler(CODE) \
278 catch (PresageException& ex) \
284#define presage_exception_handler_with_result(CODE) \
289 catch (PresageException& ex) \
298 char* result_c_str = (
char*) malloc (str.size() + 1);
300 strcpy (result_c_str, str.c_str());
305 void* past_stream_cb_arg,
307 void* future_stream_cb_arg,
318 future_stream_cb_arg);
319 (*result)->presage_object =
new Presage ((*result)->presage_callback_object);
326 void* past_stream_cb_arg,
328 void* future_stream_cb_arg,
341 future_stream_cb_arg);
342 (*result)->presage_object =
new Presage ((*result)->presage_callback_object,
config);
366 for (
size_t t = 0; strs[t] != 0; t++) {
379 size_t prediction_c_str_size = prediction.size() + 1;
380 char** prediction_c_str = (
char**) malloc (prediction_c_str_size *
sizeof(
char*));
381 if (prediction_c_str != NULL)
383 memset (prediction_c_str, 0, prediction_c_str_size *
sizeof(
char*));
386 while (i < prediction_c_str_size - 1) {
387 prediction_c_str[i] = (
char*) malloc (prediction[i].size() + 1);
388 if (prediction_c_str[i] != NULL)
389 strcpy (prediction_c_str[i], prediction[i].c_str());
392 prediction_c_str[i] = 0;
395 *result = prediction_c_str;
virtual ~CPresageCallback()
CPresageCallback(_presage_callback_get_past_stream past, void *past_arg, _presage_callback_get_future_stream future, void *future_arg)
void * m_get_past_stream_cb_arg
void * m_get_future_stream_cb_arg
_presage_callback_get_past_stream m_get_past_stream_cb
_presage_callback_get_future_stream m_get_future_stream_cb
std::string get_past_stream() const
std::string get_future_stream() const
Tracks user interaction and context.
Suggestion getSuggestion(int=0) const
Presage, the intelligent predictive text entry platform.
bool context_change() const EXCEPT(PresageException)
Returns true if a context change occured.
Configuration * configuration
std::string context() const EXCEPT(PresageException)
Returns the text entered so far.
void save_config() const EXCEPT(PresageException)
Save current configuration to file.
void learn(const std::string text) const EXCEPT(PresageException)
Learn from text offline.
std::vector< std::string > predict() EXCEPT(PresageException)
Obtain a prediction.
Presage(PresageCallback *callback) EXCEPT(PresageException)
ContextTracker * contextTracker
std::string completion(std::string str) EXCEPT(PresageException)
Request presage to return the completion string for the given predicted token.
PredictorRegistry * predictorRegistry
PresageCallback * callback(PresageCallback *callback) EXCEPT(PresageException)
Callback getter/setter.
std::string prefix() const EXCEPT(PresageException)
Returns the current prefix.
ProfileManager * profileManager
std::string config(const std::string variable) const EXCEPT(PresageException)
Gets the value of specified configuration variable.
PredictorActivator * predictorActivator
double getProbability() const
const char *(* _presage_callback_get_past_stream)(void *)
const char *(* _presage_callback_get_future_stream)(void *)
@ PRESAGE_TOKEN_PREFIX_MISMATCH_ERROR
presage_error_code_t presage_prefix(presage_t prsg, char **result)
void presage_free_string_array(char **strs)
presage_error_code_t presage_context(presage_t prsg, char **result)
presage_error_code_t presage_completion(presage_t prsg, const char *token, char **result)
presage_error_code_t presage_new_with_config(_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, const char *config, presage_t *result)
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_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)
#define presage_exception_handler(CODE)
presage_error_code_t presage_config_set(presage_t prsg, const char *variable, const char *value)
presage_error_code_t presage_context_change(presage_t prsg, int *result)
#define presage_exception_handler_with_result(CODE)
static char * alloc_c_str(const std::string &str)
presage_error_code_t presage_config(presage_t prsg, const char *variable, char **result)
void presage_free(presage_t prsg)
void presage_free_string(char *str)
presage_error_code_t presage_save_config(presage_t prsg)
struct _presage * presage_t
PresageCallback * presage_callback_object