presage  0.9.1
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 
31 #if __cplusplus >= 201103L
32 #define EXCEPT(...) noexcept(false)
33 #else
34 #define EXCEPT(...) throw(__VA_ARGS__)
35 #endif
36 
91 /********************************
92  * Presage C++ API starts here
93  */
94 
95 #ifdef __cplusplus
96 #ifndef _MSC_VER
97 
98 #include <string>
99 #include <vector>
100 #include <map>
101 
102 /* Forward declarations, not part of presage C++ API */
103 class Configuration;
104 class ProfileManager;
105 class Profile;
106 class ContextTracker;
107 class PredictorRegistry;
108 class PredictorActivator;
109 class Selector;
110 
113 class Presage {
114 public:
122 
123 
132 
133 
136  ~Presage();
137 
147  std::vector<std::string> predict() EXCEPT(PresageException);
148 
162  std::multimap<double, std::string> predict(std::vector<std::string> filter) EXCEPT(PresageException);
163 
176  void learn(const std::string text) const EXCEPT(PresageException);
177 
186 
199  std::string completion(std::string str) EXCEPT(PresageException);
200 
205  std::string context() const EXCEPT(PresageException);
206 
212  bool context_change() const EXCEPT(PresageException);
213 
218  std::string prefix() const EXCEPT(PresageException);
219 
227  std::string config(const std::string variable) const EXCEPT(PresageException);
228 
236  void config(const std::string variable, const std::string value) const EXCEPT(PresageException);
237 
245  void save_config() const EXCEPT(PresageException);
246 
247  /*
248  * Presage public API ends here
249  */
250 
251 private:
258 
259 };
260 
261 #endif /* _MSC_VER */
262 #endif /* __cplusplus */
263 
264 /*
265  * Presage C++ API ends here
266  *******************************/
267 
268 
269 /*******************************
270  * Presage C API starts here
271  */
272 
273 #ifdef __cplusplus
274 extern "C" {
275 #endif
276 
277  typedef struct _presage* presage_t;
278 
280  void* past_stream_cb_arg,
281  _presage_callback_get_future_stream future_stream_cb,
282  void* future_stream_cb_arg,
283  presage_t* result);
284 
286  void* past_stream_cb_arg,
287  _presage_callback_get_future_stream future_stream_cb,
288  void* future_stream_cb_arg,
289  const char* config,
290  presage_t* result);
291 
292  void presage_free (presage_t prsg);
293 
294  void presage_free_string (char* str);
295  void presage_free_string_array (char** str);
296 
298  char*** result);
299 
301  const char* text);
302 
304  const char* token,
305  char** result);
306 
308  char** result);
309 
311  int* result);
312 
314  char** result);
315 
317  const char* variable,
318  char** result);
319 
321  const char* variable,
322  const char* value);
323 
325 
326 #ifdef __cplusplus
327 }
328 #endif
329 
330 /*
331  * Presage C API ends here
332  ****************************/
333 
334 
335 #endif /* PRESAGE */
void learn(const std::string text) const EXCEPT(PresageException)
Learn from text offline.
Definition: presage.cpp:139
PredictorRegistry * predictorRegistry
Definition: presage.h:254
presage_error_code_t
Selector * selector
Definition: presage.h:257
presage_error_code_t presage_save_config(presage_t prsg)
Definition: presage.cpp:455
struct _presage * presage_t
Definition: presage.h:277
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
void presage_free_string_array(char **str)
Definition: presage.cpp:363
void presage_free(presage_t prsg)
Definition: presage.cpp:347
presage_error_code_t presage_config_set(presage_t prsg, const char *variable, const char *value)
Definition: presage.cpp:447
presage_error_code_t presage_predict(presage_t prsg, char ***result)
Definition: presage.cpp:373
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
PredictorActivator * predictorActivator
Definition: presage.h:256
bool context_change() const EXCEPT(PresageException)
Returns true if a context change occured.
Definition: presage.cpp:206
ContextTracker * contextTracker
Definition: presage.h:255
std::string config
Definition: presageDemo.cpp:70
std::vector< std::string > predict() EXCEPT(PresageException)
Obtain a prediction.
Definition: presage.cpp:64
std::string completion(std::string str) EXCEPT(PresageException)
Request presage to return the completion string for the given predicted token.
Definition: presage.cpp:152
presage_error_code_t presage_prefix(presage_t prsg, char **result)
Definition: presage.cpp:431
Presage(PresageCallback *callback) EXCEPT(PresageException)
Definition: presage.cpp:33
~Presage()
Definition: presage.cpp:55
presage_error_code_t presage_context_change(presage_t prsg, int *result)
Definition: presage.cpp:423
presage_error_code_t presage_context(presage_t prsg, char **result)
Definition: presage.cpp:415
void save_config() const EXCEPT(PresageException)
Save current configuration to file.
Definition: presage.cpp:230
ProfileManager * profileManager
Definition: presage.h:252
const char *(* _presage_callback_get_future_stream)(void *)
Presage, the intelligent predictive text entry platform.
Definition: presage.h:113
PresageCallback * callback(PresageCallback *callback) EXCEPT(PresageException)
Callback getter/setter.
Definition: presage.cpp:146
Configuration * configuration
Definition: presage.h:253
presage_error_code_t presage_config(presage_t prsg, const char *variable, char **result)
Definition: presage.cpp:439
std::string prefix() const EXCEPT(PresageException)
Returns the current prefix.
Definition: presage.cpp:212
std::string config(const std::string variable) const EXCEPT(PresageException)
Gets the value of specified configuration variable.
Definition: presage.cpp:218
void presage_free_string(char *str)
Definition: presage.cpp:358
presage_error_code_t presage_learn(presage_t prsg, const char *text)
Definition: presage.cpp:399
Tracks user interaction and context.
#define EXCEPT(...)
Definition: presage.h:34
std::string context() const EXCEPT(PresageException)
Returns the text entered so far.
Definition: presage.cpp:200
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:407