37 configuration = profileManager->get_configuration();
39 contextTracker =
new ContextTracker(configuration, predictorRegistry, callback);
40 predictorActivator =
new PredictorActivator(configuration, predictorRegistry, contextTracker);
41 selector =
new Selector(configuration, contextTracker);
48 configuration = profileManager->get_configuration();
50 contextTracker =
new ContextTracker(configuration, predictorRegistry, callback);
51 predictorActivator =
new PredictorActivator(configuration, predictorRegistry, contextTracker);
52 selector =
new Selector(configuration, contextTracker);
67 std::vector<std::string> result;
69 unsigned int multiplier = 1;
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;
109 Prediction prediction = predictorActivator->predict(multiplier++, internal_filter);
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();
134 contextTracker->update();
142 contextTracker->learn(text);
149 return const_cast<PresageCallback*
>(contextTracker->callback(callback));
171 std::string::size_type offset = str.find_first_not_of(
'\b');
177 if (contextTracker->isCompletionValid(str)) {
178 std::string prefix = contextTracker->getPrefix();
179 result = str.substr(prefix.size());
181 std::string message =
"[Presage] Error: token '";
183 message +=
"' does not match prefix: ";
184 message += contextTracker->getPrefix();
221 return configuration->find (variable)->get_value ();
227 configuration->insert (variable, value);
279 #define presage_exception_handler(CODE) \ 284 catch (PresageException& ex) \ 290 #define presage_exception_handler_with_result(CODE) \ 295 catch (PresageException& ex) \ 304 char* result_c_str = (
char*) malloc (str.size() + 1);
306 strcpy (result_c_str, str.c_str());
311 void* past_stream_cb_arg,
313 void* future_stream_cb_arg,
324 future_stream_cb_arg);
325 (*result)->presage_object =
new Presage ((*result)->presage_callback_object);
332 void* past_stream_cb_arg,
334 void* future_stream_cb_arg,
347 future_stream_cb_arg);
348 (*result)->presage_object =
new Presage ((*result)->presage_callback_object,
config);
373 for (
size_t t = 0; strs[t] != 0; t++)
384 for (
size_t i = 0; prediction[i].
token != 0; ++i)
385 free (prediction[i].token);
397 size_t prediction_c_str_size = prediction.size() + 1;
398 char** prediction_c_str = (
char**) malloc (prediction_c_str_size *
sizeof(
char*));
399 if (prediction_c_str != NULL)
401 memset (prediction_c_str, 0, prediction_c_str_size *
sizeof(
char*));
404 while (i < prediction_c_str_size - 1) {
405 prediction_c_str[i] = (
char*) malloc (prediction[i].size() + 1);
406 if (prediction_c_str[i] != NULL)
407 strcpy (prediction_c_str[i], prediction[i].c_str());
410 prediction_c_str[i] = 0;
413 *result = prediction_c_str;
423 typedef std::multimap<double, std::string> prediction_map_t;
424 typedef std::multimap<double, std::string>::const_reverse_iterator prediction_map_const_reverse_iterator_t;
428 std::vector<std::string> filt;
429 for (
size_t i = 0; filter[i] != 0; i++)
431 filt.push_back(filter[i]);
435 size_t prediction_result_size = prediction.size() + 1;
438 if (prediction_result != NULL)
440 memset (prediction_result, 0, prediction_result_size *
sizeof (*prediction_result));
443 for (prediction_map_const_reverse_iterator_t it = prediction.rbegin();
444 it != prediction.rend();
447 prediction_result[i].
token = (
char*) malloc ((it->second).size() + 1);
448 if (prediction_result[i].token != NULL)
450 strcpy (prediction_result[i].token, (it->second).c_str());
458 *result = prediction_result;
std::string config(const std::string variable) const
Gets the value of specified configuration variable.
PredictorRegistry * predictorRegistry
Prediction predict(unsigned int multiplier, const char **filter)
void presage_free(presage_t prsg)
presage_error_code_t presage_save_config(presage_t prsg)
presage_error_code_t presage_prefix(presage_t prsg, char **result)
std::string get_past_stream() const
void presage_free_prediction(presage_prediction_t prediction)
presage_error_code_t presage_predict(presage_t prsg, char ***result)
std::vector< std::string > predict()
Obtain a prediction.
PresageCallback * callback(PresageCallback *callback)
Callback getter/setter.
presage_error_code_t presage_learn(presage_t prsg, const char *text)
std::string getPastStream() const
void * m_get_future_stream_cb_arg
presage_error_code_t presage_config(presage_t prsg, const char *variable, char **result)
presage_error_code_t presage_predict_with_filter(presage_t prsg, const char **filter, presage_prediction_t *result)
Presage(PresageCallback *callback)
void save_profile() const
double getProbability() const
PresageCallback * presage_callback_object
#define presage_exception_handler_with_result(CODE)
void presage_free_string_array(char **strs)
static char * alloc_c_str(const std::string &str)
#define presage_exception_handler(CODE)
presage_error_code_t presage_context(presage_t prsg, char **result)
PredictorActivator * predictorActivator
presage_error_code_t presage_context_change(presage_t prsg, int *result)
ContextTracker * contextTracker
presage_suggestion_t * presage_prediction_t
Suggestion getSuggestion(int=0) const
std::string version() const
Returns presage release version.
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_config_set(presage_t prsg, const char *variable, const char *value)
void * m_get_past_stream_cb_arg
bool context_change() const
Returns true if a context change occured.
presage_error_code_t presage_version(presage_t prsg, char **result)
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_callback_get_past_stream m_get_past_stream_cb
ProfileManager * profileManager
const char *(* _presage_callback_get_future_stream)(void *)
Presage, the intelligent predictive text entry platform.
std::string prefix() const
Returns the current prefix.
CPresageCallback(_presage_callback_get_past_stream past, void *past_arg, _presage_callback_get_future_stream future, void *future_arg)
std::string context() const
Returns the text entered so far.
void save_config() const
Save current configuration to file.
std::vector< std::string > select(Prediction)
presage_error_code_t presage_completion(presage_t prsg, const char *token, char **result)
std::string get_future_stream() const
Tracks user interaction and context.
void learn(const std::string text) const
Learn from text offline.
size_t get_suggestions() const
void presage_free_string(char *str)
std::string getPrefix() const
const char *(* _presage_callback_get_past_stream)(void *)
_presage_callback_get_future_stream m_get_future_stream_cb
std::string completion(std::string str)
Request presage to return the completion string for the given predicted token.
virtual ~CPresageCallback()