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