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.
25
#include "prediction.h"
28
Prediction::Prediction()
31
Prediction::~Prediction()
34
const Prediction &Prediction::operator=( const Prediction &right )
36
if( &right != this ) {
37
suggestions = right.suggestions;
39
//assert( ( suggestions == right.suggestions ) );
45
bool Prediction::operator== (const Prediction& right) const
47
// same instance is obviously equal to itself
51
if (size() != right.size()) {
54
// need to compare each suggestion
57
while (i < size() && result) {
58
if (getSuggestion(i) != right.getSuggestion(i)) {
68
size_t Prediction::size() const
70
return suggestions.size();
73
Suggestion Prediction::getSuggestion(int i) const
75
assert( i >= 0 && static_cast<unsigned int>(i) < suggestions.size() );
77
return suggestions[i];
80
Suggestion Prediction::getSuggestion(std::string token) const
82
for (size_t i = 0; i < suggestions.size(); i++) {
83
if (suggestions[i].getWord() == token) {
84
return suggestions[i];
90
void Prediction::addSuggestion(Suggestion s)
92
// insert s so that suggestions vector is sorted
94
// handle empty vector first
95
if( suggestions.empty() ) {
96
suggestions.push_back( s );
98
std::vector< Suggestion >::iterator i = suggestions.begin();
99
while( i != suggestions.end() && s < *i ) {
102
suggestions.insert( i, s );
106
std::string Prediction::toString() const
109
std::vector<Suggestion>::const_iterator i;
110
for( i=suggestions.begin(); i!=suggestions.end(); i++ ) {
111
str += i->toString();
116
std::ostream &operator<<( std::ostream &output, const Prediction &p )
118
std::vector<Suggestion>::const_iterator i;
119
for( i=p.suggestions.begin(); i!=p.suggestions.end(); i++ ) {
120
output << *i << std::endl;