Document xapian-compact --blocksize takes an argument
[xapian.git] / xapian-core / languages / stem.cc
blob1cd9720a1f214ee59dc9a6bf5a9a568ca954cbb1
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 ARMENIAN:
55 internal = new InternalStemArmenian;
56 return;
57 case BASQUE:
58 internal = new InternalStemBasque;
59 return;
60 case CATALAN:
61 internal = new InternalStemCatalan;
62 return;
63 case DANISH:
64 internal = new InternalStemDanish;
65 return;
66 case DUTCH:
67 internal = new InternalStemDutch;
68 return;
69 case EARLYENGLISH:
70 internal = new InternalStemEarlyenglish;
71 return;
72 case ENGLISH:
73 internal = new InternalStemEnglish;
74 return;
75 case FINNISH:
76 internal = new InternalStemFinnish;
77 return;
78 case FRENCH:
79 internal = new InternalStemFrench;
80 return;
81 case GERMAN:
82 internal = new InternalStemGerman;
83 return;
84 case GERMAN2:
85 internal = new InternalStemGerman2;
86 return;
87 case HUNGARIAN:
88 internal = new InternalStemHungarian;
89 return;
90 case ITALIAN:
91 internal = new InternalStemItalian;
92 return;
93 case KRAAIJ_POHLMANN:
94 internal = new InternalStemKraaij_pohlmann;
95 return;
96 case LOVINS:
97 internal = new InternalStemLovins;
98 return;
99 case NORWEGIAN:
100 internal = new InternalStemNorwegian;
101 return;
102 case NONE:
103 return;
104 case PORTUGUESE:
105 internal = new InternalStemPortuguese;
106 return;
107 case PORTER:
108 internal = new InternalStemPorter;
109 return;
110 case RUSSIAN:
111 internal = new InternalStemRussian;
112 return;
113 case ROMANIAN:
114 internal = new InternalStemRomanian;
115 return;
116 case SPANISH:
117 internal = new InternalStemSpanish;
118 return;
119 case SWEDISH:
120 internal = new InternalStemSwedish;
121 return;
122 case TURKISH:
123 internal = new InternalStemTurkish;
124 return;
127 if (language.empty())
128 return;
129 throw Xapian::InvalidArgumentError("Language code " + language + " unknown");
132 Stem::Stem(StemImplementation * p) : internal(p) { }
134 Stem::~Stem() { }
136 string
137 Stem::operator()(const std::string &word) const
139 if (!internal.get() || word.empty()) return word;
140 return internal->operator()(word);
143 string
144 Stem::get_description() const
146 string desc = "Xapian::Stem(";
147 if (internal.get()) {
148 desc += internal->get_description();
149 desc += ')';
150 } else {
151 desc += "none)";
153 return desc;