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 "defaultProfile.h"
26 
27 #include "dirs.h"
28 
29 #include <sstream>
30 
31 const char*        DefaultProfile::DEFAULT_PROFILE_FILENAME            = "presage.xml";
32 
DefaultProfile(const std::string & filename)33 DefaultProfile::DefaultProfile (const std::string& filename)
34   : Profile (filename)
35 {
36     build_xml_document (filename);
37 }
38 
~DefaultProfile()39 DefaultProfile::~DefaultProfile()
40 {
41     // complete
42 }
43 
build_xml_document(const std::string & filename)44 void DefaultProfile::build_xml_document (const std::string& filename)
45 {
46     const char* xml =
47 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>"
48 "<Presage>"
49 "    <PredictorRegistry>"
50 "        <LOGGER>ERROR</LOGGER>"
51 "        <!-- PREDICTORS"
52 "          Space separated list of predictors to use to generate predictions"
53 "        -->"
54 "        <PREDICTORS>DefaultAbbreviationExpansionPredictor DefaultSmoothedNgramPredictor UserSmoothedNgramPredictor DefaultRecencyPredictor</PREDICTORS>"
55 "    </PredictorRegistry>"
56 "    <ContextTracker>"
57 "        <LOGGER>ERROR</LOGGER>"
58 "        <!-- SLIDING_WINDOW_SIZE"
59 "          Size of buffer used by context tracker to detect context changes"
60 "        -->"
61 "        <SLIDING_WINDOW_SIZE>80</SLIDING_WINDOW_SIZE>"
62 "        <!-- LOWERCASE_MODE"
63 "          Instruct context tracker to track text as lowercase"
64 "        -->"
65 "         <LOWERCASE_MODE>yes</LOWERCASE_MODE>"
66 "    </ContextTracker>"
67 "    <Selector>"
68 "        <LOGGER>ERROR</LOGGER>"
69 "        <!-- SUGGESTIONS"
70 "          Controls how many suggestions are returned in each prediction."
71 "        -->"
72 "        <SUGGESTIONS>6</SUGGESTIONS>"
73 "        <!-- REPEAT_SUGGESTIONS"
74 "          Allow the same suggestion to be offered in subsequent"
75 "          predictions, even if no context change has been detected."
76 "        -->"
77 "        <REPEAT_SUGGESTIONS>no</REPEAT_SUGGESTIONS>"
78 "        <!-- GREEDY_SUGGESTION_THRESHOLD"
79 "          Select only tokens whose completion length is greater than"
80 "          the specified greedy suggestion threshold."
81 "          i.e. If this option is set to 2 and the current prefix is"
82 "               \"cu\", then the word \"cub\" will not offered as a"
83 "               suggestion, because the completion's length is only one"
84 "               character long. Tokens \"curb\" or \"cube\" or \"cubicle\" or"
85 "               \"cucumber\" will however be offered, because these"
86 "               words' completions are at least 2 characters long."
87 "        -->"
88 "        <GREEDY_SUGGESTION_THRESHOLD>0</GREEDY_SUGGESTION_THRESHOLD>"
89 "    </Selector>"
90 "    <PredictorActivator>"
91 "        <LOGGER>ERROR</LOGGER>"
92 "        <!-- PREDICT_TIME"
93 "          Maximum time allowed for predictors to return their prediction."
94 "        -->"
95 "        <PREDICT_TIME>1000</PREDICT_TIME>"
96 "        <!-- MAX_PARTIAL_PREDICTION_SIZE"
97 "          Desired size of each prediction prior to combination phase."
98 "        -->"
99 "        <MAX_PARTIAL_PREDICTION_SIZE>60</MAX_PARTIAL_PREDICTION_SIZE>"
100 "        <!-- COMBINATION_POLICY"
101 "          policy used by predictor to combine predictions returned"
102 "          by the active predictors into one prediction."
103 "        -->"
104 "        <COMBINATION_POLICY>Meritocracy</COMBINATION_POLICY>"
105 "    </PredictorActivator>"
106 "    <ProfileManager>"
107 "        <LOGGER>ERROR</LOGGER>"
108 "        <!-- AUTOPERSIST"
109 "             Automatically saves configuration to active profile."
110 "          -->"
111 "        <AUTOPERSIST>false</AUTOPERSIST>"
112 "    </ProfileManager>"
113 "    <Predictors>"
114 "        <DefaultSmoothedNgramPredictor>"
115 "            <PREDICTOR>SmoothedNgramPredictor</PREDICTOR>"
116 "            <LOGGER>ERROR</LOGGER>"
117 "            <DBFILENAME>" pkgdatadir "/database_en.db</DBFILENAME>"
118 "            <!-- $delta_0, $delta_1, ..., $delta_{n-1} -->"
119 "            <DELTAS>0.01 0.1 0.89</DELTAS>"
120 "            <LEARN>false</LEARN>"
121 "            <DatabaseConnector>"
122 "                <LOGGER>ERROR</LOGGER>"
123 "            </DatabaseConnector>"
124 "        </DefaultSmoothedNgramPredictor>"
125 "        <UserSmoothedNgramPredictor>"
126 "            <PREDICTOR>SmoothedNgramPredictor</PREDICTOR>"
127 "            <LOGGER>ERROR</LOGGER>"
128 "            <!-- ${HOME} is special. It expands to:"
129 "                  - $HOME on Unix"
130 "                  - %USERPROFILE% on Windows"
131 "              -->"
132 "            <DBFILENAME>${HOME}/.presage/lm.db</DBFILENAME>"
133 "            <!-- delta_0, delta_1, ..., delta_{n-1} -->"
134 "            <DELTAS>0.01 0.1 0.89</DELTAS>"
135 "            <LEARN>true</LEARN>"
136 "            <DatabaseConnector>"
137 "                <LOGGER>ERROR</LOGGER>"
138 "            </DatabaseConnector>"
139 "        </UserSmoothedNgramPredictor>"
140 "        <DefaultRecencyPredictor>"
141 "            <PREDICTOR>RecencyPredictor</PREDICTOR>"
142 "            <LOGGER>ERROR</LOGGER>"
143 "            <LAMBDA>1</LAMBDA>"
144 "            <N_0>1</N_0>"
145 "            <CUTOFF_THRESHOLD>20</CUTOFF_THRESHOLD>"
146 "        </DefaultRecencyPredictor>"
147 "        <DefaultDictionaryPredictor>"
148 "            <PREDICTOR>DictionaryPredictor</PREDICTOR>"
149 "            <DICTIONARY>/usr/share/dict/words</DICTIONARY>"
150 "            <!-- fixed probability assigned to prediction -->"
151 "            <PROBABILITY>0.000001</PROBABILITY>"
152 "        </DefaultDictionaryPredictor>"
153 "       <DefaultAbbreviationExpansionPredictor>"
154 "            <PREDICTOR>AbbreviationExpansionPredictor</PREDICTOR>"
155 "            <LOGGER>ERROR</LOGGER>"
156 "            <ABBREVIATIONS>" pkgdatadir "/abbreviations_en.txt</ABBREVIATIONS>"
157 "       </DefaultAbbreviationExpansionPredictor>"
158 "       <DefaultDejavuPredictor>"
159 "            <PREDICTOR>DejavuPredictor</PREDICTOR>"
160 "            <LOGGER>ERROR</LOGGER>"
161 "            <MEMORY>" pkgdatadir "/dejavu_memory_en.txt</MEMORY>"
162 "            <TRIGGER>3</TRIGGER>"
163 "       </DefaultDejavuPredictor>"
164 "        <DefaultARPAPredictor>"
165 "            <PREDICTOR>ARPAPredictor</PREDICTOR>"
166 "            <LOGGER>ERROR</LOGGER>"
167 "            <ARPAFILENAME>" pkgdatadir "/arpa_en.arpa</ARPAFILENAME>"
168 "            <VOCABFILENAME>" pkgdatadir "/arpa_en.vocab</VOCABFILENAME>"
169 "            <TIMEOUT>100</TIMEOUT>"
170 "        </DefaultARPAPredictor>"
171 "    </Predictors>"
172 "</Presage>";
173 
174   xmlProfileDoc->Parse (xml);
175 
176 }
177