thesaurus.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_THESAURUS_API_H
18 #define ZORBA_THESAURUS_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/uri_resolvers.h>
28 #include <zorba/zorba_string.h>
29 
30 namespace zorba {
31 
32 ///////////////////////////////////////////////////////////////////////////////
33 
34 /**
35  * A %Thesaurus provides a way to look up related phrases for a given phrase.
36  */
37 class ZORBA_DLL_PUBLIC Thesaurus {
38 public:
39  typedef std::unique_ptr<
41  >
42  ptr;
43 
44  /**
45  * The integral type for "at least" and "at most" values.
46  */
47  typedef unsigned range_type;
48 
49  /**
50  * An %iterator is used to iterate over lookup results.
51  */
52  class iterator {
53  public:
55  ptr;
56 
57  /**
58  * Destroys this iterator.
59  */
60  virtual void destroy() const = 0;
61 
62  /**
63  * Gets the next synonym. This function must always include the original
64  * phrase that was looked up in its results.
65  *
66  * @param synonym A pointer to the string to receive the next synonym.
67  * @return Returns \c true only if there is a next synonym.
68  */
69  virtual bool next( String *synonym ) = 0;
70 
71  protected:
72  virtual ~iterator() { }
73  };
74 
75  /**
76  * Destroys this %Thesaurus.
77  * This function is called by Zorba when the %Thesaurus is no longer needed.
78  *
79  * If your implementation dynamically allocates %Thesaurus objects, then your
80  * implementation can simply be (and usually is) <code>delete this</code>.
81  *
82  * If your implementation returns a pointer to a static %Thesaurus object,
83  * then your implementation should do nothing.
84  */
85  virtual void destroy() const = 0;
86 
87  /**
88  * Looks-up the given phrase.
89  *
90  * @param phrase The phrase to look up.
91  * @param relationship The relationship the synonyms are to have to the given
92  * \a phrase.
93  * @param at_least The minimum number of levels within the thesaurus to be
94  * traversed.
95  * @param at_most The maximum number of levels within the thesaurus to be
96  * traversed.
97  * @return Returns a pointer to an iterator for the results or \c NULL if the
98  * phrase was not found.
99  */
100  virtual iterator::ptr
101  lookup( String const &phrase, String const &relationship,
102  range_type at_least, range_type at_most ) const = 0;
103 
104 protected:
105  virtual ~Thesaurus();
106 };
107 
108 ///////////////////////////////////////////////////////////////////////////////
109 
110 /**
111  * A %ThesaurusProvider is-a Resource for providing thesauri for a given
112  * language.
113  */
114 class ZORBA_DLL_PUBLIC ThesaurusProvider : public Resource {
115 public:
116  typedef std::unique_ptr<
117  ThesaurusProvider const,
119  >
121 
122  /**
123  * Gets a Thesaurus for the given language.
124  *
125  * @param lang The desired language of the thesaurus.
126  * @param t If not \c null, set to point to a Thesaurus for \a lang.
127  * @return Returns \c true only if this provider can provide a thesaurus for
128  * \a lang.
129  */
130  virtual bool getThesaurus( locale::iso639_1::type lang,
131  Thesaurus::ptr *t = 0 ) const = 0;
132 };
133 
134 ///////////////////////////////////////////////////////////////////////////////
135 
136 } // namespace zorba
137 #endif /* ZORBA_NO_FULL_TEXT */
138 #endif /* ZORBA_THESAURUS_API_H */
139 /* vim:set et sw=2 ts=2: */
This header file defines all uri resolvers.
The Zorba string class.
Definition: zorba_string.h:33
A deleter class that can be used with unique_ptr.
Definition: ztd.h:201
An iterator is used to iterate over lookup results.
Definition: thesaurus.h:52
std::unique_ptr< Thesaurus const, internal::ztd::destroy_delete< Thesaurus const > > ptr
Definition: thesaurus.h:42
unsigned range_type
The integral type for "at least" and "at most" values.
Definition: thesaurus.h:47
std::unique_ptr< iterator, internal::ztd::destroy_delete< iterator > > ptr
Definition: thesaurus.h:55
A Thesaurus provides a way to look up related phrases for a given phrase.
Definition: thesaurus.h:37
The class representing the result of URL resolution.
Definition: uri_resolvers.h:50
std::unique_ptr< ThesaurusProvider const, internal::ztd::destroy_delete< ThesaurusProvider const > > ptr
Definition: thesaurus.h:120
A ThesaurusProvider is-a Resource for providing thesauri for a given language.
Definition: thesaurus.h:114