assistant_query.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef ASH_ASSISTANT_MODEL_ASSISTANT_QUERY_H_
  5. #define ASH_ASSISTANT_MODEL_ASSISTANT_QUERY_H_
  6. #include <string>
  7. #include "base/component_export.h"
  8. #include "chromeos/ash/services/assistant/public/cpp/assistant_service.h"
  9. namespace ash {
  10. // AssistantQueryType ----------------------------------------------------------
  11. // Defines possible types of an Assistant query.
  12. enum class AssistantQueryType {
  13. kNull, // See AssistantNullQuery.
  14. kText, // See AssistantTextQuery.
  15. kVoice, // See AssistantVoiceQuery.
  16. };
  17. // AssistantQuery --------------------------------------------------------------
  18. // Base class for an Assistant query.
  19. class COMPONENT_EXPORT(ASSISTANT_MODEL) AssistantQuery {
  20. public:
  21. using AssistantQuerySource = chromeos::assistant::AssistantQuerySource;
  22. AssistantQuery(const AssistantQuery&) = delete;
  23. AssistantQuery& operator=(const AssistantQuery&) = delete;
  24. virtual ~AssistantQuery() = default;
  25. // Returns the type for the query.
  26. AssistantQueryType type() const { return type_; }
  27. // Returns the input source for the query.
  28. AssistantQuerySource source() const { return source_; }
  29. // Returns true if the query is empty, false otherwise.
  30. virtual bool Empty() const = 0;
  31. protected:
  32. AssistantQuery(AssistantQueryType type, AssistantQuerySource source)
  33. : type_(type), source_(source) {}
  34. private:
  35. const AssistantQueryType type_;
  36. const AssistantQuerySource source_;
  37. };
  38. // AssistantNullQuery ----------------------------------------------------------
  39. // An null Assistant query used to signify the absence of an Assistant query.
  40. class COMPONENT_EXPORT(ASSISTANT_MODEL) AssistantNullQuery
  41. : public AssistantQuery {
  42. public:
  43. AssistantNullQuery()
  44. : AssistantQuery(AssistantQueryType::kNull,
  45. AssistantQuerySource::kUnspecified) {}
  46. AssistantNullQuery(const AssistantNullQuery&) = delete;
  47. AssistantNullQuery& operator=(const AssistantNullQuery&) = delete;
  48. ~AssistantNullQuery() override = default;
  49. // AssistantQuery:
  50. bool Empty() const override;
  51. };
  52. // AssistantTextQuery ----------------------------------------------------------
  53. // An Assistant text query.
  54. class COMPONENT_EXPORT(ASSISTANT_MODEL) AssistantTextQuery
  55. : public AssistantQuery {
  56. public:
  57. AssistantTextQuery(const std::string& text, AssistantQuerySource source)
  58. : AssistantQuery(AssistantQueryType::kText, source), text_(text) {}
  59. AssistantTextQuery(const AssistantTextQuery&) = delete;
  60. AssistantTextQuery& operator=(const AssistantTextQuery&) = delete;
  61. ~AssistantTextQuery() override = default;
  62. // AssistantQuery:
  63. bool Empty() const override;
  64. // Returns the text for the query.
  65. const std::string& text() const { return text_; }
  66. private:
  67. const std::string text_;
  68. };
  69. // AssistantVoiceQuery ---------------------------------------------------------
  70. // An Assistant voice query. At the start of a voice query, both the high and
  71. // low confidence speech portions will be empty. As speech recognition
  72. // continues, the low confidence portion will become non-empty. As speech
  73. // recognition improves, both the high and low confidence portions of the query
  74. // will be non-empty. When speech is fully recognized, only the high confidence
  75. // portion will be populated.
  76. class COMPONENT_EXPORT(ASSISTANT_MODEL) AssistantVoiceQuery
  77. : public AssistantQuery {
  78. public:
  79. AssistantVoiceQuery() : AssistantVoiceQuery(std::string(), std::string()) {}
  80. AssistantVoiceQuery(const std::string& high_confidence_speech,
  81. const std::string& low_confidence_speech = std::string())
  82. : AssistantQuery(AssistantQueryType::kVoice,
  83. AssistantQuerySource::kVoiceInput),
  84. high_confidence_speech_(high_confidence_speech),
  85. low_confidence_speech_(low_confidence_speech) {}
  86. AssistantVoiceQuery(const AssistantVoiceQuery&) = delete;
  87. AssistantVoiceQuery& operator=(const AssistantVoiceQuery&) = delete;
  88. ~AssistantVoiceQuery() override = default;
  89. // AssistantQuery:
  90. bool Empty() const override;
  91. // Returns speech for which we have high confidence of recognition.
  92. const std::string& high_confidence_speech() const {
  93. return high_confidence_speech_;
  94. }
  95. // Returns speech for which we have low confidence of recognition.
  96. const std::string& low_confidence_speech() const {
  97. return low_confidence_speech_;
  98. }
  99. private:
  100. const std::string high_confidence_speech_;
  101. const std::string low_confidence_speech_;
  102. };
  103. } // namespace ash
  104. #endif // ASH_ASSISTANT_MODEL_ASSISTANT_QUERY_H_