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_LUA_RANKER_H_ 18 #define LIBTEXTCLASSIFIER_ACTIONS_LUA_RANKER_H_ 19 20 #include <memory> 21 #include <string> 22 23 #include "actions/types.h" 24 #include "utils/lua-utils.h" 25 26 namespace libtextclassifier3 { 27 28 // Lua backed action suggestion ranking. 29 class ActionsSuggestionsLuaRanker : public LuaEnvironment { 30 public: 31 static std::unique_ptr<ActionsSuggestionsLuaRanker> Create( 32 const Conversation& conversation, const std::string& ranker_code, 33 const reflection::Schema* entity_data_schema, 34 const reflection::Schema* annotations_entity_data_schema, 35 ActionsSuggestionsResponse* response); 36 37 bool RankActions(); 38 39 private: ActionsSuggestionsLuaRanker(const Conversation & conversation,const std::string & ranker_code,const reflection::Schema * actions_entity_data_schema,const reflection::Schema * annotations_entity_data_schema,ActionsSuggestionsResponse * response)40 explicit ActionsSuggestionsLuaRanker( 41 const Conversation& conversation, const std::string& ranker_code, 42 const reflection::Schema* actions_entity_data_schema, 43 const reflection::Schema* annotations_entity_data_schema, 44 ActionsSuggestionsResponse* response) 45 : conversation_(conversation), 46 ranker_code_(ranker_code), 47 actions_entity_data_schema_(actions_entity_data_schema), 48 annotations_entity_data_schema_(annotations_entity_data_schema), 49 response_(response) {} 50 51 bool Initialize(); 52 53 // Reads ranking results from the lua stack. 54 int ReadActionsRanking(); 55 56 const Conversation& conversation_; 57 const std::string& ranker_code_; 58 const reflection::Schema* actions_entity_data_schema_; 59 const reflection::Schema* annotations_entity_data_schema_; 60 ActionsSuggestionsResponse* response_; 61 }; 62 63 } // namespace libtextclassifier3 64 65 #endif // LIBTEXTCLASSIFIER_ACTIONS_LUA_RANKER_H_ 66