xapian-core  2.0.0
stem.h
Go to the documentation of this file.
1 
4 /* Copyright (C) 2005-2026 Olly Betts
5  * Copyright (C) 2010 Evgeny Sizikov
6  *
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.
11  *
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.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, see
19  * <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef XAPIAN_INCLUDED_STEM_H
23 #define XAPIAN_INCLUDED_STEM_H
24 
25 #if !defined XAPIAN_IN_XAPIAN_H && !defined XAPIAN_LIB_BUILD
26 # error Never use <xapian/stem.h> directly; include <xapian.h> instead.
27 #endif
28 
29 #include <xapian/constinfo.h>
30 #include <xapian/intrusive_ptr.h>
31 #include <xapian/visibility.h>
32 
33 #include <string>
34 #include <string_view>
35 
36 namespace Xapian {
37 
41 {
43  void operator=(const StemImplementation &) = delete;
44 
47 
48  public:
51 
53  virtual ~StemImplementation();
54 
56  virtual std::string operator()(const std::string & word) = 0;
57 
67  virtual bool use_proper_noun_heuristic() const;
68 
70  virtual std::string get_description() const = 0;
71 };
72 
75  public:
78 
80  Stem(const Stem& o) : internal(o.internal) { }
81 
83  Stem& operator=(const Stem& o) {
84  internal = o.internal;
85  return *this;
86  }
87 
89  Stem(Stem&&) = default;
90 
92  Stem& operator=(Stem&&) = default;
93 
98  Stem() { }
99 
164  Stem(std::string_view language, bool fallback = false);
165 
177  explicit Stem(StemImplementation* p) : internal(p) { }
178 
180  ~Stem() { }
181 
187  std::string operator()(const std::string& word) const {
188  if (!internal || word.empty()) return word;
189  return internal->operator()(word);
190  }
191 
193  bool is_none() const { return !internal; }
194 
196  std::string get_description() const;
197 
208  static std::string get_available_languages() {
209  const struct Xapian::Internal::constinfo * info =
211  return std::string(info->stemmer_data, info->stemmer_name_len);
212  }
213 };
214 
215 }
216 
217 #endif // XAPIAN_INCLUDED_STEM_H
Base class for objects managed by intrusive_ptr.
Definition: intrusive_ptr.h:50
A smart pointer that uses intrusive reference counting.
Definition: intrusive_ptr.h:83
Class representing a stemming algorithm implementation.
Definition: stem.h:41
StemImplementation(const StemImplementation &)=delete
Don't allow copying.
StemImplementation()
Default constructor.
Definition: stem.h:50
virtual std::string get_description() const =0
Return a string describing this object.
void operator=(const StemImplementation &)=delete
Don't allow assignment.
virtual std::string operator()(const std::string &word)=0
Stem the specified word.
Class representing a stemming algorithm.
Definition: stem.h:74
Stem()
Construct a Xapian::Stem object which doesn't change terms.
Definition: stem.h:98
static std::string get_available_languages()
Return a list of available languages.
Definition: stem.h:208
Stem & operator=(Stem &&)=default
Move assignment operator.
Xapian::Internal::intrusive_ptr< StemImplementation > internal
Definition: stem.h:77
Stem(const Stem &o)
Copy constructor.
Definition: stem.h:80
bool is_none() const
Return true if this is a no-op stemmer.
Definition: stem.h:193
Stem(Stem &&)=default
Move constructor.
Stem(StemImplementation *p)
Construct a Xapian::Stem object with a user-provided stemming algorithm.
Definition: stem.h:177
~Stem()
Destructor.
Definition: stem.h:180
Stem & operator=(const Stem &o)
Assignment.
Definition: stem.h:83
std::string operator()(const std::string &word) const
Stem a word.
Definition: stem.h:187
Mechanism for accessing a struct of constant information.
PositionList * p
const struct constinfo * get_constinfo_() noexcept
Definition: constinfo.cc:43
The Xapian namespace contains public interfaces for the Xapian library.
Definition: compactor.cc:82
static string language
Definition: stemtest.cc:40
Define XAPIAN_VISIBILITY_* macros.
#define XAPIAN_VISIBILITY_DEFAULT
Definition: visibility.h:28