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