presage  0.8.7
defaultProfile.cpp
Go to the documentation of this file.
00001 
00002 /******************************************************
00003  *  Presage, an extensible predictive text entry system
00004  *  ---------------------------------------------------
00005  *
00006  *  Copyright (C) 2008  Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License along
00019     with this program; if not, write to the Free Software Foundation, Inc.,
00020     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00021                                                                              *
00022                                                                 **********(*)*/
00023 
00024 
00025 #include "defaultProfile.h"
00026 
00027 #include "dirs.h"
00028 
00029 #include <sstream>
00030 
00031 const char*        DefaultProfile::DEFAULT_PROFILE_FILENAME            = "presage.xml";
00032 const std::string  DefaultProfile::DEFAULT_LOGGER_LEVEL                = "DEBUG";
00033 const int          DefaultProfile::DEFAULT_PREDICT_TIME                = 1000;
00034 const int          DefaultProfile::DEFAULT_MAX_PARTIAL_PREDICTION_SIZE = 100;
00035 const std::string  DefaultProfile::DEFAULT_COMBINATION_POLICY          = "Meritocracy";
00036 const int          DefaultProfile::DEFAULT_SLIDING_WINDOW_SIZE         = 80;
00037 const size_t       DefaultProfile::DEFAULT_SUGGESTIONS                 = 6;
00038 const bool         DefaultProfile::DEFAULT_REPEAT_SUGGESTION           = false;
00039 const size_t       DefaultProfile::DEFAULT_GREEDY_SUGGESTION_THRESHOLD = 0;
00040 const std::string  DefaultProfile::DEFAULT_PREDICTORS                  = "RecencyPredictor";
00041 const char*        DefaultProfile::DEFAULT_AUTOPERSIST                 = "false";
00042 
00043 DefaultProfile::DefaultProfile (const std::string& filename)
00044   : Profile (filename)
00045 {
00046     build_xml_document (filename);
00047 }
00048 
00049 DefaultProfile::~DefaultProfile()
00050 {
00051     // complete
00052 }
00053 
00054 void DefaultProfile::build_xml_document (const std::string& filename)
00055 {
00056     const char* xml =
00057 "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\" ?>"
00058 "<Presage>"
00059 "    <PredictorRegistry>"
00060 "        <LOGGER>ERROR</LOGGER>"
00061 "        <!-- PREDICTORS"
00062 "          Space separated list of predictors to use to generate predictions"
00063 "        -->"
00064 "        <PREDICTORS>AbbreviationExpansionPredictor SmoothedNgramPredictor RecencyPredictor</PREDICTORS>"
00065 "    </PredictorRegistry>"
00066 "    <ContextTracker>"
00067 "       <LOGGER>ERROR</LOGGER>"
00068 "        <!-- SLIDING_WINDOW_SIZE"
00069 "          Size of buffer used by context tracker to detect context changes"
00070 "        -->"
00071 "        <SLIDING_WINDOW_SIZE>80</SLIDING_WINDOW_SIZE>"
00072 "    </ContextTracker>"
00073 "    <Selector>"
00074 "       <LOGGER>ERROR</LOGGER>"
00075 "        <!-- SUGGESTIONS"
00076 "          Controls how many suggestions are returned in each prediction."
00077 "        -->"
00078 "        <SUGGESTIONS>6</SUGGESTIONS>"
00079 "        <!-- REPEAT_SUGGESTIONS"
00080 "          Allow the same suggestion to be offered in subsequent"
00081 "         predictions, even if no context change has been detected."
00082 "        -->"
00083 "        <REPEAT_SUGGESTIONS>no</REPEAT_SUGGESTIONS>"
00084 "       <!-- GREEDY_SUGGESTION_THRESHOLD"
00085 "         Select only tokens whose completion length is greater than"
00086 "          the specified greedy suggestion threshold."
00087 "         i.e. If this option is set to 2 and the current prefix is"
00088 "               \"cu\", then the word \"cub\" will not offered as a"
00089 "               suggestion, because the completion's length is only one"
00090 "               character long. Tokens \"curb\" or \"cube\" or \"cubicle\" or"
00091 "               \"cucumber\" will however be offered, because these"
00092 "               words' completions are at least 2 characters long."
00093 "       -->"
00094 "        <GREEDY_SUGGESTION_THRESHOLD>0</GREEDY_SUGGESTION_THRESHOLD>"
00095 "    </Selector>"
00096 "    <PredictorActivator>"
00097 "        <LOGGER>ERROR</LOGGER>"
00098 "        <!-- PREDICT_TIME"
00099 "          Maximum time allowed for predictors to return their prediction."
00100 "       -->"
00101 "        <PREDICT_TIME>1000</PREDICT_TIME>"
00102 "        <!-- MAX_PARTIAL_PREDICTION_SIZE"
00103 "          Desired size of each prediction prior to combination phase."
00104 "        -->"
00105 "        <MAX_PARTIAL_PREDICTION_SIZE>60</MAX_PARTIAL_PREDICTION_SIZE>"
00106 "       <!-- COMBINATION_POLICY"
00107 "         policy used by predictor to combine predictions returned"
00108 "         by the active predictors into one prediction."
00109 "        -->"
00110 "        <COMBINATION_POLICY>Meritocracy</COMBINATION_POLICY>"
00111 "    </PredictorActivator>"
00112 "    <ProfileManager>"
00113 "        <LOGGER>ERROR</LOGGER>"
00114 "        <!-- AUTOPERSIST"
00115 "            Automatically saves configuration to active profile."
00116 "         -->"
00117 "       <AUTOPERSIST>false</AUTOPERSIST>"
00118 "    </ProfileManager>"
00119 "    <Predictors>"
00120 "        <SmoothedNgramPredictor>"
00121 "            <LOGGER>ERROR</LOGGER>"
00122 "            <DBFILENAME>" pkgdatadir "/database_en.db</DBFILENAME>"
00123 "            <!-- $delta_0, $delta_1, ..., $delta_{n-1} -->"
00124 "            <DELTAS>0.01 0.1 0.89</DELTAS>"
00125 "            <LEARN>false</LEARN>"
00126 "            <DatabaseConnector>"
00127 "                <LOGGER>ERROR</LOGGER>"
00128 "            </DatabaseConnector>"
00129 "        </SmoothedNgramPredictor>"
00130 "       <RecencyPredictor>"
00131 "            <LOGGER>ERROR</LOGGER>"
00132 "            <LAMBDA>1</LAMBDA>"
00133 "            <N_0>1</N_0>"
00134 "            <CUTOFF_THRESHOLD>20</CUTOFF_THRESHOLD>"
00135 "       </RecencyPredictor>"
00136 "       <DictionaryPredictor>"
00137 "           <DICTIONARY>/usr/share/dict/words</DICTIONARY>"
00138 "            <!-- fixed probability assigned to prediction -->"
00139 "            <PROBABILITY>0.000001</PROBABILITY>"
00140 "       </DictionaryPredictor>"
00141 "        <AbbreviationExpansionPredictor>"
00142 "            <LOGGER>ERROR</LOGGER>"
00143 "            <ABBREVIATIONS>" pkgdatadir "/abbreviations_en.txt</ABBREVIATIONS>"
00144 "        </AbbreviationExpansionPredictor>"
00145 "        <DejavuPredictor>"
00146 "            <LOGGER>ERROR</LOGGER>"
00147 "            <MEMORY>" pkgdatadir "/dejavu_memory_en.txt</MEMORY>"
00148 "            <TRIGGER>3</TRIGGER>"
00149 "        </DejavuPredictor>"
00150 "       <ARPAPredictor>"
00151 "         <LOGGER>ERROR</LOGGER>"
00152 "         <ARPAFILENAME>" pkgdatadir "/arpa_en.arpa</ARPAFILENAME>"
00153 "         <VOCABFILENAME>" pkgdatadir "/arpa_en.vocab</VOCABFILENAME>"
00154 "         <TIMEOUT>100</TIMEOUT>"
00155 "       </ARPAPredictor>"
00156 "    </Predictors>"
00157 "</Presage>";
00158 
00159   xmlProfileDoc->Parse (xml);
00160 
00161 }