xref: /aosp_15_r20/external/icing/icing/expand/stemming/stemmer-factory.h (revision 8b6cd535a057e39b3b86660c4aa06c99747c2136)
1 // Copyright (C) 2024 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef ICING_EXPAND_STEMMING_STEMMER_FACTORY_H_
16 #define ICING_EXPAND_STEMMING_STEMMER_FACTORY_H_
17 
18 #include <memory>
19 #include <string>
20 
21 #include "icing/text_classifier/lib3/utils/base/statusor.h"
22 #include "icing/expand/stemming/stemmer.h"
23 
24 namespace icing {
25 namespace lib {
26 
27 namespace stemmer_factory {
28 
29 // Creates a stemmer for the given language code.
30 //
31 // The language code should be a IETF BCP 47 language tag.
32 //   - E.g. "en" for English, "fr" for French, etc.
33 //   - See https://en.wikipedia.org/wiki/IETF_language_tag for more
34 //     information.
35 //
36 // This is the header file for the factory function. Implementations are in the
37 // .cc files, and we select which stemmer and .cc file to build with in each
38 // build rule.
39 //
40 // Returns:
41 //  - A stemmer on success
42 //  - INVALID_ARGUMENT_ERROR if the language code is invalid or not supported.
43 libtextclassifier3::StatusOr<std::unique_ptr<Stemmer>> Create(
44     std::string language_code);
45 
46 // Whether stemming is enabled.
47 //
48 // This is false for the none-stemmer implementation and true for the
49 // snowball-stemmer implementation.
50 bool IsStemmingEnabled();
51 
52 }  // namespace stemmer_factory
53 
54 }  // namespace lib
55 }  // namespace icing
56 
57 #endif  // ICING_EXPAND_STEMMING_STEMMER_FACTORY_H_
58