stemmer.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2006-2008 The FLWOR Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #ifndef ZORBA_STEMMER_API_H
00018 #define ZORBA_STEMMER_API_H
00019 
00020 #include <zorba/config.h>
00021 
00022 #ifndef ZORBA_NO_FULL_TEXT
00023 
00024 #include <zorba/internal/unique_ptr.h>
00025 #include <zorba/internal/ztd.h>
00026 #include <zorba/locale.h>
00027 #include <zorba/zorba_string.h>
00028 
00029 namespace zorba {
00030 
00031 ///////////////////////////////////////////////////////////////////////////////
00032 
00033 /**
00034  * A %Stemmer is used to obtain the "stem" (root) word of of some word.  For
00035  * example the stem of "flavoring" is "flavor".  A %Stemmer is used by the
00036  * XQuery Full Text feature.
00037  */
00038 class ZORBA_DLL_PUBLIC Stemmer {
00039 public:
00040   typedef std::unique_ptr<Stemmer,internal::ztd::destroy_delete<Stemmer> > ptr;
00041 
00042   /**
00043    * Destroys this %Stemmer.
00044    * This function is called by Zorba when the %Stemmer is no longer needed.
00045    *
00046    * If your StemmerProvider dynamically allocates %Stemmer objects, then the
00047    * implementation can (and usually is) simply <code>delete this</code>.
00048    *
00049    * If your StemmerProvider returns a pointer to a static %Stemmer object,
00050    * then the implementation should do nothing.
00051    */
00052   virtual void destroy() const = 0;
00053 
00054   /**
00055    * Stems the given word.
00056    *
00057    * @param word The word to stem.
00058    * @param lang The language of the word.
00059    * @param result The stemmed word (or the original word if either it and its
00060    * stem are the same word or the stemmer doesn't know how to stem it).
00061    */
00062   virtual void stem( String const &word, locale::iso639_1::type lang,
00063                      String *result ) const = 0;
00064 protected:
00065   virtual ~Stemmer();
00066 };
00067 
00068 /**
00069  * A %StemmerProvider, given an language, provies a stemmer for it.
00070  */
00071 class ZORBA_DLL_PUBLIC StemmerProvider {
00072 public:
00073   virtual ~StemmerProvider();
00074 
00075   /**
00076    * Gets a Stemmer for the given language.
00077    *
00078    * @param lang The language to get a Stemmer for.
00079    * @return The relevant Stemmer or \c NULL if no stemmer for the given
00080    * language is available.
00081    */
00082   virtual Stemmer::ptr getStemmer( locale::iso639_1::type lang ) const = 0;
00083 };
00084 
00085 ///////////////////////////////////////////////////////////////////////////////
00086 
00087 } // namespace zorba
00088 #endif /* ZORBA_NO_FULL_TEXT */
00089 #endif /* ZORBA_STEMMER_API_H */
00090 /* vim:set et sw=2 ts=2: */
blog comments powered by Disqus