Website now in git not CVS
[xapian.git] / xapian-core / languages / stem.cc
bloba2935f264a349eeba6ac5054f3fa921f9cfe8636
1 /** @file stem.cc
2 * @brief Implementation of Xapian::Stem API class.
3 */
4 /* Copyright (C) 2007,2008,2010,2011,2012,2015 Olly Betts
5 * Copyright (C) 2010 Evgeny Sizikov
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <config.h>
24 #include <xapian/stem.h>
26 #include <xapian/error.h>
28 #include "steminternal.h"
30 #include "keyword.h"
31 #include "sbl-dispatch.h"
33 #include <string>
35 using namespace std;
37 namespace Xapian {
39 Stem::Stem(const Stem & o) : internal(o.internal) { }
41 Stem &
42 Stem::operator=(const Stem & o)
44 internal = o.internal;
45 return *this;
48 Stem::Stem() : internal(0) { }
50 Stem::Stem(const std::string &language) : internal(0) {
51 int l = keyword(tab, language.data(), language.size());
52 if (l >= 0) {
53 switch (static_cast<sbl_code>(l)) {
54 case ARABIC:
55 internal = new InternalStemArabic;
56 return;
57 case ARMENIAN:
58 internal = new InternalStemArmenian;
59 return;
60 case BASQUE:
61 internal = new InternalStemBasque;
62 return;
63 case CATALAN:
64 internal = new InternalStemCatalan;
65 return;
66 case DANISH:
67 internal = new InternalStemDanish;
68 return;
69 case DUTCH:
70 internal = new InternalStemDutch;
71 return;
72 case EARLYENGLISH:
73 internal = new InternalStemEarlyenglish;
74 return;
75 case ENGLISH:
76 internal = new InternalStemEnglish;
77 return;
78 case FINNISH:
79 internal = new InternalStemFinnish;
80 return;
81 case FRENCH:
82 internal = new InternalStemFrench;
83 return;
84 case GERMAN:
85 internal = new InternalStemGerman;
86 return;
87 case GERMAN2:
88 internal = new InternalStemGerman2;
89 return;
90 case HUNGARIAN:
91 internal = new InternalStemHungarian;
92 return;
93 case ITALIAN:
94 internal = new InternalStemItalian;
95 return;
96 case KRAAIJ_POHLMANN:
97 internal = new InternalStemKraaij_pohlmann;
98 return;
99 case LOVINS:
100 internal = new InternalStemLovins;
101 return;
102 case NORWEGIAN:
103 internal = new InternalStemNorwegian;
104 return;
105 case NONE:
106 return;
107 case PORTUGUESE:
108 internal = new InternalStemPortuguese;
109 return;
110 case PORTER:
111 internal = new InternalStemPorter;
112 return;
113 case RUSSIAN:
114 internal = new InternalStemRussian;
115 return;
116 case ROMANIAN:
117 internal = new InternalStemRomanian;
118 return;
119 case SPANISH:
120 internal = new InternalStemSpanish;
121 return;
122 case SWEDISH:
123 internal = new InternalStemSwedish;
124 return;
125 case TURKISH:
126 internal = new InternalStemTurkish;
127 return;
130 if (language.empty())
131 return;
132 throw Xapian::InvalidArgumentError("Language code " + language + " unknown");
135 Stem::Stem(StemImplementation * p) : internal(p) { }
137 Stem::~Stem() { }
139 string
140 Stem::operator()(const std::string &word) const
142 if (!internal.get() || word.empty()) return word;
143 return internal->operator()(word);
146 string
147 Stem::get_description() const
149 string desc = "Xapian::Stem(";
150 if (internal.get()) {
151 desc += internal->get_description();
152 desc += ')';
153 } else {
154 desc += "none)";
156 return desc;