presage  0.9.2~beta
presage.h
Go to the documentation of this file.
1 
2 /******************************************************
3  * Presage, an extensible predictive text entry system
4  * ---------------------------------------------------
5  *
6  * Copyright (C) 2008 Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License along
19  with this program; if not, write to the Free Software Foundation, Inc.,
20  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  *
22  **********(*)*/
23 
24 
25 #ifndef PRESAGE
26 #define PRESAGE
27 
28 #include "presageException.h"
29 #include "presageCallback.h"
30 
85 /********************************
86  * Presage C++ API starts here
87  */
88 
89 #ifdef __cplusplus
90 #ifndef _MSC_VER
91 
92 #include <string>
93 #include <vector>
94 #include <map>
95 
96 /* Forward declarations, not part of presage C++ API */
97 class Configuration;
98 class ProfileManager;
99 class Profile;
100 class ContextTracker;
101 class PredictorRegistry;
102 class PredictorActivator;
103 class Selector;
104 
107 class Presage {
108 public:
116 
117 
125  Presage(PresageCallback* callback, const std::string config) throw (PresageException);
126 
127 
130  ~Presage();
131 
141  std::vector<std::string> predict() throw (PresageException);
142 
156  std::multimap<double, std::string> predict(std::vector<std::string> filter) throw (PresageException);
157 
170  void learn(const std::string text) const throw (PresageException);
171 
180 
193  std::string completion(std::string str) throw (PresageException);
194 
199  std::string context() const throw (PresageException);
200 
206  bool context_change() const throw (PresageException);
207 
212  std::string prefix() const throw (PresageException);
213 
221  std::string config(const std::string variable) const throw (PresageException);
222 
230  void config(const std::string variable, const std::string value) const throw (PresageException);
231 
239  void save_config() const throw (PresageException);
240 
246  std::string version() const throw (PresageException);
247 
248  /*
249  * Presage public API ends here
250  */
251 
252 private:
259 
260 };
261 
262 #endif /* _MSC_VER */
263 #endif /* __cplusplus */
264 
265 /*
266  * Presage C++ API ends here
267  *******************************/
268 
269 
270 /*******************************
271  * Presage C API starts here
272  */
273 
274 #ifdef __cplusplus
275 extern "C" {
276 #endif
277 
278  typedef struct _presage* presage_t;
279 
280  typedef struct {
281  char* token;
282  double probability;
284 
286 
287 
289  void* past_stream_cb_arg,
290  _presage_callback_get_future_stream future_stream_cb,
291  void* future_stream_cb_arg,
292  presage_t* result);
293 
295  void* past_stream_cb_arg,
296  _presage_callback_get_future_stream future_stream_cb,
297  void* future_stream_cb_arg,
298  const char* config,
299  presage_t* result);
300 
301  void presage_free (presage_t prsg);
302 
303  void presage_free_string (char* str);
304 
305  void presage_free_string_array (char** str);
306 
308 
310  char*** result);
311 
313  const char** filter,
314  presage_prediction_t* result);
315 
317  const char* text);
318 
320  const char* token,
321  char** result);
322 
324  char** result);
325 
327  int* result);
328 
330  char** result);
331 
333  const char* variable,
334  char** result);
335 
337  const char* variable,
338  const char* value);
339 
341 
343  char** result);
344 
345 #ifdef __cplusplus
346 }
347 #endif
348 
349 /*
350  * Presage C API ends here
351  ****************************/
352 
353 
354 #endif /* PRESAGE */
std::string config(const std::string variable) const
Gets the value of specified configuration variable.
Definition: presage.cpp:218
PredictorRegistry * predictorRegistry
Definition: presage.h:255
presage_error_code_t
Selector * selector
Definition: presage.h:258
presage_error_code_t presage_predict_with_filter(presage_t prsg, const char **filter, presage_prediction_t *result)
Definition: presage.cpp:417
std::vector< std::string > predict()
Obtain a prediction.
Definition: presage.cpp:64
PresageCallback * callback(PresageCallback *callback)
Callback getter/setter.
Definition: presage.cpp:146
presage_error_code_t presage_save_config(presage_t prsg)
Definition: presage.cpp:518
struct _presage * presage_t
Definition: presage.h:278
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:331
void presage_free_string_array(char **str)
Definition: presage.cpp:369
void presage_free(presage_t prsg)
Definition: presage.cpp:353
Presage(PresageCallback *callback)
Definition: presage.cpp:33
presage_error_code_t presage_config_set(presage_t prsg, const char *variable, const char *value)
Definition: presage.cpp:510
presage_error_code_t presage_predict(presage_t prsg, char ***result)
Definition: presage.cpp:391
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:310
PredictorActivator * predictorActivator
Definition: presage.h:257
ContextTracker * contextTracker
Definition: presage.h:256
std::string config
Definition: presageDemo.cpp:70
presage_suggestion_t * presage_prediction_t
Definition: presage.h:285
presage_error_code_t presage_prefix(presage_t prsg, char **result)
Definition: presage.cpp:494
std::string version() const
Returns presage release version.
Definition: presage.cpp:236
bool context_change() const
Returns true if a context change occured.
Definition: presage.cpp:206
~Presage()
Definition: presage.cpp:55
presage_error_code_t presage_context_change(presage_t prsg, int *result)
Definition: presage.cpp:486
presage_error_code_t presage_context(presage_t prsg, char **result)
Definition: presage.cpp:478
ProfileManager * profileManager
Definition: presage.h:253
presage_error_code_t presage_version(presage_t prsg, char **result)
Definition: presage.cpp:526
const char *(* _presage_callback_get_future_stream)(void *)
Presage, the intelligent predictive text entry platform.
Definition: presage.h:107
std::string prefix() const
Returns the current prefix.
Definition: presage.cpp:212
Configuration * configuration
Definition: presage.h:254
presage_error_code_t presage_config(presage_t prsg, const char *variable, char **result)
Definition: presage.cpp:502
std::string context() const
Returns the text entered so far.
Definition: presage.cpp:200
void save_config() const
Save current configuration to file.
Definition: presage.cpp:230
void presage_free_string(char *str)
Definition: presage.cpp:364
presage_error_code_t presage_learn(presage_t prsg, const char *text)
Definition: presage.cpp:462
Tracks user interaction and context.
void learn(const std::string text) const
Learn from text offline.
Definition: presage.cpp:139
const char *(* _presage_callback_get_past_stream)(void *)
presage_error_code_t presage_completion(presage_t prsg, const char *token, char **result)
Definition: presage.cpp:470
std::string completion(std::string str)
Request presage to return the completion string for the given predicted token.
Definition: presage.cpp:152
void presage_free_prediction(presage_prediction_t prediction)
Definition: presage.cpp:380