• 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_GRAMMAR_ACTIONS_H_
18 #define LIBTEXTCLASSIFIER_ACTIONS_GRAMMAR_ACTIONS_H_
19 
20 #include <memory>
21 #include <vector>
22 
23 #include "actions/actions_model_generated.h"
24 #include "actions/types.h"
25 #include "utils/flatbuffers/mutable.h"
26 #include "utils/grammar/analyzer.h"
27 #include "utils/grammar/evaluated-derivation.h"
28 #include "utils/grammar/text-context.h"
29 #include "utils/i18n/locale.h"
30 #include "utils/tokenizer.h"
31 #include "utils/utf8/unilib.h"
32 
33 namespace libtextclassifier3 {
34 
35 // Grammar backed actions suggestions.
36 class GrammarActions {
37  public:
38   explicit GrammarActions(const UniLib* unilib,
39                           const RulesModel_::GrammarRules* grammar_rules,
40                           const MutableFlatbufferBuilder* entity_data_builder,
41                           const std::string& smart_reply_action_type);
42 
43   // Suggests actions for a conversation from a message stream.
44   bool SuggestActions(const Conversation& conversation,
45                       std::vector<ActionSuggestion>* result) const;
46 
47  private:
48   // Creates action suggestions from a grammar match result.
49   bool InstantiateActionsFromMatch(const grammar::TextContext& text_context,
50                                    int message_index,
51                                    const grammar::Derivation& derivation,
52                                    std::vector<ActionSuggestion>* result) const;
53 
54   const UniLib& unilib_;
55   const RulesModel_::GrammarRules* grammar_rules_;
56   const std::unique_ptr<Tokenizer> tokenizer_;
57   const MutableFlatbufferBuilder* entity_data_builder_;
58   const grammar::Analyzer analyzer_;
59   const std::string smart_reply_action_type_;
60 };
61 
62 }  // namespace libtextclassifier3
63 
64 #endif  // LIBTEXTCLASSIFIER_ACTIONS_GRAMMAR_ACTIONS_H_
65