presage 0.9.1
smoothedNgramPredictor.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_SMOOTHEDNGRAMPREDICTOR
26#define PRESAGE_SMOOTHEDNGRAMPREDICTOR
27
28#include "predictor.h"
29#include "../core/logger.h"
30#include "../core/dispatcher.h"
32
33#include <assert.h>
34
35#if defined(HAVE_SQLITE3_H)
36# include <sqlite3.h>
37#elif defined(HAVE_SQLITE_H)
38# include <sqlite.h>
39#else
40# error "SQLite is required. Please install SQLite."
41#endif
42
43
48public:
51
52 virtual Prediction predict(const size_t size, const char** filter) const;
53
54 virtual void learn(const std::vector<std::string>& change);
55
56 virtual void update (const Observable* variable);
57
58private:
59 std::string LOGGER;
60 std::string DBFILENAME;
61 std::string DELTAS;
62 std::string LEARN;
63 std::string DATABASE_LOGGER;
64
65 unsigned int count(const std::vector<std::string>& tokens, int offset, int ngram_size) const;
66 void check_learn_consistency(const Ngram& name) const;
67
68 void set_dbfilename (const std::string& filename);
69 void set_deltas (const std::string& deltas);
70 void set_database_logger_level (const std::string& level);
71 void set_learn (const std::string& learn_mode);
72
74
76 std::string dbfilename;
77 std::string dbloglevel;
78 std::vector<double> deltas;
79 size_t cardinality; // cardinality == what is the n in n-gram?
82
84};
85
86#endif // PRESAGE_SMOOTHEDNGRAMPREDICTOR
Tracks user interaction and context.
Definition: ngram.h:33
const std::string name
Definition: predictor.h:77
void check_learn_consistency(const Ngram &name) const
Dispatcher< SmoothedNgramPredictor > dispatcher
std::vector< double > deltas
void set_database_logger_level(const std::string &level)
virtual void learn(const std::vector< std::string > &change)
unsigned int count(const std::vector< std::string > &tokens, int offset, int ngram_size) const
Builds the required n-gram and returns its count.
virtual void update(const Observable *variable)
void set_dbfilename(const std::string &filename)
void set_learn(const std::string &learn_mode)
virtual Prediction predict(const size_t size, const char **filter) const
Generate prediction.
void set_deltas(const std::string &deltas)