presage
0.9.2~beta
presage
src
lib
predictors
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"
31
#include "
dbconnector/sqliteDatabaseConnector.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
47
class
SmoothedNgramPredictor
:
public
Predictor
,
public
Observer
{
48
public
:
49
SmoothedNgramPredictor
(
Configuration
*,
ContextTracker
*,
const
char
*);
50
~SmoothedNgramPredictor
();
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
58
private
:
59
std::string
LOGGER
;
60
std::string
DBFILENAME
;
61
std::string
DELTAS
;
62
std::string
COUNT_THRESHOLD
;
63
std::string
LEARN
;
64
std::string
DATABASE_LOGGER
;
65
66
unsigned
int
count
(
const
std::vector<std::string>& tokens,
int
offset,
int
ngram_size)
const
;
67
void
check_learn_consistency
(
const
Ngram
&
name
)
const
;
68
69
void
set_dbfilename
(
const
std::string& filename);
70
void
set_deltas
(
const
std::string&
deltas
);
71
void
set_count_threshold
(
const
std::string& value);
72
void
set_database_logger_level
(
const
std::string& level);
73
void
set_learn
(
const
std::string&
learn_mode
);
74
75
void
init_database_connector_if_ready
();
76
77
DatabaseConnector
*
db
;
78
std::string
dbfilename
;
79
std::string
dbloglevel
;
80
std::vector<double>
deltas
;
81
int
count_threshold
;
82
size_t
cardinality
;
// cardinality == what is the n in n-gram?
83
bool
learn_mode
;
84
bool
learn_mode_set
;
85
86
Dispatcher<SmoothedNgramPredictor>
dispatcher
;
87
};
88
89
#endif // PRESAGE_SMOOTHEDNGRAMPREDICTOR
predictor.h
Prediction
Definition:
prediction.h:47
Dispatcher< SmoothedNgramPredictor >
SmoothedNgramPredictor::~SmoothedNgramPredictor
~SmoothedNgramPredictor()
Definition:
smoothedNgramPredictor.cpp:61
SmoothedNgramPredictor::dispatcher
Dispatcher< SmoothedNgramPredictor > dispatcher
Definition:
smoothedNgramPredictor.h:86
SmoothedNgramPredictor::count_threshold
int count_threshold
Definition:
smoothedNgramPredictor.h:81
Predictor
Definition:
predictor.h:46
SmoothedNgramPredictor::learn_mode_set
bool learn_mode_set
Definition:
smoothedNgramPredictor.h:84
SmoothedNgramPredictor::dbloglevel
std::string dbloglevel
Definition:
smoothedNgramPredictor.h:79
DatabaseConnector
Definition:
databaseConnector.h:44
SmoothedNgramPredictor::set_count_threshold
void set_count_threshold(const std::string &value)
Definition:
smoothedNgramPredictor.cpp:99
SmoothedNgramPredictor::learn
virtual void learn(const std::vector< std::string > &change)
Definition:
smoothedNgramPredictor.cpp:344
SmoothedNgramPredictor::LEARN
std::string LEARN
Definition:
smoothedNgramPredictor.h:63
SmoothedNgramPredictor::DBFILENAME
std::string DBFILENAME
Definition:
smoothedNgramPredictor.h:60
SmoothedNgramPredictor::set_database_logger_level
void set_database_logger_level(const std::string &level)
Definition:
smoothedNgramPredictor.cpp:76
SmoothedNgramPredictor::set_deltas
void set_deltas(const std::string &deltas)
Definition:
smoothedNgramPredictor.cpp:82
SmoothedNgramPredictor::deltas
std::vector< double > deltas
Definition:
smoothedNgramPredictor.h:80
SmoothedNgramPredictor::init_database_connector_if_ready
void init_database_connector_if_ready()
Definition:
smoothedNgramPredictor.cpp:117
Predictor::name
const std::string name
Definition:
predictor.h:77
SmoothedNgramPredictor::count
unsigned int count(const std::vector< std::string > &tokens, int offset, int ngram_size) const
Builds the required n-gram and returns its count.
Definition:
smoothedNgramPredictor.cpp:181
SmoothedNgramPredictor::cardinality
size_t cardinality
Definition:
smoothedNgramPredictor.h:82
SmoothedNgramPredictor::update
virtual void update(const Observable *variable)
Definition:
smoothedNgramPredictor.cpp:508
Observer
Definition:
observer.h:34
SmoothedNgramPredictor::DELTAS
std::string DELTAS
Definition:
smoothedNgramPredictor.h:61
SmoothedNgramPredictor::set_learn
void set_learn(const std::string &learn_mode)
Definition:
smoothedNgramPredictor.cpp:106
SmoothedNgramPredictor::check_learn_consistency
void check_learn_consistency(const Ngram &name) const
Definition:
smoothedNgramPredictor.cpp:473
Configuration
Definition:
configuration.h:36
SmoothedNgramPredictor::SmoothedNgramPredictor
SmoothedNgramPredictor(Configuration *, ContextTracker *, const char *)
Definition:
smoothedNgramPredictor.cpp:31
sqliteDatabaseConnector.h
SmoothedNgramPredictor::learn_mode
bool learn_mode
Definition:
smoothedNgramPredictor.h:83
SmoothedNgramPredictor::db
DatabaseConnector * db
Definition:
smoothedNgramPredictor.h:77
SmoothedNgramPredictor::dbfilename
std::string dbfilename
Definition:
smoothedNgramPredictor.h:78
SmoothedNgramPredictor::COUNT_THRESHOLD
std::string COUNT_THRESHOLD
Definition:
smoothedNgramPredictor.h:62
SmoothedNgramPredictor::DATABASE_LOGGER
std::string DATABASE_LOGGER
Definition:
smoothedNgramPredictor.h:64
SmoothedNgramPredictor::predict
virtual Prediction predict(const size_t size, const char **filter) const
Generate prediction.
Definition:
smoothedNgramPredictor.cpp:201
SmoothedNgramPredictor
Definition:
smoothedNgramPredictor.h:47
ContextTracker
Tracks user interaction and context.
Definition:
contextTracker.h:155
Observable
Definition:
observable.h:37
Ngram
Definition:
ngram.h:33
SmoothedNgramPredictor::set_dbfilename
void set_dbfilename(const std::string &filename)
Definition:
smoothedNgramPredictor.cpp:67
SmoothedNgramPredictor::LOGGER
std::string LOGGER
Definition:
smoothedNgramPredictor.h:59
Generated on Wed Nov 28 2018 12:12:14 for presage by
1.8.14