presage
0.8.8
Main Page
Classes
Files
File List
File Members
src
lib
core
combiner.cpp
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
#include "
combiner.h
"
26
#include "
profile.h
"
27
28
#include <set>
29
30
Combiner::Combiner
()
31
{
32
// intentionally empty
33
}
34
35
Combiner::~Combiner
()
36
{
37
// intentionally empty
38
}
39
55
Prediction
Combiner::filter
(
const
Prediction
& prediction)
const
56
{
57
Prediction
result;
58
59
std::set<std::string> seen_tokens;
60
61
size_t
size = prediction.
size
();
62
Suggestion
suggestion;
63
std::string token;
64
for
(
size_t
i = 0; i < size; i++)
65
{
66
suggestion = prediction.
getSuggestion
(i);
67
token = suggestion.
getWord
();
68
//std::cerr << "[filter] token: " << token << std::endl;
69
if
(seen_tokens.find(token) == seen_tokens.end())
70
{
71
// if token has not been seen before, then look for
72
// potential duplicates and incrementally add the
73
// interpolated combined probability and remember that
74
// this token has now been processed
75
//
76
77
//std::cerr << "[filter] searching for possible duplicates" << std::endl;
78
for
(
int
j = i + 1; j < size; j++)
79
{
80
if
(token == prediction.
getSuggestion
(j).
getWord
())
81
{
82
// duplicate of token found, increment probability, up to MAX_PROBABILITY
83
suggestion.
setProbability
(
84
( (suggestion.
getProbability
() + prediction.
getSuggestion
(j).
getProbability
()) >
Suggestion::MAX_PROBABILITY
85
?
Suggestion::MAX_PROBABILITY
86
: (suggestion.
getProbability
() + prediction.
getSuggestion
(j).
getProbability
()))
87
);
88
//std::cerr << "[filter] duplicate found, adjusting probability" << std::endl;
89
}
90
}
91
seen_tokens.insert(token);
92
result.
addSuggestion
(suggestion);
93
//std::cerr << "[filter] added token " << token << std::endl;
94
}
95
}
96
97
return
result;
98
}
Generated on Thu Nov 7 2013 14:39:06 for presage by
1.8.4