• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
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 LIBTEXTCLASSIFIER_ACTIONS_RANKER_H_
18 #define LIBTEXTCLASSIFIER_ACTIONS_RANKER_H_
19 
20 #include <memory>
21 
22 #include "actions/actions_model_generated.h"
23 #include "actions/types.h"
24 #include "utils/zlib/zlib.h"
25 #include "flatbuffers/reflection.h"
26 
27 namespace libtextclassifier3 {
28 
29 // Ranking and filtering of actions suggestions.
30 class ActionsSuggestionsRanker {
31  public:
32   static std::unique_ptr<ActionsSuggestionsRanker>
33   CreateActionsSuggestionsRanker(const RankingOptions* options,
34                                  ZlibDecompressor* decompressor,
35                                  const std::string& smart_reply_action_type);
36 
37   // Rank and filter actions.
38   bool RankActions(
39       const Conversation& conversation, ActionsSuggestionsResponse* response,
40       const reflection::Schema* entity_data_schema = nullptr,
41       const reflection::Schema* annotations_entity_data_schema = nullptr) const;
42 
43  private:
ActionsSuggestionsRanker(const RankingOptions * options,const std::string & smart_reply_action_type)44   explicit ActionsSuggestionsRanker(const RankingOptions* options,
45                                     const std::string& smart_reply_action_type)
46       : options_(options), smart_reply_action_type_(smart_reply_action_type) {}
47 
48   bool InitializeAndValidate(ZlibDecompressor* decompressor);
49 
50   const RankingOptions* const options_;
51   std::string lua_bytecode_;
52   std::string smart_reply_action_type_;
53 };
54 
55 }  // namespace libtextclassifier3
56 
57 #endif  // LIBTEXTCLASSIFIER_ACTIONS_RANKER_H_
58