1 2 #ifndef LIBTEXTCLASSIFIER_UTILS_INTENTS_INTENT_GENERATOR_H_ 3 #define LIBTEXTCLASSIFIER_UTILS_INTENTS_INTENT_GENERATOR_H_ 4 5 #include <jni.h> 6 7 #include <map> 8 #include <memory> 9 #include <string> 10 #include <vector> 11 12 #include "actions/types.h" 13 #include "annotator/types.h" 14 #include "utils/i18n/locale.h" 15 #include "utils/intents/intent-config_generated.h" 16 #include "utils/intents/remote-action-template.h" 17 #include "utils/java/jni-cache.h" 18 #include "utils/resources.h" 19 #include "utils/resources_generated.h" 20 #include "utils/strings/stringpiece.h" 21 22 namespace libtextclassifier3 { 23 24 // Helper class to generate Android intents for text classifier results. 25 class IntentGenerator { 26 public: 27 static std::unique_ptr<IntentGenerator> Create( 28 const IntentFactoryModel* options, const ResourcePool* resources, 29 const std::shared_ptr<JniCache>& jni_cache); 30 31 // Generates intents for a classification result. 32 // Returns true, if the intent generator snippets could be successfully run, 33 // returns false otherwise. 34 bool GenerateIntents(const jstring device_locales, 35 const ClassificationResult& classification, 36 const int64 reference_time_ms_utc, 37 const std::string& text, 38 const CodepointSpan selection_indices, 39 const jobject context, 40 const reflection::Schema* annotations_entity_data_schema, 41 std::vector<RemoteActionTemplate>* remote_actions) const; 42 43 // Generates intents for an action suggestion. 44 // Returns true, if the intent generator snippets could be successfully run, 45 // returns false otherwise. 46 bool GenerateIntents(const jstring device_locales, 47 const ActionSuggestion& action, 48 const Conversation& conversation, const jobject context, 49 const reflection::Schema* annotations_entity_data_schema, 50 const reflection::Schema* actions_entity_data_schema, 51 std::vector<RemoteActionTemplate>* remote_actions) const; 52 53 private: IntentGenerator(const IntentFactoryModel * options,const ResourcePool * resources,const std::shared_ptr<JniCache> & jni_cache)54 IntentGenerator(const IntentFactoryModel* options, 55 const ResourcePool* resources, 56 const std::shared_ptr<JniCache>& jni_cache) 57 : options_(options), 58 resources_(Resources(resources)), 59 jni_cache_(jni_cache) {} 60 61 std::vector<Locale> ParseDeviceLocales(const jstring device_locales) const; 62 63 const IntentFactoryModel* options_; 64 const Resources resources_; 65 std::shared_ptr<JniCache> jni_cache_; 66 std::map<std::string, std::string> generators_; 67 }; 68 69 } // namespace libtextclassifier3 70 71 #endif // LIBTEXTCLASSIFIER_UTILS_INTENTS_INTENT_GENERATOR_H_ 72