2
/******************************************************
3
* Presage, an extensible predictive text entry system
4
* ---------------------------------------------------
6
* Copyright (C) 2008 Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
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.
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.
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.
40
const char PROGRAM_NAME[] = "presage_demo_text";
43
void parse_cmd_line_args (int argc, char** argv);
44
void print_version ();
46
void print_prediction (const std::vector<std::string>&);
51
int main(int argc, char** argv)
53
parse_cmd_line_args (argc, argv);
56
// magic starts here...
57
LegacyPresageCallback callback;
58
Presage presage (&callback, config);
62
// convert int to string using a stringstream
65
presage.config("Presage.Selector.SUGGESTIONS", ss.str());
68
// buffer to read user input
69
const int BUFFER_SIZE = 80;
70
char buffer[ BUFFER_SIZE ];
73
std::cout << "> "; // prompt the user
74
std::cin.getline (buffer, BUFFER_SIZE); // read in string (if any)
76
callback.update(buffer); // update internal buffer
78
presage.predict() // request new prediction
80
std::cout << "-- Context: " << presage.context() << '|' << std::endl;
81
if (presage.context_change()) {
82
std::cout << "-- Context changed" << std::endl;
93
"Presage Textual Demo\n"
94
"--------------------\n"
96
"This program is intended as a demonstration of Presage ONLY.\n"
98
"The Presage project aims to provide an intelligent predictive text entry platform.\n"
100
"Its intent is NOT to provide a predictive text entry user interface.\n"
101
"Think of Presage as the predictive backend that sits behind a shiny user interface and does all the predictive heavy lifting.\n"
105
void parse_cmd_line_args (int argc, char* argv[])
110
const char* const short_options = "c:s:hv";
112
const struct option long_options[] = {
113
{ "config", required_argument, 0, 'c' },
114
{ "suggestions", required_argument, 0, 's' },
115
{ "help", no_argument, 0, 'h' },
116
{ "version", no_argument, 0, 'v' },
121
next_option = getopt_long( argc, argv,
122
short_options, long_options, NULL );
124
switch( next_option ) {
125
case 'c': // --config or -c option
128
case 's': // --suggestions or -s option
129
suggestions = atoi(optarg);
131
case 'h': // --help or -h option
135
case 'v': // --version or -v option
139
case '?': // unknown option
150
} while (next_option != -1);
153
void print_prediction (const std::vector<std::string>& words)
155
for( std::vector<std::string>::const_iterator i = words.begin();
158
std::cout << *i << std::endl;
162
void print_version ()
164
std::cout << PROGRAM_NAME << " (" << PACKAGE << ") version " << VERSION << std::endl
165
<< "Copyright (C) 2004 Matteo Vescovi." << std::endl
166
<< "This is free software; see the source for copying conditions. There is NO" << std::endl
167
<< "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE," << std::endl
168
<< "to the extent permitted by law." << std::endl;
173
std::cout << "Usage: " << PROGRAM_NAME << " [OPTION]..." << std::endl
175
<< "At the prompt, type in some text. Hit enter to generate a prediction." << std::endl
176
<< "Any text input is valid, including no text, a single character, or a long string." << std::endl
178
<< " -c, --config CONFIG use config file CONFIG" << std::endl
179
<< " -s, --suggestions N set prediction size to N suggestions" << std::endl
180
<< " -h, --help display this help and exit" << std::endl
181
<< " -v, --version output version information and exit" << std::endl
183
<< "Direct your bug reports to: " << PACKAGE_BUGREPORT << std::endl;