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_H_ 16 #define ICING_EXPAND_STEMMING_STEMMER_H_ 17 18 #include <string> 19 #include <string_view> 20 21 namespace icing { 22 namespace lib { 23 24 // Stems a given term to its root form. 25 // 26 // Example usage: 27 // std::unique_ptr<Stemmer> stemmer = stemmer_factory::Create("en"); 28 // std::string stem = stemmer->Stem("running"); 29 class Stemmer { 30 public: 31 virtual ~Stemmer() = default; 32 33 // Returns the stem of a given term. 34 // This returns the same value if the term is already in its stem form. 35 virtual std::string Stem(std::string_view term) const = 0; 36 37 // Returns the language code of the stemmer. 38 virtual const std::string& language_code() const = 0; 39 }; 40 41 } // namespace lib 42 } // namespace icing 43 44 #endif // ICING_EXPAND_STEMMING_STEMMER_H_ 45