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
90
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 */
103class Configuration;
104class ProfileManager;
105class Profile;
106class ContextTracker;
109class Selector;
110
113class Presage {
114public:
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
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
251private:
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
274extern "C" {
275#endif
276
277 typedef struct _presage* presage_t;
278
280 void* past_stream_cb_arg,
282 void* future_stream_cb_arg,
283 presage_t* result);
284
286 void* past_stream_cb_arg,
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 */
Tracks user interaction and context.
bool context_change() const EXCEPT(PresageException)
Returns true if a context change occured.
Definition presage.cpp:206
Configuration * configuration
Definition presage.h:253
std::string context() const EXCEPT(PresageException)
Returns the text entered so far.
Definition presage.cpp:200
void save_config() const EXCEPT(PresageException)
Save current configuration to file.
Definition presage.cpp:230
void learn(const std::string text) const EXCEPT(PresageException)
Learn from text offline.
Definition presage.cpp:139
std::vector< std::string > predict() EXCEPT(PresageException)
Obtain a prediction.
Definition presage.cpp:64
Presage(PresageCallback *callback) EXCEPT(PresageException)
Definition presage.cpp:33
Selector * selector
Definition presage.h:257
ContextTracker * contextTracker
Definition presage.h:255
~Presage()
Definition presage.cpp:55
std::string completion(std::string str) EXCEPT(PresageException)
Request presage to return the completion string for the given predicted token.
Definition presage.cpp:152
PredictorRegistry * predictorRegistry
Definition presage.h:254
PresageCallback * callback(PresageCallback *callback) EXCEPT(PresageException)
Callback getter/setter.
Definition presage.cpp:146
std::string prefix() const EXCEPT(PresageException)
Returns the current prefix.
Definition presage.cpp:212
ProfileManager * profileManager
Definition presage.h:252
std::string config(const std::string variable) const EXCEPT(PresageException)
Gets the value of specified configuration variable.
Definition presage.cpp:218
PredictorActivator * predictorActivator
Definition presage.h:256
const char *(* _presage_callback_get_past_stream)(void *)
const char *(* _presage_callback_get_future_stream)(void *)
std::string config
presage_error_code_t
presage_error_code_t presage_prefix(presage_t prsg, char **result)
Definition presage.cpp:431
presage_error_code_t presage_context(presage_t prsg, char **result)
Definition presage.cpp:415
presage_error_code_t presage_completion(presage_t prsg, const char *token, char **result)
Definition presage.cpp:407
#define EXCEPT(...)
Definition presage.h:34
struct _presage * presage_t
Definition presage.h:277
presage_error_code_t presage_predict(presage_t prsg, char ***result)
Definition presage.cpp:373
presage_error_code_t presage_learn(presage_t prsg, const char *text)
Definition presage.cpp:399
void presage_free_string_array(char **str)
Definition presage.cpp:363
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
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_context_change(presage_t prsg, int *result)
Definition presage.cpp:423
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
presage_error_code_t presage_config(presage_t prsg, const char *variable, char **result)
Definition presage.cpp:439
void presage_free(presage_t prsg)
Definition presage.cpp:347
void presage_free_string(char *str)
Definition presage.cpp:358
presage_error_code_t presage_save_config(presage_t prsg)
Definition presage.cpp:455