LCOV - code coverage report
Current view: top level - include/xapian - stem.h (source / functions) Hit Total Coverage
Test: Test Coverage for xapian-core 954b5873a738 Lines: 5 5 100.0 %
Date: 2019-06-30 05:20:33 Functions: 4 4 100.0 %
Branches: 1 2 50.0 %

           Branch data     Line data    Source code
       1                 :            : /** @file stem.h
       2                 :            :  * @brief stemming algorithms
       3                 :            :  */
       4                 :            : /* Copyright (C) 2005,2007,2010,2011,2013,2014,2015,2018 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, write to the Free Software
      19                 :            :  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
      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                 :            : 
      35                 :            : namespace Xapian {
      36                 :            : 
      37                 :            : /// Class representing a stemming algorithm implementation.
      38                 :            : class XAPIAN_VISIBILITY_DEFAULT StemImplementation
      39                 :            :     : public Xapian::Internal::intrusive_base
      40                 :            : {
      41                 :            :     /// Don't allow assignment.
      42                 :            :     void operator=(const StemImplementation &) = delete;
      43                 :            : 
      44                 :            :     /// Don't allow copying.
      45                 :            :     StemImplementation(const StemImplementation &) = delete;
      46                 :            : 
      47                 :            :   public:
      48                 :            :     /// Default constructor.
      49                 :       3408 :     StemImplementation() { }
      50                 :            : 
      51                 :            :     /// Virtual destructor.
      52                 :            :     virtual ~StemImplementation();
      53                 :            : 
      54                 :            :     /// Stem the specified word.
      55                 :            :     virtual std::string operator()(const std::string & word) = 0;
      56                 :            : 
      57                 :            :     /// Return a string describing this object.
      58                 :            :     virtual std::string get_description() const = 0;
      59                 :            : };
      60                 :            : 
      61                 :            : /// Class representing a stemming algorithm.
      62                 :         62 : class XAPIAN_VISIBILITY_DEFAULT Stem {
      63                 :            :   public:
      64                 :            :     /// @private @internal Reference counted internals.
      65                 :            :     Xapian::Internal::intrusive_ptr<StemImplementation> internal;
      66                 :            : 
      67                 :            :     /// Copy constructor.
      68                 :            :     Stem(const Stem & o);
      69                 :            : 
      70                 :            :     /// Assignment.
      71                 :            :     Stem & operator=(const Stem & o);
      72                 :            : 
      73                 :            :     /// Move constructor.
      74                 :            :     Stem(Stem && o);
      75                 :            : 
      76                 :            :     /// Move assignment operator.
      77                 :            :     Stem & operator=(Stem && o);
      78                 :            : 
      79                 :            :     /** Construct a Xapian::Stem object which doesn't change terms.
      80                 :            :      *
      81                 :            :      *  Equivalent to Stem("none").
      82                 :            :      */
      83                 :            :     Stem();
      84                 :            : 
      85                 :            :     /** Construct a Xapian::Stem object for a particular language.
      86                 :            :      *
      87                 :            :      *  @param language Either the English name for the language
      88                 :            :      *                  or the two letter ISO639 code.
      89                 :            :      *
      90                 :            :      *  The following language names are understood (aliases follow the
      91                 :            :      *  name):
      92                 :            :      *
      93                 :            :      *  - none - don't stem terms
      94                 :            :      *  - arabic (ar) - Since Xapian 1.3.5
      95                 :            :      *  - armenian (hy) - Since Xapian 1.3.0
      96                 :            :      *  - basque (eu) - Since Xapian 1.3.0
      97                 :            :      *  - catalan (ca) - Since Xapian 1.3.0
      98                 :            :      *  - danish (da)
      99                 :            :      *  - dutch (nl)
     100                 :            :      *  - english (en) - Martin Porter's 2002 revision of his stemmer
     101                 :            :      *  - earlyenglish - Early English (e.g. Shakespeare, Dickens) stemmer
     102                 :            :      *    (since Xapian 1.3.2)
     103                 :            :      *  - english_lovins (lovins) - Lovin's stemmer
     104                 :            :      *  - english_porter (porter) - Porter's stemmer as described in
     105                 :            :      *                  his 1980 paper
     106                 :            :      *  - finnish (fi)
     107                 :            :      *  - french (fr)
     108                 :            :      *  - german (de)
     109                 :            :      *  - german2 - Normalises umlauts and &szlig;
     110                 :            :      *  - hungarian (hu)
     111                 :            :      *  - indonesian (id) - Since Xapian 1.4.6
     112                 :            :      *  - irish (ga) - Since Xapian 1.4.7
     113                 :            :      *  - italian (it)
     114                 :            :      *  - kraaij_pohlmann - A different Dutch stemmer
     115                 :            :      *  - lithuanian (lt) - Since Xapian 1.4.7
     116                 :            :      *  - nepali (ne) - Since Xapian 1.4.7
     117                 :            :      *  - norwegian (nb, nn, no)
     118                 :            :      *  - portuguese (pt)
     119                 :            :      *  - romanian (ro)
     120                 :            :      *  - russian (ru)
     121                 :            :      *  - spanish (es)
     122                 :            :      *  - swedish (sv)
     123                 :            :      *  - tamil (ta) - Since Xapian 1.4.7
     124                 :            :      *  - turkish (tr)
     125                 :            :      *
     126                 :            :      *  @exception      Xapian::InvalidArgumentError is thrown if
     127                 :            :      *                  language isn't recognised.
     128                 :            :      */
     129                 :            :     explicit Stem(const std::string &language);
     130                 :            : 
     131                 :            :     /** Construct a Xapian::Stem object with a user-provided stemming algorithm.
     132                 :            :      *
     133                 :            :      *  You can subclass Xapian::StemImplementation to implement your own
     134                 :            :      *  stemming algorithm (or to wrap a third-party algorithm) and then wrap
     135                 :            :      *  your implementation in a Xapian::Stem object to pass to the Xapian API.
     136                 :            :      *
     137                 :            :      *  @param p        The user-subclassed StemImplementation object.  This
     138                 :            :      *                  is reference counted, and so will be automatically
     139                 :            :      *                  deleted by the Xapian::Stem wrapper when no longer
     140                 :            :      *                  required.
     141                 :            :      */
     142                 :            :     explicit Stem(StemImplementation * p);
     143                 :            : 
     144                 :            :     /// Destructor.
     145                 :            :     ~Stem();
     146                 :            : 
     147                 :            :     /** Stem a word.
     148                 :            :      *
     149                 :            :      *  @param word             a word to stem.
     150                 :            :      *  @return         the stem
     151                 :            :      */
     152                 :            :     std::string operator()(const std::string &word) const;
     153                 :            : 
     154                 :            :     /// Return a string describing this object.
     155                 :            :     std::string get_description() const;
     156                 :            : 
     157                 :            :     /** Return a list of available languages.
     158                 :            :      *
     159                 :            :      *  Each stemmer is only included once in the list (not once for
     160                 :            :      *  each alias).  The name included is the English name of the
     161                 :            :      *  language.
     162                 :            :      *
     163                 :            :      *  The list is returned as a string, with language names separated by
     164                 :            :      *  spaces.  This is a static method, so a Xapian::Stem object is not
     165                 :            :      *  required for this operation.
     166                 :            :      */
     167                 :          2 :     static std::string get_available_languages() {
     168                 :            :         const struct Xapian::Internal::constinfo * info =
     169                 :          2 :             Xapian::Internal::get_constinfo_();
     170         [ +  - ]:          2 :         return std::string(info->stemmer_data, info->stemmer_name_len);
     171                 :            :     }
     172                 :            : };
     173                 :            : 
     174                 :            : }
     175                 :            : 
     176                 :            : #endif // XAPIAN_INCLUDED_STEM_H

Generated by: LCOV version 1.11