stemmer.h
Go to the documentation of this file.
1 /*
2  * Copyright 2006-2008 The FLWOR Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ZORBA_STEMMER_API_H
18 #define ZORBA_STEMMER_API_H
19 
20 #include <zorba/config.h>
21 
22 #ifndef ZORBA_NO_FULL_TEXT
23 
25 #include <zorba/internal/ztd.h>
26 #include <zorba/locale.h>
27 #include <zorba/zorba_string.h>
28 
29 namespace zorba {
30 
31 ///////////////////////////////////////////////////////////////////////////////
32 
33 /**
34  * A %Stemmer is used to obtain the "stem" (root) word of of some word. For
35  * example the stem of "flavoring" is "flavor". A %Stemmer is used by the
36  * XQuery Full Text feature.
37  */
38 class ZORBA_DLL_PUBLIC Stemmer {
39 public:
41 
42  /**
43  * Destroys this %Stemmer.
44  * This function is called by Zorba when the %Stemmer is no longer needed.
45  *
46  * If your StemmerProvider dynamically allocates %Stemmer objects, then the
47  * implementation can simply be (and usually is) <code>delete this</code>.
48  *
49  * If your StemmerProvider returns a pointer to a static %Stemmer object,
50  * then the implementation should do nothing.
51  */
52  virtual void destroy() const = 0;
53 
54  /**
55  * Various properties of this %Stemmer.
56  */
57  struct Properties {
58  /**
59  * The URI that uniquely identifies this %Stemmer.
60  */
61  char const *uri;
62  };
63 
64  /**
65  * Gets the Properties of this %Stemmer.
66  *
67  * @param result The Properties to populate.
68  */
69  virtual void properties( Properties *result ) const = 0;
70 
71  /**
72  * Stems the given word.
73  *
74  * @param word The word to stem.
75  * @param lang The language of the word.
76  * @param result The stemmed word (or the original word if either it and its
77  * stem are the same word or the stemmer doesn't know how to stem it).
78  */
79  virtual void stem( String const &word, locale::iso639_1::type lang,
80  String *result ) const = 0;
81 protected:
82  virtual ~Stemmer();
83 };
84 
85 /**
86  * A %StemmerProvider, given a language, provides a Stemmer for it.
87  */
88 class ZORBA_DLL_PUBLIC StemmerProvider {
89 public:
90  virtual ~StemmerProvider();
91 
92  /**
93  * Gets a Stemmer for the given language.
94  *
95  * @param lang The language to get a Stemmer for.
96  * @param s If not \c null, set to point to a Stemmer for \a lang.
97  * @return Returns \c true only if this provider can provide a stemmer for
98  * \a lang.
99  */
100  virtual bool getStemmer( locale::iso639_1::type lang,
101  Stemmer::ptr *s = 0 ) const = 0;
102 };
103 
104 ///////////////////////////////////////////////////////////////////////////////
105 
106 } // namespace zorba
107 #endif /* ZORBA_NO_FULL_TEXT */
108 #endif /* ZORBA_STEMMER_API_H */
109 /* vim:set et sw=2 ts=2: */