AiOcrTableContext.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import json
  4. from alipay.aop.api.constant.ParamConstants import *
  5. class AiOcrTableContext(object):
  6. def __init__(self):
  7. self._ex = None
  8. self._ey = None
  9. self._height = None
  10. self._sx = None
  11. self._sy = None
  12. self._text = None
  13. self._type = None
  14. self._width = None
  15. @property
  16. def ex(self):
  17. return self._ex
  18. @ex.setter
  19. def ex(self, value):
  20. self._ex = value
  21. @property
  22. def ey(self):
  23. return self._ey
  24. @ey.setter
  25. def ey(self, value):
  26. self._ey = value
  27. @property
  28. def height(self):
  29. return self._height
  30. @height.setter
  31. def height(self, value):
  32. self._height = value
  33. @property
  34. def sx(self):
  35. return self._sx
  36. @sx.setter
  37. def sx(self, value):
  38. self._sx = value
  39. @property
  40. def sy(self):
  41. return self._sy
  42. @sy.setter
  43. def sy(self, value):
  44. self._sy = value
  45. @property
  46. def text(self):
  47. return self._text
  48. @text.setter
  49. def text(self, value):
  50. if isinstance(value, list):
  51. self._text = list()
  52. for i in value:
  53. self._text.append(i)
  54. @property
  55. def type(self):
  56. return self._type
  57. @type.setter
  58. def type(self, value):
  59. self._type = value
  60. @property
  61. def width(self):
  62. return self._width
  63. @width.setter
  64. def width(self, value):
  65. self._width = value
  66. def to_alipay_dict(self):
  67. params = dict()
  68. if self.ex:
  69. if hasattr(self.ex, 'to_alipay_dict'):
  70. params['ex'] = self.ex.to_alipay_dict()
  71. else:
  72. params['ex'] = self.ex
  73. if self.ey:
  74. if hasattr(self.ey, 'to_alipay_dict'):
  75. params['ey'] = self.ey.to_alipay_dict()
  76. else:
  77. params['ey'] = self.ey
  78. if self.height:
  79. if hasattr(self.height, 'to_alipay_dict'):
  80. params['height'] = self.height.to_alipay_dict()
  81. else:
  82. params['height'] = self.height
  83. if self.sx:
  84. if hasattr(self.sx, 'to_alipay_dict'):
  85. params['sx'] = self.sx.to_alipay_dict()
  86. else:
  87. params['sx'] = self.sx
  88. if self.sy:
  89. if hasattr(self.sy, 'to_alipay_dict'):
  90. params['sy'] = self.sy.to_alipay_dict()
  91. else:
  92. params['sy'] = self.sy
  93. if self.text:
  94. if isinstance(self.text, list):
  95. for i in range(0, len(self.text)):
  96. element = self.text[i]
  97. if hasattr(element, 'to_alipay_dict'):
  98. self.text[i] = element.to_alipay_dict()
  99. if hasattr(self.text, 'to_alipay_dict'):
  100. params['text'] = self.text.to_alipay_dict()
  101. else:
  102. params['text'] = self.text
  103. if self.type:
  104. if hasattr(self.type, 'to_alipay_dict'):
  105. params['type'] = self.type.to_alipay_dict()
  106. else:
  107. params['type'] = self.type
  108. if self.width:
  109. if hasattr(self.width, 'to_alipay_dict'):
  110. params['width'] = self.width.to_alipay_dict()
  111. else:
  112. params['width'] = self.width
  113. return params
  114. @staticmethod
  115. def from_alipay_dict(d):
  116. if not d:
  117. return None
  118. o = AiOcrTableContext()
  119. if 'ex' in d:
  120. o.ex = d['ex']
  121. if 'ey' in d:
  122. o.ey = d['ey']
  123. if 'height' in d:
  124. o.height = d['height']
  125. if 'sx' in d:
  126. o.sx = d['sx']
  127. if 'sy' in d:
  128. o.sy = d['sy']
  129. if 'text' in d:
  130. o.text = d['text']
  131. if 'type' in d:
  132. o.type = d['type']
  133. if 'width' in d:
  134. o.width = d['width']
  135. return o