presage.h   presage.h 
skipping to change at line 27 skipping to change at line 27
You should have received a copy of the GNU General Public License along You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc., with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* *
**********( *)*/ **********( *)*/
#ifndef PRESAGE #ifndef PRESAGE
#define PRESAGE #define PRESAGE
#include "presageException.h"
#include "presageCallback.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* Presage C API starts here
*/
typedef struct _presage* presage_t;
presage_error_code_t presage_new (_presage_callback_get
_past_stream past_stream_cb,
void* past_stream_cb_a
rg,
_presage_callback_get_
future_stream future_stream_cb,
void* future_stream_cb
_arg,
presage_t* result);
presage_error_code_t presage_new_with_config (_presage_callback_get
_past_stream past,
void* past_stream_cb_a
rg,
_presage_callback_get_
future_stream future_stream_cb,
void* future_stream_cb
_arg,
const char* config,
presage_t* result);
void presage_free (presage_t prsg);
void presage_free_string (char* str);
void presage_free_string_array (char** str);
presage_error_code_t presage_predict (presage_t prsg,
char*** result);
presage_error_code_t presage_completion (presage_t prsg,
const char* token,
char** result);
presage_error_code_t presage_context (presage_t prsg,
char** result);
presage_error_code_t presage_context_change (presage_t prsg,
int* result);
presage_error_code_t presage_prefix (presage_t prsg,
char** result);
presage_error_code_t presage_config (presage_t prsg,
const char* variable,
char** result);
presage_error_code_t presage_config_set (presage_t prsg,
const char* variable,
const char* value);
presage_error_code_t presage_save_config (presage_t prsg);
/*
* Presage C API ends here
*/
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
#include <string> #include <string>
#include <vector> #include <vector>
#include <map> #include <map>
// Forward declarations, not part of presage API /* Forward declarations, not part of presage C++ API */
class Configuration; class Configuration;
class ProfileManager; class ProfileManager;
class Profile; class Profile;
class ContextTracker; class ContextTracker;
class PredictorRegistry; class PredictorRegistry;
class PredictorActivator; class PredictorActivator;
class Selector; class Selector;
/* /*
* Presage public API starts here * Presage C++ API starts here
*/ */
#include "presageException.h"
#include "presageCallback.h"
/** \brief Presage, the intelligent predictive text entry platform. /** \brief Presage, the intelligent predictive text entry platform.
*/ */
class Presage { class Presage {
public: public:
/** Creates and initializes presage. /** Creates and initializes presage.
* *
* \param callback is a user-supplied implementation of PresageCallback interface * \param callback is a user-supplied implementation of PresageCallback interface
* *
* Presage does not take ownership of the callback object. * Presage does not take ownership of the callback object.
*/ */
Presage(PresageCallback* callback); Presage(PresageCallback* callback) throw (PresageException);
/** Creates and initializes presage with supplied configuration. /** Creates and initializes presage with supplied configuration.
* *
* \param callback is a user-supplied implementation of PresageCallback interface * \param callback is a user-supplied implementation of PresageCallback interface
* \param config path to configuration file * \param config path to configuration file
* *
* Presage does not take ownership of the callback object. * Presage does not take ownership of the callback object.
*/ */
Presage(PresageCallback* callback, const std::string config); Presage(PresageCallback* callback, const std::string config) throw (Pre sageException);
/** Destroys presage. /** Destroys presage.
*/ */
~Presage(); ~Presage();
/** \brief Obtain a prediction, and notify presage of newly /** \brief Obtain a prediction, and notify presage of newly
* entered text (if any, else empty string). * entered text (if any, else empty string).
* *
* This method notifies presage that new text was entered by * This method notifies presage that new text was entered by
* the user and requests that presage generates a prediction * the user and requests that presage generates a prediction
skipping to change at line 88 skipping to change at line 152
* It is possible to invoke this method passing an empty string as * It is possible to invoke this method passing an empty string as
* argument, in cases where no text was entered by the user since * argument, in cases where no text was entered by the user since
* the previous invocation. * the previous invocation.
* *
* This method returns a prediction based on the current * This method returns a prediction based on the current
* context. The prediction is a std::vector of std::string's. * context. The prediction is a std::vector of std::string's.
* *
* \return prediction * \return prediction
* *
*/ */
std::vector<std::string> predict(); std::vector<std::string> predict() throw (PresageException);
/** \brief Obtains a prediction that matches the supplied token /** \brief Obtains a prediction that matches the supplied token
* filter. * filter.
* *
* \param filter a vector of strings to use to filter the * \param filter a vector of strings to use to filter the
* prediction for desired tokens. I.e. If the current prefix is * prediction for desired tokens. I.e. If the current prefix is
* "gr" and the filter is ["ea", "an"], then only words starting * "gr" and the filter is ["ea", "an"], then only words starting
* with "grea" or "gran" such as "great" or "grand" * with "grea" or "gran" such as "great" or "grand"
* *
* \return prediction containing only tokens that begin with one * \return prediction containing only tokens that begin with one
* of the filter tokens. * of the filter tokens.
* *
*/ */
std::multimap<double, std::string> predict(std::vector<std::string> fil ter); std::multimap<double, std::string> predict(std::vector<std::string> fil ter) throw (PresageException);
/** \brief Callback getter/setter. /** \brief Callback getter/setter.
* *
* \param callback to be used by presage (pass a null pointer to * \param callback to be used by presage (pass a null pointer to
* obtain callback to current callback without modifying it) * obtain callback to current callback without modifying it)
* *
* \return pointer to previously used callback * \return pointer to previously used callback
*/ */
PresageCallback* callback(PresageCallback* callback); PresageCallback* callback(PresageCallback* callback) throw (PresageExce ption);
/** \brief Request presage to return the completion string for the give n predicted token. /** \brief Request presage to return the completion string for the give n predicted token.
* *
* Requests presage to return the completion string. The * Requests presage to return the completion string. The
* completion string is defined as the string which, when appended * completion string is defined as the string which, when appended
* to the current prefix, forms the token passed as the str * to the current prefix, forms the token passed as the str
* argument. * argument.
* *
* \param str successful prediction, for which a completion string * \param str successful prediction, for which a completion string
* is requested * is requested
* *
* \return completion string * \return completion string
*/ */
std::string completion(std::string str); std::string completion(std::string str) throw (PresageException);
/** \brief Returns the text entered so far. /** \brief Returns the text entered so far.
* *
* \return context, text entered so far. * \return context, text entered so far.
*/ */
std::string context() const; std::string context() const throw (PresageException);
/** \brief Returns true if a context change occured. /** \brief Returns true if a context change occured.
* *
* \return true if a context change occured after the last update * \return true if a context change occured after the last update
* or predict calls, or false otherwise. * or predict calls, or false otherwise.
*/ */
bool context_change() const; bool context_change() const throw (PresageException);
/** \brief Returns the current prefix. /** \brief Returns the current prefix.
* *
* \return prefix * \return prefix
*/ */
std::string prefix() const; std::string prefix() const throw (PresageException);
/** \brief Gets the value of specified configuration variable. /** \brief Gets the value of specified configuration variable.
* *
* Programmatically get the value currently assigned to the * Programmatically get the value currently assigned to the
* specified configuration \param variable * specified configuration \param variable
* *
* \return value assigned to configuration variable. * \return value assigned to configuration variable.
*/ */
std::string config(const std::string variable) const; std::string config(const std::string variable) const throw (PresageExce ption);
/** \brief Sets the value of specified configuration variable. /** \brief Sets the value of specified configuration variable.
* *
* Programmatically set the specified configuration \param * Programmatically set the specified configuration \param
* variable to \param value . This will override the setting read * variable to \param value . This will override the setting read
* from the configuration file in use. * from the configuration file in use.
* *
*/ */
void config(const std::string variable, const std::string value) const; void config(const std::string variable, const std::string value) const throw (PresageException);
/** \brief Save current configuration to file. /** \brief Save current configuration to file.
* *
* Call this method to persist current presage configuration to * Call this method to persist current presage configuration to
* file. The configuration data will be saved to the currently * file. The configuration data will be saved to the currently
* active XML profile. * active XML profile.
* *
*/ */
void save_config() const; void save_config() const throw (PresageException);
/* /*
* Presage public API ends here * Presage public API ends here
*/ */
private: private:
ProfileManager* profileManager; ProfileManager* profileManager;
Configuration* configuration; Configuration* configuration;
PredictorRegistry* predictorRegistry; PredictorRegistry* predictorRegistry;
ContextTracker* contextTracker; ContextTracker* contextTracker;
PredictorActivator* predictorActivator; PredictorActivator* predictorActivator;
Selector* selector; Selector* selector;
}; };
/*
* Presage C++ API ends here
*/
#endif /* __cplusplus */
/** \mainpage /** \mainpage
\section intro_section Introduction \section intro_section Introduction
Presage is an intelligent predictive text entry Presage is an intelligent predictive text entry
platform. Presage exploits <a platform. Presage exploits <a
href="http://en.wikipedia.org/wiki/Redundancy_%28information_theory%29" >redundant href="http://en.wikipedia.org/wiki/Redundancy_%28information_theory%29" >redundant
information</a> embedded in natural languages to generate information</a> embedded in natural languages to generate
predictions. Presage's modular and pluggable <a predictions. Presage's modular and pluggable <a
href="?q=node/14">architecture</a> allows its <a href="?q=node/14">architecture</a> allows its <a
skipping to change at line 241 skipping to change at line 310
href="http://www.gnu.org/copyleft/gpl.html">General Public href="http://www.gnu.org/copyleft/gpl.html">General Public
License</a>. License</a>.
\author Matteo Vescovi \author Matteo Vescovi
\section getting_started_section Getting started \section getting_started_section Getting started
\include getting_started.txt \include getting_started.txt
*/ */
#endif // PRESAGE #endif /* PRESAGE */
 End of changes. 18 change blocks. 
16 lines changed or deleted 93 lines changed or added


 presageCallback.h   presageCallback.h 
skipping to change at line 27 skipping to change at line 27
You should have received a copy of the GNU General Public License along You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc., with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* *
**********( *)*/ **********( *)*/
#ifndef PRESAGE_CALLBACK #ifndef PRESAGE_CALLBACK
#define PRESAGE_CALLBACK #define PRESAGE_CALLBACK
#ifdef __cplusplus
extern "C" {
#endif
typedef const char* (*_presage_callback_get_past_stream) (void*);
typedef const char* (*_presage_callback_get_future_stream) (void*);
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
#include <string> #include <string>
#include <sstream> #include <sstream>
/** Abstract callback object used to retrieve context from user application . /** Abstract callback object used to retrieve context from user application .
* *
* A concrete callback implementation must implement the * A concrete callback implementation must implement the
* getPastStream() and getFutureStream() method which are responsible * getPastStream() and getFutureStream() method which are responsible
* for retrieving the context from the user text buffer. * for retrieving the context from the user text buffer.
* *
* Using a callback object decouples the user application from the * Using a callback object decouples the user application from the
skipping to change at line 101 skipping to change at line 114
m_stream.erase(m_stream.end() - 1); m_stream.erase(m_stream.end() - 1);
} else { } else {
m_stream.push_back(character); m_stream.push_back(character);
} }
} }
std::string m_stream; std::string m_stream;
const std::string m_empty; const std::string m_empty;
}; };
#endif // PRESAGE_CALLBACK #endif /* _cplusplus */
#endif /* PRESAGE_CALLBACK */
 End of changes. 2 change blocks. 
0 lines changed or deleted 13 lines changed or added


 presageException.h   presageException.h 
skipping to change at line 27 skipping to change at line 27
You should have received a copy of the GNU General Public License along You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc., with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* *
**********( *)*/ **********( *)*/
#ifndef PRESAGE_EXCEPTION #ifndef PRESAGE_EXCEPTION
#define PRESAGE_EXCEPTION #define PRESAGE_EXCEPTION
#ifdef __cplusplus
extern "C" {
#endif
typedef enum
{
PRESAGE_OK = 0, /* successful result */
PRESAGE_ERROR, /* generic/unknown presage error */
PRESAGE_TOKEN_PREFIX_MISMATCH_ERROR,
PRESAGE_SMOOTHED_NGRAM_PREDICTOR_LEARN_ERROR,
PRESAGE_CONFIG_VARIABLE_ERROR,
PRESAGE_INVALID_CALLBACK_ERROR,
PRESAGE_INVALID_SUGGESTION_ERROR,
PRESAGE_INIT_PREDICTOR_ERROR,
PRESAGE_SQLITE_OPEN_DATABASE_ERROR,
PRESAGE_SQLITE_EXECUTE_SQL_ERROR
} presage_error_code_t;
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
#include <exception> #include <exception>
#include <string> #include <string>
/** When thrown, provides information about an error that has occurred with in presage. /** When thrown, provides information about an error that has occurred with in presage.
* *
* If an error occurs within presage, an exception is thrown, and * If an error occurs within presage, an exception is thrown, and
* this is the object that encapsulates the details of the problem. * this is the object that encapsulates the details of the problem.
* *
* Application using presage should always ensure that exceptions * Application using presage should always ensure that exceptions
* are caught by enclosing all presage methods within a try{} * are caught by enclosing all presage methods within a try{}
* catch(PresageException& e) {} block. * catch(PresageException& e) {} block.
* *
*/ */
class PresageException : public std::exception { class PresageException : public std::exception {
public: public:
PresageException(const std::string& msg) throw(); PresageException(presage_error_code_t code, const std::string& msg) thr
virtual ~PresageException() throw(); ow()
virtual const char* what() const throw(); : m_details (msg),
m_code (code)
{
// intentionally empty
}
virtual ~PresageException() throw()
{
// intentionally empty
}
virtual const char* what() const throw()
{
return m_details.c_str();
}
virtual const presage_error_code_t code() const throw()
{
return m_code;
}
private: private:
std::string details; std::string m_details;
presage_error_code_t m_code;
}; };
#endif // PRESAGE_EXCEPTION #endif /* __cplusplus */
#endif /* PRESAGE_EXCEPTION */
 End of changes. 4 change blocks. 
4 lines changed or deleted 48 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/