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);
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.
std::string getPastStream() const
std::string getPrefix() const
Suggestion getSuggestion(int=0) const
Prediction predict(unsigned int multiplier, const char **filter)
Presage, the intelligent predictive text entry platform.
std::string prefix() const
Returns the current prefix.
std::string context() const
Returns the text entered so far.
std::string completion(std::string str)
Request presage to return the completion string for the given predicted token.
std::vector< std::string > predict()
Obtain a prediction.
PresageCallback * callback(PresageCallback *callback)
Callback getter/setter.
ContextTracker * contextTracker
PredictorRegistry * predictorRegistry
bool context_change() const
Returns true if a context change occured.
Presage(PresageCallback *callback)
ProfileManager * profileManager
void save_config() const
Save current configuration to file.
std::string config(const std::string variable) const
Gets the value of specified configuration variable.
void learn(const std::string text) const
Learn from text offline.
PredictorActivator * predictorActivator
void save_profile() const
std::vector< std::string > select(Prediction)
size_t get_suggestions() const
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)
static char * alloc_c_str(const std::string &str)
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)
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)
PresageCallback * presage_callback_object