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_PREDICTION
26 #define PRESAGE_PREDICTION
27 
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31 
32 #include <vector>
33 
34 #include "suggestion.h"
35 
36 
37 /** Prediction
38  *
39  * A prediction contains a set of Suggestion objects.  More precisely,
40  * a Prediction is a list of Suggestion object, ordered by decreasing
41  * probability.
42  *
43  * A Prediction object is returned by the predictors and by a combiner
44  * object.
45  *
46  */
47 class Prediction {
48     friend std::ostream &operator<<( std::ostream &, const Prediction & );
49 
50 public:
51     Prediction();
52     ~Prediction();
53 
54     const Prediction &operator=( const Prediction & );
55 
56     /** Predictions are equal iff suggestions are equal and in same order.
57      */
58     bool operator== (const Prediction&) const;
59 
60     /** Returns number of suggestions in prediction.
61      */
62     size_t size() const;
63 
64     /** Returns nth most probable suggestion.
65      */
66     Suggestion getSuggestion(int=0) const;
67 
68     /** Returns suggestion with given token.
69      */
70     Suggestion getSuggestion(std::string token) const;
71 
72     /** Inserts a new suggestion, preserves the ordering.
73      *
74      * The suggestion object to be inserted is compared against the
75      * suggestions already contained in the prediction and inserted in an
76      * ordered fashion.
77      *
78      * Comparison between suggestion objects uses the overloaded operator<
79      *
80      */
81     void addSuggestion( Suggestion );
82 
83     /** Returns a string representation of the prediction.
84      */
85     std::string toString() const;
86 private:
87     std::vector<Suggestion> suggestions;
88 
89 };
90 
91 
92 #endif // PRESAGE_PREDICTION
93