00001
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include <xapian/error.h>
00024 #include <xapian/stem.h>
00025
00026 #include "steminternal.h"
00027
00028 #include "allsnowballheaders.h"
00029
00030 #include <string>
00031
00032 using namespace std;
00033
00034 namespace Xapian {
00035
00036 Stem::Stem(const Stem & o) : internal(o.internal) { }
00037
00038 void
00039 Stem::operator=(const Stem & o)
00040 {
00041 internal = o.internal;
00042 }
00043
00044 Stem::Stem() : internal(0) { }
00045
00046 Stem::Stem(const std::string &language) : internal(0) {
00047 if (language.empty()) return;
00048 switch (language[0]) {
00049 case 'd':
00050 if (language == "da" || language == "danish") {
00051 internal = new InternalStemDanish;
00052 return;
00053 }
00054 if (language == "dutch") {
00055 internal = new InternalStemDutch;
00056 return;
00057 }
00058 if (language == "de") {
00059 internal = new InternalStemGerman;
00060 return;
00061 }
00062 break;
00063 case 'e':
00064 if (language == "en" || language == "english") {
00065 internal = new InternalStemEnglish;
00066 return;
00067 }
00068 if (language == "es") {
00069 internal = new InternalStemSpanish;
00070 return;
00071 }
00072 break;
00073 case 'f':
00074 if (language == "fi" || language == "finnish") {
00075 internal = new InternalStemFinnish;
00076 return;
00077 }
00078 if (language == "fr" || language == "french") {
00079 internal = new InternalStemFrench;
00080 return;
00081 }
00082 break;
00083 case 'g':
00084 if (language == "german") {
00085 internal = new InternalStemGerman;
00086 return;
00087 }
00088 if (language == "german2") {
00089 internal = new InternalStemGerman2;
00090 return;
00091 }
00092 break;
00093 case 'h':
00094 if (language == "hu" || language == "hungarian") {
00095 internal = new InternalStemHungarian;
00096 return;
00097 }
00098 break;
00099 case 'i':
00100 if (language == "it" || language == "italian") {
00101 internal = new InternalStemItalian;
00102 return;
00103 }
00104 break;
00105 case 'k':
00106 if (language == "kraaij_pohlmann") {
00107 internal = new InternalStemKraaij_pohlmann;
00108 return;
00109 }
00110 break;
00111 case 'l':
00112 if (language == "lovins") {
00113 internal = new InternalStemLovins;
00114 return;
00115 }
00116 break;
00117 case 'n':
00118 if (language == "nl") {
00119 internal = new InternalStemDutch;
00120 return;
00121 }
00122 if (language == "no" || language == "norwegian") {
00123 internal = new InternalStemNorwegian;
00124 return;
00125 }
00126 if (language == "none") {
00127 return;
00128 }
00129 break;
00130 case 'p':
00131 if (language == "pt" || language == "portuguese") {
00132 internal = new InternalStemPortuguese;
00133 return;
00134 }
00135 if (language == "porter") {
00136 internal = new InternalStemPorter;
00137 return;
00138 }
00139 break;
00140 case 'r':
00141 if (language == "ru" || language == "russian") {
00142 internal = new InternalStemRussian;
00143 return;
00144 }
00145 if (language == "ro" || language == "romanian") {
00146 internal = new InternalStemRomanian;
00147 return;
00148 }
00149 break;
00150 case 's':
00151 if (language == "spanish") {
00152 internal = new InternalStemSpanish;
00153 return;
00154 }
00155 if (language == "sv" || language == "swedish") {
00156 internal = new InternalStemSwedish;
00157 return;
00158 }
00159 break;
00160 case 't':
00161 if (language == "tr" || language == "turkish") {
00162 internal = new InternalStemTurkish;
00163 return;
00164 }
00165 break;
00166 }
00167 throw Xapian::InvalidArgumentError("Language code " + language + " unknown");
00168 }
00169
00170 Stem::~Stem() { }
00171
00172 string
00173 Stem::operator()(const std::string &word) const
00174 {
00175 if (!internal.get() || word.empty()) return word;
00176 return internal->operator()(word);
00177 }
00178
00179 string
00180 Stem::get_description() const
00181 {
00182 string desc = "Xapian::Stem(";
00183 if (internal.get()) {
00184 desc += internal->get_description();
00185 desc += ')';
00186 } else {
00187 desc += "none)";
00188 }
00189 return desc;
00190 }
00191
00192 string
00193 Stem::get_available_languages()
00194 {
00195 return LANGSTRING;
00196 }
00197
00198 }