QueryMcuJobResult.cc 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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/mts/model/QueryMcuJobResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Mts;
  19. using namespace AlibabaCloud::Mts::Model;
  20. QueryMcuJobResult::QueryMcuJobResult() :
  21. ServiceResult()
  22. {}
  23. QueryMcuJobResult::QueryMcuJobResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. QueryMcuJobResult::~QueryMcuJobResult()
  29. {}
  30. void QueryMcuJobResult::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 allJobResult = value["JobResult"]["Job"];
  37. for (auto value : allJobResult)
  38. {
  39. Job jobResultObject;
  40. if(!value["JobId"].isNull())
  41. jobResultObject.jobId = value["JobId"].asString();
  42. if(!value["UserData"].isNull())
  43. jobResultObject.userData = value["UserData"].asString();
  44. if(!value["TemplateId"].isNull())
  45. jobResultObject.templateId = value["TemplateId"].asString();
  46. if(!value["Template"].isNull())
  47. jobResultObject._template = value["Template"].asString();
  48. auto allOcrResult = value["OcrResult"]["Ocr"];
  49. for (auto value : allOcrResult)
  50. {
  51. Job::Ocr ocrResultObject;
  52. if(!value["Time"].isNull())
  53. ocrResultObject.time = value["Time"].asString();
  54. if(!value["OcrText"].isNull())
  55. ocrResultObject.ocrText = value["OcrText"].asString();
  56. if(!value["ImageUrl"].isNull())
  57. ocrResultObject.imageUrl = value["ImageUrl"].asString();
  58. if(!value["ImageId"].isNull())
  59. ocrResultObject.imageId = value["ImageId"].asString();
  60. jobResultObject.ocrResult.push_back(ocrResultObject);
  61. }
  62. auto allTagResult = value["TagResult"]["Tag"];
  63. for (auto value : allTagResult)
  64. {
  65. Job::Tag tagResultObject;
  66. if(!value["Time"].isNull())
  67. tagResultObject.time = value["Time"].asString();
  68. if(!value["ImageUrl"].isNull())
  69. tagResultObject.imageUrl = value["ImageUrl"].asString();
  70. if(!value["ImageId"].isNull())
  71. tagResultObject.imageId = value["ImageId"].asString();
  72. auto allFrameTagInfos = value["FrameTagInfos"]["FrameTagInfo"];
  73. for (auto value : allFrameTagInfos)
  74. {
  75. Job::Tag::FrameTagInfo frameTagInfosObject;
  76. if(!value["Tag"].isNull())
  77. frameTagInfosObject.tag = value["Tag"].asString();
  78. if(!value["Score"].isNull())
  79. frameTagInfosObject.score = value["Score"].asString();
  80. if(!value["Category"].isNull())
  81. frameTagInfosObject.category = value["Category"].asString();
  82. tagResultObject.frameTagInfos.push_back(frameTagInfosObject);
  83. }
  84. jobResultObject.tagResult.push_back(tagResultObject);
  85. }
  86. auto allFaceResult = value["FaceResult"]["Face"];
  87. for (auto value : allFaceResult)
  88. {
  89. Job::Face faceResultObject;
  90. if(!value["Time"].isNull())
  91. faceResultObject.time = value["Time"].asString();
  92. if(!value["ImageUrl"].isNull())
  93. faceResultObject.imageUrl = value["ImageUrl"].asString();
  94. if(!value["ImageId"].isNull())
  95. faceResultObject.imageId = value["ImageId"].asString();
  96. auto allCelebrities = value["Celebrities"]["Celebrity"];
  97. for (auto value : allCelebrities)
  98. {
  99. Job::Face::Celebrity celebritiesObject;
  100. if(!value["Name"].isNull())
  101. celebritiesObject.name = value["Name"].asString();
  102. if(!value["Score"].isNull())
  103. celebritiesObject.score = value["Score"].asString();
  104. if(!value["Target"].isNull())
  105. celebritiesObject.target = value["Target"].asString();
  106. faceResultObject.celebrities.push_back(celebritiesObject);
  107. }
  108. jobResultObject.faceResult.push_back(faceResultObject);
  109. }
  110. auto inputNode = value["Input"];
  111. if(!inputNode["Bucket"].isNull())
  112. jobResultObject.input.bucket = inputNode["Bucket"].asString();
  113. if(!inputNode["Location"].isNull())
  114. jobResultObject.input.location = inputNode["Location"].asString();
  115. if(!inputNode["Object"].isNull())
  116. jobResultObject.input.object = inputNode["Object"].asString();
  117. auto asrResultNode = value["AsrResult"];
  118. if(!asrResultNode["Duration"].isNull())
  119. jobResultObject.asrResult.duration = asrResultNode["Duration"].asString();
  120. auto allAsrTextList = value["AsrTextList"]["AsrText"];
  121. for (auto value : allAsrTextList)
  122. {
  123. Job::AsrResult::AsrText asrTextObject;
  124. if(!value["StartTime"].isNull())
  125. asrTextObject.startTime = std::stoi(value["StartTime"].asString());
  126. if(!value["EndTime"].isNull())
  127. asrTextObject.endTime = value["EndTime"].asString();
  128. if(!value["ChannelId"].isNull())
  129. asrTextObject.channelId = value["ChannelId"].asString();
  130. if(!value["SpeechRate"].isNull())
  131. asrTextObject.speechRate = value["SpeechRate"].asString();
  132. if(!value["Text"].isNull())
  133. asrTextObject.text = value["Text"].asString();
  134. jobResultObject.asrResult.asrTextList.push_back(asrTextObject);
  135. }
  136. auto categoryResultNode = value["CategoryResult"];
  137. if(!categoryResultNode["Details"].isNull())
  138. jobResultObject.categoryResult.details = categoryResultNode["Details"].asString();
  139. auto allCategories = value["Categories"]["Category"];
  140. for (auto value : allCategories)
  141. {
  142. Job::CategoryResult::Category categoryObject;
  143. if(!value["Label"].isNull())
  144. categoryObject.label = value["Label"].asString();
  145. if(!value["Score"].isNull())
  146. categoryObject.score = value["Score"].asString();
  147. jobResultObject.categoryResult.categories.push_back(categoryObject);
  148. }
  149. jobResult_.push_back(jobResultObject);
  150. }
  151. auto allNonExistJobIds = value["NonExistJobIds"]["String"];
  152. for (const auto &item : allNonExistJobIds)
  153. nonExistJobIds_.push_back(item.asString());
  154. }
  155. std::vector<std::string> QueryMcuJobResult::getNonExistJobIds()const
  156. {
  157. return nonExistJobIds_;
  158. }
  159. std::vector<QueryMcuJobResult::Job> QueryMcuJobResult::getJobResult()const
  160. {
  161. return jobResult_;
  162. }