• 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_TYPES_H_
18 #define LIBTEXTCLASSIFIER_ACTIONS_TYPES_H_
19 
20 #include <map>
21 #include <string>
22 #include <vector>
23 
24 #include "actions/actions-entity-data_generated.h"
25 #include "annotator/types.h"
26 #include "utils/flatbuffers.h"
27 
28 namespace libtextclassifier3 {
29 
30 // A text span in the conversation.
31 struct MessageTextSpan {
32   explicit MessageTextSpan() = default;
MessageTextSpanMessageTextSpan33   MessageTextSpan(const int message_index, const CodepointSpan span,
34                   const std::string& text)
35       : message_index(message_index), span(span), text(text) {}
36 
37   // The referenced message.
38   // -1 if not referencing a particular message in the provided input.
39   int message_index = kInvalidIndex;
40 
41   // The span within the reference message.
42   // (-1, -1) if not referencing a particular location.
43   CodepointSpan span = CodepointSpan{kInvalidIndex, kInvalidIndex};
44 
45   // The span text.
46   std::string text;
47 };
48 
49 // An entity associated with an action.
50 struct ActionSuggestionAnnotation {
51   MessageTextSpan span;
52   ClassificationResult entity;
53 
54   // Optional annotation name.
55   std::string name;
56 };
57 
58 // Action suggestion that contains a response text and the type of the response.
59 struct ActionSuggestion {
60   // Text of the action suggestion.
61   std::string response_text;
62 
63   // Type of the action suggestion.
64   std::string type;
65 
66   // Score.
67   float score = 0.f;
68 
69   // Priority score for internal conflict resolution.
70   float priority_score = 0.f;
71 
72   // The associated annotations.
73   std::vector<ActionSuggestionAnnotation> annotations;
74 
75   // Extras information.
76   std::string serialized_entity_data;
77 
entity_dataActionSuggestion78   const ActionsEntityData* entity_data() {
79     return LoadAndVerifyFlatbuffer<ActionsEntityData>(
80         serialized_entity_data.data(), serialized_entity_data.size());
81   }
82 };
83 
84 // Actions suggestions result containing meta - information and the suggested
85 // actions.
86 struct ActionsSuggestionsResponse {
87   // The sensitivity assessment.
88   float sensitivity_score = -1.f;
89   float triggering_score = -1.f;
90 
91   // Whether the output was suppressed by the sensitivity threshold.
92   bool output_filtered_sensitivity = false;
93 
94   // Whether the output was suppressed by the triggering score threshold.
95   bool output_filtered_min_triggering_score = false;
96 
97   // Whether the output was suppressed by the low confidence patterns.
98   bool output_filtered_low_confidence = false;
99 
100   // Whether the output was suppressed due to locale mismatch.
101   bool output_filtered_locale_mismatch = false;
102 
103   // The suggested actions.
104   std::vector<ActionSuggestion> actions;
105 };
106 
107 // Represents a single message in the conversation.
108 struct ConversationMessage {
109   // User ID distinguishing the user from other users in the conversation.
110   int user_id = 0;
111 
112   // Text of the message.
113   std::string text;
114 
115   // Reference time of this message.
116   int64 reference_time_ms_utc = 0;
117 
118   // Timezone in which the input text was written (format as accepted by ICU).
119   std::string reference_timezone;
120 
121   // Annotations on the text.
122   std::vector<AnnotatedSpan> annotations;
123 
124   // Comma-separated list of BCP 47 language tags of the message.
125   std::string detected_text_language_tags;
126 };
127 
128 // Conversation between multiple users.
129 struct Conversation {
130   // Sequence of messages that were exchanged in the conversation.
131   std::vector<ConversationMessage> messages;
132 };
133 
134 }  // namespace libtextclassifier3
135 
136 #endif  // LIBTEXTCLASSIFIER_ACTIONS_TYPES_H_
137