QueryIntentsResult.cc 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright 2009-2017 Alibaba Cloud All rights reserved.
  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. #include <alibabacloud/chatbot/model/QueryIntentsResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Chatbot;
  19. using namespace AlibabaCloud::Chatbot::Model;
  20. QueryIntentsResult::QueryIntentsResult() :
  21. ServiceResult()
  22. {}
  23. QueryIntentsResult::QueryIntentsResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. QueryIntentsResult::~QueryIntentsResult()
  29. {}
  30. void QueryIntentsResult::parse(const std::string &payload)
  31. {
  32. Json::Reader reader;
  33. Json::Value value;
  34. reader.parse(payload, value);
  35. setRequestId(value["RequestId"].asString());
  36. auto allIntentsNode = value["Intents"]["Intent"];
  37. for (auto valueIntentsIntent : allIntentsNode)
  38. {
  39. Intent intentsObject;
  40. if(!valueIntentsIntent["IntentId"].isNull())
  41. intentsObject.intentId = std::stol(valueIntentsIntent["IntentId"].asString());
  42. if(!valueIntentsIntent["Name"].isNull())
  43. intentsObject.name = valueIntentsIntent["Name"].asString();
  44. if(!valueIntentsIntent["CreateTime"].isNull())
  45. intentsObject.createTime = valueIntentsIntent["CreateTime"].asString();
  46. if(!valueIntentsIntent["ModifyTime"].isNull())
  47. intentsObject.modifyTime = valueIntentsIntent["ModifyTime"].asString();
  48. if(!valueIntentsIntent["CreateUserId"].isNull())
  49. intentsObject.createUserId = valueIntentsIntent["CreateUserId"].asString();
  50. if(!valueIntentsIntent["CreateUserName"].isNull())
  51. intentsObject.createUserName = valueIntentsIntent["CreateUserName"].asString();
  52. if(!valueIntentsIntent["ModifyUserId"].isNull())
  53. intentsObject.modifyUserId = valueIntentsIntent["ModifyUserId"].asString();
  54. if(!valueIntentsIntent["ModifyUserName"].isNull())
  55. intentsObject.modifyUserName = valueIntentsIntent["ModifyUserName"].asString();
  56. auto allUserSayNode = allIntentsNode["UserSay"]["UserSayItem"];
  57. for (auto allIntentsNodeUserSayUserSayItem : allUserSayNode)
  58. {
  59. Intent::UserSayItem userSayObject;
  60. if(!allIntentsNodeUserSayUserSayItem["Strict"].isNull())
  61. userSayObject.strict = allIntentsNodeUserSayUserSayItem["Strict"].asString() == "true";
  62. if(!allIntentsNodeUserSayUserSayItem["UserSayId"].isNull())
  63. userSayObject.userSayId = allIntentsNodeUserSayUserSayItem["UserSayId"].asString();
  64. auto allDataNode = allUserSayNode["Data"]["DataItem"];
  65. for (auto allUserSayNodeDataDataItem : allDataNode)
  66. {
  67. Intent::UserSayItem::DataItem dataObject;
  68. if(!allUserSayNodeDataDataItem["Text"].isNull())
  69. dataObject.text = allUserSayNodeDataDataItem["Text"].asString();
  70. if(!allUserSayNodeDataDataItem["SlotId"].isNull())
  71. dataObject.slotId = allUserSayNodeDataDataItem["SlotId"].asString();
  72. userSayObject.data.push_back(dataObject);
  73. }
  74. intentsObject.userSay.push_back(userSayObject);
  75. }
  76. auto allRuleCheckNode = allIntentsNode["RuleCheck"]["RuleCheckItem"];
  77. for (auto allIntentsNodeRuleCheckRuleCheckItem : allRuleCheckNode)
  78. {
  79. Intent::RuleCheckItem ruleCheckObject;
  80. if(!allIntentsNodeRuleCheckRuleCheckItem["Text"].isNull())
  81. ruleCheckObject.text = allIntentsNodeRuleCheckRuleCheckItem["Text"].asString();
  82. if(!allIntentsNodeRuleCheckRuleCheckItem["Strict"].isNull())
  83. ruleCheckObject.strict = allIntentsNodeRuleCheckRuleCheckItem["Strict"].asString() == "true";
  84. auto allWarning = value["Warning"]["Warning"];
  85. for (auto value : allWarning)
  86. ruleCheckObject.warning.push_back(value.asString());
  87. auto allError = value["Error"]["Error"];
  88. for (auto value : allError)
  89. ruleCheckObject.error.push_back(value.asString());
  90. intentsObject.ruleCheck.push_back(ruleCheckObject);
  91. }
  92. auto allSlotNode = allIntentsNode["Slot"]["SlotItem"];
  93. for (auto allIntentsNodeSlotSlotItem : allSlotNode)
  94. {
  95. Intent::SlotItem slotObject;
  96. if(!allIntentsNodeSlotSlotItem["Name"].isNull())
  97. slotObject.name = allIntentsNodeSlotSlotItem["Name"].asString();
  98. if(!allIntentsNodeSlotSlotItem["Value"].isNull())
  99. slotObject.value = allIntentsNodeSlotSlotItem["Value"].asString();
  100. if(!allIntentsNodeSlotSlotItem["IsNecessary"].isNull())
  101. slotObject.isNecessary = allIntentsNodeSlotSlotItem["IsNecessary"].asString() == "true";
  102. if(!allIntentsNodeSlotSlotItem["IsArray"].isNull())
  103. slotObject.isArray = allIntentsNodeSlotSlotItem["IsArray"].asString() == "true";
  104. if(!allIntentsNodeSlotSlotItem["LifeSpan"].isNull())
  105. slotObject.lifeSpan = std::stoi(allIntentsNodeSlotSlotItem["LifeSpan"].asString());
  106. if(!allIntentsNodeSlotSlotItem["SlotId"].isNull())
  107. slotObject.slotId = allIntentsNodeSlotSlotItem["SlotId"].asString();
  108. auto allTagsNode = allSlotNode["Tags"]["TagsItem"];
  109. for (auto allSlotNodeTagsTagsItem : allTagsNode)
  110. {
  111. Intent::SlotItem::TagsItem tagsObject;
  112. if(!allSlotNodeTagsTagsItem["Value"].isNull())
  113. tagsObject.value = allSlotNodeTagsTagsItem["Value"].asString();
  114. if(!allSlotNodeTagsTagsItem["UserSayId"].isNull())
  115. tagsObject.userSayId = allSlotNodeTagsTagsItem["UserSayId"].asString();
  116. slotObject.tags.push_back(tagsObject);
  117. }
  118. auto allQuestion = value["Question"]["Question"];
  119. for (auto value : allQuestion)
  120. slotObject.question.push_back(value.asString());
  121. intentsObject.slot.push_back(slotObject);
  122. }
  123. intents_.push_back(intentsObject);
  124. }
  125. if(!value["PageNumber"].isNull())
  126. pageNumber_ = std::stoi(value["PageNumber"].asString());
  127. if(!value["PageSize"].isNull())
  128. pageSize_ = std::stoi(value["PageSize"].asString());
  129. if(!value["TotalCount"].isNull())
  130. totalCount_ = std::stoi(value["TotalCount"].asString());
  131. }
  132. int QueryIntentsResult::getTotalCount()const
  133. {
  134. return totalCount_;
  135. }
  136. int QueryIntentsResult::getPageSize()const
  137. {
  138. return pageSize_;
  139. }
  140. int QueryIntentsResult::getPageNumber()const
  141. {
  142. return pageNumber_;
  143. }
  144. std::vector<QueryIntentsResult::Intent> QueryIntentsResult::getIntents()const
  145. {
  146. return intents_;
  147. }