2 * @brief Implementation of Xapian::Stem API class.
4 /* Copyright (C) 2007,2008,2010,2011,2012,2015,2018,2019 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
24 #include <xapian/stem.h>
26 #include <xapian/error.h>
28 #include "steminternal.h"
30 #include "allsnowballheaders.h"
32 #include "sbl-dispatch.h"
40 Stem::Stem(const Stem
& o
) : internal(o
.internal
) { }
43 Stem::operator=(const Stem
& o
)
45 internal
= o
.internal
;
49 Stem::Stem(Stem
&&) = default;
52 Stem::operator=(Stem
&&) = default;
56 static StemImplementation
*
57 stem_internal_factory(const std::string
& language
, bool fallback
)
59 int l
= keyword2(tab
, language
.data(), language
.size());
61 switch (static_cast<sbl_code
>(l
)) {
63 return new InternalStemArabic
;
65 return new InternalStemArmenian
;
67 return new InternalStemBasque
;
69 return new InternalStemCatalan
;
71 return new InternalStemDanish
;
73 return new InternalStemDutch
;
75 return new InternalStemEarlyenglish
;
77 return new InternalStemEnglish
;
79 return new InternalStemFinnish
;
81 return new InternalStemFrench
;
83 return new InternalStemGerman
;
85 return new InternalStemGerman2
;
87 return new InternalStemHungarian
;
89 return new InternalStemIndonesian
;
91 return new InternalStemIrish
;
93 return new InternalStemItalian
;
95 return new InternalStemKraaij_pohlmann
;
97 return new InternalStemLithuanian
;
99 return new InternalStemLovins
;
101 return new InternalStemNepali
;
103 return new InternalStemNorwegian
;
107 return new InternalStemPortuguese
;
109 return new InternalStemPorter
;
111 return new InternalStemRussian
;
113 return new InternalStemRomanian
;
115 return new InternalStemSpanish
;
117 return new InternalStemSwedish
;
119 return new InternalStemTamil
;
121 return new InternalStemTurkish
;
124 if (fallback
|| language
.empty())
126 throw Xapian::InvalidArgumentError("Language code " + language
+ " unknown");
129 Stem::Stem(const std::string
& language
)
130 : internal(stem_internal_factory(language
, false)) { }
132 Stem::Stem(const std::string
& language
, bool fallback
)
133 : internal(stem_internal_factory(language
, fallback
)) { }
135 Stem::Stem(StemImplementation
* p
) : internal(p
) { }
140 Stem::operator()(const std::string
&word
) const
142 if (!internal
.get() || word
.empty()) return word
;
143 return internal
->operator()(word
);
147 Stem::get_description() const
149 string desc
= "Xapian::Stem(";
150 if (internal
.get()) {
151 desc
+= internal
->get_description();