RecognizePdfResult.cc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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/ocr/model/RecognizePdfResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Ocr;
  19. using namespace AlibabaCloud::Ocr::Model;
  20. RecognizePdfResult::RecognizePdfResult() :
  21. ServiceResult()
  22. {}
  23. RecognizePdfResult::RecognizePdfResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. RecognizePdfResult::~RecognizePdfResult()
  29. {}
  30. void RecognizePdfResult::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 dataNode = value["Data"];
  37. if(!dataNode["Height"].isNull())
  38. data_.height = std::stol(dataNode["Height"].asString());
  39. if(!dataNode["Width"].isNull())
  40. data_.width = std::stol(dataNode["Width"].asString());
  41. if(!dataNode["OrgHeight"].isNull())
  42. data_.orgHeight = std::stol(dataNode["OrgHeight"].asString());
  43. if(!dataNode["OrgWidth"].isNull())
  44. data_.orgWidth = std::stol(dataNode["OrgWidth"].asString());
  45. if(!dataNode["PageIndex"].isNull())
  46. data_.pageIndex = std::stol(dataNode["PageIndex"].asString());
  47. if(!dataNode["Angle"].isNull())
  48. data_.angle = std::stol(dataNode["Angle"].asString());
  49. auto allWordsInfoNode = dataNode["WordsInfo"]["wordsInfoItem"];
  50. for (auto dataNodeWordsInfowordsInfoItem : allWordsInfoNode)
  51. {
  52. Data::WordsInfoItem wordsInfoItemObject;
  53. if(!dataNodeWordsInfowordsInfoItem["Angle"].isNull())
  54. wordsInfoItemObject.angle = std::stol(dataNodeWordsInfowordsInfoItem["Angle"].asString());
  55. if(!dataNodeWordsInfowordsInfoItem["Word"].isNull())
  56. wordsInfoItemObject.word = dataNodeWordsInfowordsInfoItem["Word"].asString();
  57. if(!dataNodeWordsInfowordsInfoItem["Height"].isNull())
  58. wordsInfoItemObject.height = std::stol(dataNodeWordsInfowordsInfoItem["Height"].asString());
  59. if(!dataNodeWordsInfowordsInfoItem["Width"].isNull())
  60. wordsInfoItemObject.width = std::stol(dataNodeWordsInfowordsInfoItem["Width"].asString());
  61. if(!dataNodeWordsInfowordsInfoItem["X"].isNull())
  62. wordsInfoItemObject.x = std::stol(dataNodeWordsInfowordsInfoItem["X"].asString());
  63. if(!dataNodeWordsInfowordsInfoItem["Y"].isNull())
  64. wordsInfoItemObject.y = std::stol(dataNodeWordsInfowordsInfoItem["Y"].asString());
  65. auto allPositionsNode = dataNodeWordsInfowordsInfoItem["Positions"]["positionsItem"];
  66. for (auto dataNodeWordsInfowordsInfoItemPositionspositionsItem : allPositionsNode)
  67. {
  68. Data::WordsInfoItem::PositionsItem positionsObject;
  69. if(!dataNodeWordsInfowordsInfoItemPositionspositionsItem["X"].isNull())
  70. positionsObject.x = std::stol(dataNodeWordsInfowordsInfoItemPositionspositionsItem["X"].asString());
  71. if(!dataNodeWordsInfowordsInfoItemPositionspositionsItem["Y"].isNull())
  72. positionsObject.y = std::stol(dataNodeWordsInfowordsInfoItemPositionspositionsItem["Y"].asString());
  73. wordsInfoItemObject.positions.push_back(positionsObject);
  74. }
  75. data_.wordsInfo.push_back(wordsInfoItemObject);
  76. }
  77. if(!value["Code"].isNull())
  78. code_ = value["Code"].asString();
  79. if(!value["Message"].isNull())
  80. message_ = value["Message"].asString();
  81. }
  82. std::string RecognizePdfResult::getMessage()const
  83. {
  84. return message_;
  85. }
  86. RecognizePdfResult::Data RecognizePdfResult::getData()const
  87. {
  88. return data_;
  89. }
  90. std::string RecognizePdfResult::getCode()const
  91. {
  92. return code_;
  93. }