• 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 // Utils for creating action suggestions.
18 
19 #ifndef LIBTEXTCLASSIFIER_ACTIONS_UTILS_H_
20 #define LIBTEXTCLASSIFIER_ACTIONS_UTILS_H_
21 
22 #include <string>
23 #include <vector>
24 
25 #include "actions/actions_model_generated.h"
26 #include "actions/types.h"
27 #include "annotator/types.h"
28 #include "utils/flatbuffers.h"
29 #include "utils/utf8/unicodetext.h"
30 #include "utils/utf8/unilib.h"
31 
32 namespace libtextclassifier3 {
33 
34 // Fills an action suggestion from a template.
35 void FillSuggestionFromSpec(const ActionSuggestionSpec* action,
36                             ReflectiveFlatbuffer* entity_data,
37                             ActionSuggestion* suggestion);
38 
39 // Creates text replies from capturing matches.
40 void SuggestTextRepliesFromCapturingMatch(
41     const ReflectiveFlatbufferBuilder* entity_data_builder,
42     const RulesModel_::RuleActionSpec_::RuleCapturingGroup* group,
43     const UnicodeText& match_text, const std::string& smart_reply_action_type,
44     std::vector<ActionSuggestion>* actions);
45 
46 // Applies normalization to a capturing match.
47 UnicodeText NormalizeMatchText(
48     const UniLib& unilib,
49     const RulesModel_::RuleActionSpec_::RuleCapturingGroup* group,
50     StringPiece match_text);
51 
52 // Fills the fields in an annotation from a capturing match.
53 bool FillAnnotationFromCapturingMatch(
54     const CodepointSpan& span,
55     const RulesModel_::RuleActionSpec_::RuleCapturingGroup* group,
56     const int message_index, StringPiece match_text,
57     ActionSuggestionAnnotation* annotation);
58 
59 // Merges entity data from a capturing match.
60 // Parses and sets values from the text and merges fixed data.
61 bool MergeEntityDataFromCapturingMatch(
62     const RulesModel_::RuleActionSpec_::RuleCapturingGroup* group,
63     StringPiece match_text, ReflectiveFlatbuffer* buffer);
64 
65 }  // namespace libtextclassifier3
66 
67 #endif  // LIBTEXTCLASSIFIER_ACTIONS_UTILS_H_
68