pyxllib 0.3.96__py3-none-any.whl → 0.3.200__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (358) hide show
  1. pyxllib/__init__.py +21 -21
  2. pyxllib/algo/__init__.py +8 -8
  3. pyxllib/algo/disjoint.py +54 -54
  4. pyxllib/algo/geo.py +541 -529
  5. pyxllib/algo/intervals.py +964 -964
  6. pyxllib/algo/matcher.py +389 -311
  7. pyxllib/algo/newbie.py +166 -166
  8. pyxllib/algo/pupil.py +629 -461
  9. pyxllib/algo/shapelylib.py +67 -67
  10. pyxllib/algo/specialist.py +241 -240
  11. pyxllib/algo/stat.py +494 -458
  12. pyxllib/algo/treelib.py +149 -149
  13. pyxllib/algo/unitlib.py +66 -66
  14. {pyxlpr → pyxllib/autogui}/__init__.py +5 -5
  15. pyxllib/autogui/activewin.py +246 -0
  16. pyxllib/autogui/all.py +9 -0
  17. pyxllib/{ext/autogui → autogui}/autogui.py +852 -823
  18. pyxllib/autogui/uiautolib.py +362 -0
  19. pyxllib/{ext/autogui → autogui}/virtualkey.py +102 -102
  20. pyxllib/autogui/wechat.py +827 -0
  21. pyxllib/autogui/wechat_msg.py +421 -0
  22. pyxllib/autogui/wxautolib.py +84 -0
  23. pyxllib/cv/__init__.py +5 -5
  24. pyxllib/cv/expert.py +267 -267
  25. pyxllib/cv/imfile.py +159 -159
  26. pyxllib/cv/imhash.py +39 -39
  27. pyxllib/cv/pupil.py +9 -9
  28. pyxllib/cv/rgbfmt.py +1525 -1525
  29. pyxllib/cv/slidercaptcha.py +137 -0
  30. pyxllib/cv/trackbartools.py +251 -251
  31. pyxllib/cv/xlcvlib.py +1040 -1040
  32. pyxllib/cv/xlpillib.py +423 -423
  33. pyxllib/data/echarts.py +240 -129
  34. pyxllib/data/jsonlib.py +89 -0
  35. pyxllib/data/oss.py +72 -72
  36. pyxllib/data/pglib.py +1127 -643
  37. pyxllib/data/sqlite.py +568 -341
  38. pyxllib/data/sqllib.py +297 -297
  39. pyxllib/ext/JLineViewer.py +505 -492
  40. pyxllib/ext/__init__.py +6 -6
  41. pyxllib/ext/demolib.py +246 -246
  42. pyxllib/ext/drissionlib.py +277 -0
  43. pyxllib/ext/kq5034lib.py +12 -1606
  44. pyxllib/ext/old.py +663 -663
  45. pyxllib/ext/qt.py +449 -449
  46. pyxllib/ext/robustprocfile.py +497 -0
  47. pyxllib/ext/seleniumlib.py +76 -76
  48. pyxllib/ext/tk.py +173 -173
  49. pyxllib/ext/unixlib.py +827 -826
  50. pyxllib/ext/utools.py +351 -338
  51. pyxllib/ext/webhook.py +124 -101
  52. pyxllib/ext/win32lib.py +40 -40
  53. pyxllib/ext/wjxlib.py +88 -0
  54. pyxllib/ext/wpsapi.py +124 -0
  55. pyxllib/ext/xlwork.py +9 -0
  56. pyxllib/ext/yuquelib.py +1105 -173
  57. pyxllib/file/__init__.py +17 -17
  58. pyxllib/file/docxlib.py +761 -761
  59. pyxllib/file/gitlib.py +309 -309
  60. pyxllib/file/libreoffice.py +165 -0
  61. pyxllib/file/movielib.py +148 -139
  62. pyxllib/file/newbie.py +10 -10
  63. pyxllib/file/onenotelib.py +1469 -1469
  64. pyxllib/file/packlib/__init__.py +330 -293
  65. pyxllib/file/packlib/zipfile.py +2441 -2441
  66. pyxllib/file/pdflib.py +426 -426
  67. pyxllib/file/pupil.py +185 -185
  68. pyxllib/file/specialist/__init__.py +685 -685
  69. pyxllib/file/specialist/dirlib.py +799 -799
  70. pyxllib/file/specialist/download.py +193 -186
  71. pyxllib/file/specialist/filelib.py +2829 -2618
  72. pyxllib/file/xlsxlib.py +3131 -2976
  73. pyxllib/file/xlsyncfile.py +341 -0
  74. pyxllib/prog/__init__.py +5 -5
  75. pyxllib/prog/cachetools.py +64 -0
  76. pyxllib/prog/deprecatedlib.py +233 -233
  77. pyxllib/prog/filelock.py +42 -0
  78. pyxllib/prog/ipyexec.py +253 -253
  79. pyxllib/prog/multiprogs.py +940 -0
  80. pyxllib/prog/newbie.py +451 -444
  81. pyxllib/prog/pupil.py +1197 -1128
  82. pyxllib/prog/sitepackages.py +33 -33
  83. pyxllib/prog/specialist/__init__.py +391 -217
  84. pyxllib/prog/specialist/bc.py +203 -200
  85. pyxllib/prog/specialist/browser.py +497 -488
  86. pyxllib/prog/specialist/common.py +347 -347
  87. pyxllib/prog/specialist/datetime.py +199 -131
  88. pyxllib/prog/specialist/tictoc.py +240 -241
  89. pyxllib/prog/specialist/xllog.py +180 -180
  90. pyxllib/prog/xlosenv.py +108 -101
  91. pyxllib/stdlib/__init__.py +17 -17
  92. pyxllib/stdlib/tablepyxl/__init__.py +10 -10
  93. pyxllib/stdlib/tablepyxl/style.py +303 -303
  94. pyxllib/stdlib/tablepyxl/tablepyxl.py +130 -130
  95. pyxllib/text/__init__.py +8 -8
  96. pyxllib/text/ahocorasick.py +39 -39
  97. pyxllib/text/airscript.js +744 -0
  98. pyxllib/text/charclasslib.py +121 -109
  99. pyxllib/text/jiebalib.py +267 -264
  100. pyxllib/text/jinjalib.py +32 -0
  101. pyxllib/text/jsa_ai_prompt.md +271 -0
  102. pyxllib/text/jscode.py +922 -767
  103. pyxllib/text/latex/__init__.py +158 -158
  104. pyxllib/text/levenshtein.py +303 -303
  105. pyxllib/text/nestenv.py +1215 -1215
  106. pyxllib/text/newbie.py +300 -288
  107. pyxllib/text/pupil/__init__.py +8 -8
  108. pyxllib/text/pupil/common.py +1121 -1095
  109. pyxllib/text/pupil/xlalign.py +326 -326
  110. pyxllib/text/pycode.py +47 -47
  111. pyxllib/text/specialist/__init__.py +8 -8
  112. pyxllib/text/specialist/common.py +112 -112
  113. pyxllib/text/specialist/ptag.py +186 -186
  114. pyxllib/text/spellchecker.py +172 -172
  115. pyxllib/text/templates/echart_base.html +11 -0
  116. pyxllib/text/templates/highlight_code.html +17 -0
  117. pyxllib/text/templates/latex_editor.html +103 -0
  118. pyxllib/text/vbacode.py +17 -17
  119. pyxllib/text/xmllib.py +747 -685
  120. pyxllib/xl.py +42 -38
  121. pyxllib/xlcv.py +17 -17
  122. pyxllib-0.3.200.dist-info/METADATA +48 -0
  123. pyxllib-0.3.200.dist-info/RECORD +126 -0
  124. {pyxllib-0.3.96.dist-info → pyxllib-0.3.200.dist-info}/WHEEL +1 -2
  125. {pyxllib-0.3.96.dist-info → pyxllib-0.3.200.dist-info/licenses}/LICENSE +190 -190
  126. pyxllib/ext/autogui/__init__.py +0 -8
  127. pyxllib-0.3.96.dist-info/METADATA +0 -51
  128. pyxllib-0.3.96.dist-info/RECORD +0 -333
  129. pyxllib-0.3.96.dist-info/top_level.txt +0 -2
  130. pyxlpr/ai/__init__.py +0 -5
  131. pyxlpr/ai/clientlib.py +0 -1281
  132. pyxlpr/ai/specialist.py +0 -286
  133. pyxlpr/ai/torch_app.py +0 -172
  134. pyxlpr/ai/xlpaddle.py +0 -655
  135. pyxlpr/ai/xltorch.py +0 -705
  136. pyxlpr/data/__init__.py +0 -11
  137. pyxlpr/data/coco.py +0 -1325
  138. pyxlpr/data/datacls.py +0 -365
  139. pyxlpr/data/datasets.py +0 -200
  140. pyxlpr/data/gptlib.py +0 -1291
  141. pyxlpr/data/icdar/__init__.py +0 -96
  142. pyxlpr/data/icdar/deteval.py +0 -377
  143. pyxlpr/data/icdar/icdar2013.py +0 -341
  144. pyxlpr/data/icdar/iou.py +0 -340
  145. pyxlpr/data/icdar/rrc_evaluation_funcs_1_1.py +0 -463
  146. pyxlpr/data/imtextline.py +0 -473
  147. pyxlpr/data/labelme.py +0 -866
  148. pyxlpr/data/removeline.py +0 -179
  149. pyxlpr/data/specialist.py +0 -57
  150. pyxlpr/eval/__init__.py +0 -85
  151. pyxlpr/paddleocr.py +0 -776
  152. pyxlpr/ppocr/__init__.py +0 -15
  153. pyxlpr/ppocr/configs/rec/multi_language/generate_multi_language_configs.py +0 -226
  154. pyxlpr/ppocr/data/__init__.py +0 -135
  155. pyxlpr/ppocr/data/imaug/ColorJitter.py +0 -26
  156. pyxlpr/ppocr/data/imaug/__init__.py +0 -67
  157. pyxlpr/ppocr/data/imaug/copy_paste.py +0 -170
  158. pyxlpr/ppocr/data/imaug/east_process.py +0 -437
  159. pyxlpr/ppocr/data/imaug/gen_table_mask.py +0 -244
  160. pyxlpr/ppocr/data/imaug/iaa_augment.py +0 -114
  161. pyxlpr/ppocr/data/imaug/label_ops.py +0 -789
  162. pyxlpr/ppocr/data/imaug/make_border_map.py +0 -184
  163. pyxlpr/ppocr/data/imaug/make_pse_gt.py +0 -106
  164. pyxlpr/ppocr/data/imaug/make_shrink_map.py +0 -126
  165. pyxlpr/ppocr/data/imaug/operators.py +0 -433
  166. pyxlpr/ppocr/data/imaug/pg_process.py +0 -906
  167. pyxlpr/ppocr/data/imaug/randaugment.py +0 -143
  168. pyxlpr/ppocr/data/imaug/random_crop_data.py +0 -239
  169. pyxlpr/ppocr/data/imaug/rec_img_aug.py +0 -533
  170. pyxlpr/ppocr/data/imaug/sast_process.py +0 -777
  171. pyxlpr/ppocr/data/imaug/text_image_aug/__init__.py +0 -17
  172. pyxlpr/ppocr/data/imaug/text_image_aug/augment.py +0 -120
  173. pyxlpr/ppocr/data/imaug/text_image_aug/warp_mls.py +0 -168
  174. pyxlpr/ppocr/data/lmdb_dataset.py +0 -115
  175. pyxlpr/ppocr/data/pgnet_dataset.py +0 -104
  176. pyxlpr/ppocr/data/pubtab_dataset.py +0 -107
  177. pyxlpr/ppocr/data/simple_dataset.py +0 -372
  178. pyxlpr/ppocr/losses/__init__.py +0 -61
  179. pyxlpr/ppocr/losses/ace_loss.py +0 -52
  180. pyxlpr/ppocr/losses/basic_loss.py +0 -135
  181. pyxlpr/ppocr/losses/center_loss.py +0 -88
  182. pyxlpr/ppocr/losses/cls_loss.py +0 -30
  183. pyxlpr/ppocr/losses/combined_loss.py +0 -67
  184. pyxlpr/ppocr/losses/det_basic_loss.py +0 -208
  185. pyxlpr/ppocr/losses/det_db_loss.py +0 -80
  186. pyxlpr/ppocr/losses/det_east_loss.py +0 -63
  187. pyxlpr/ppocr/losses/det_pse_loss.py +0 -149
  188. pyxlpr/ppocr/losses/det_sast_loss.py +0 -121
  189. pyxlpr/ppocr/losses/distillation_loss.py +0 -272
  190. pyxlpr/ppocr/losses/e2e_pg_loss.py +0 -140
  191. pyxlpr/ppocr/losses/kie_sdmgr_loss.py +0 -113
  192. pyxlpr/ppocr/losses/rec_aster_loss.py +0 -99
  193. pyxlpr/ppocr/losses/rec_att_loss.py +0 -39
  194. pyxlpr/ppocr/losses/rec_ctc_loss.py +0 -44
  195. pyxlpr/ppocr/losses/rec_enhanced_ctc_loss.py +0 -70
  196. pyxlpr/ppocr/losses/rec_nrtr_loss.py +0 -30
  197. pyxlpr/ppocr/losses/rec_sar_loss.py +0 -28
  198. pyxlpr/ppocr/losses/rec_srn_loss.py +0 -47
  199. pyxlpr/ppocr/losses/table_att_loss.py +0 -109
  200. pyxlpr/ppocr/metrics/__init__.py +0 -44
  201. pyxlpr/ppocr/metrics/cls_metric.py +0 -45
  202. pyxlpr/ppocr/metrics/det_metric.py +0 -82
  203. pyxlpr/ppocr/metrics/distillation_metric.py +0 -73
  204. pyxlpr/ppocr/metrics/e2e_metric.py +0 -86
  205. pyxlpr/ppocr/metrics/eval_det_iou.py +0 -274
  206. pyxlpr/ppocr/metrics/kie_metric.py +0 -70
  207. pyxlpr/ppocr/metrics/rec_metric.py +0 -75
  208. pyxlpr/ppocr/metrics/table_metric.py +0 -50
  209. pyxlpr/ppocr/modeling/architectures/__init__.py +0 -32
  210. pyxlpr/ppocr/modeling/architectures/base_model.py +0 -88
  211. pyxlpr/ppocr/modeling/architectures/distillation_model.py +0 -60
  212. pyxlpr/ppocr/modeling/backbones/__init__.py +0 -54
  213. pyxlpr/ppocr/modeling/backbones/det_mobilenet_v3.py +0 -268
  214. pyxlpr/ppocr/modeling/backbones/det_resnet_vd.py +0 -246
  215. pyxlpr/ppocr/modeling/backbones/det_resnet_vd_sast.py +0 -285
  216. pyxlpr/ppocr/modeling/backbones/e2e_resnet_vd_pg.py +0 -265
  217. pyxlpr/ppocr/modeling/backbones/kie_unet_sdmgr.py +0 -186
  218. pyxlpr/ppocr/modeling/backbones/rec_mobilenet_v3.py +0 -138
  219. pyxlpr/ppocr/modeling/backbones/rec_mv1_enhance.py +0 -258
  220. pyxlpr/ppocr/modeling/backbones/rec_nrtr_mtb.py +0 -48
  221. pyxlpr/ppocr/modeling/backbones/rec_resnet_31.py +0 -210
  222. pyxlpr/ppocr/modeling/backbones/rec_resnet_aster.py +0 -143
  223. pyxlpr/ppocr/modeling/backbones/rec_resnet_fpn.py +0 -307
  224. pyxlpr/ppocr/modeling/backbones/rec_resnet_vd.py +0 -286
  225. pyxlpr/ppocr/modeling/heads/__init__.py +0 -54
  226. pyxlpr/ppocr/modeling/heads/cls_head.py +0 -52
  227. pyxlpr/ppocr/modeling/heads/det_db_head.py +0 -118
  228. pyxlpr/ppocr/modeling/heads/det_east_head.py +0 -121
  229. pyxlpr/ppocr/modeling/heads/det_pse_head.py +0 -37
  230. pyxlpr/ppocr/modeling/heads/det_sast_head.py +0 -128
  231. pyxlpr/ppocr/modeling/heads/e2e_pg_head.py +0 -253
  232. pyxlpr/ppocr/modeling/heads/kie_sdmgr_head.py +0 -206
  233. pyxlpr/ppocr/modeling/heads/multiheadAttention.py +0 -163
  234. pyxlpr/ppocr/modeling/heads/rec_aster_head.py +0 -393
  235. pyxlpr/ppocr/modeling/heads/rec_att_head.py +0 -202
  236. pyxlpr/ppocr/modeling/heads/rec_ctc_head.py +0 -88
  237. pyxlpr/ppocr/modeling/heads/rec_nrtr_head.py +0 -826
  238. pyxlpr/ppocr/modeling/heads/rec_sar_head.py +0 -402
  239. pyxlpr/ppocr/modeling/heads/rec_srn_head.py +0 -280
  240. pyxlpr/ppocr/modeling/heads/self_attention.py +0 -406
  241. pyxlpr/ppocr/modeling/heads/table_att_head.py +0 -246
  242. pyxlpr/ppocr/modeling/necks/__init__.py +0 -32
  243. pyxlpr/ppocr/modeling/necks/db_fpn.py +0 -111
  244. pyxlpr/ppocr/modeling/necks/east_fpn.py +0 -188
  245. pyxlpr/ppocr/modeling/necks/fpn.py +0 -138
  246. pyxlpr/ppocr/modeling/necks/pg_fpn.py +0 -314
  247. pyxlpr/ppocr/modeling/necks/rnn.py +0 -92
  248. pyxlpr/ppocr/modeling/necks/sast_fpn.py +0 -284
  249. pyxlpr/ppocr/modeling/necks/table_fpn.py +0 -110
  250. pyxlpr/ppocr/modeling/transforms/__init__.py +0 -28
  251. pyxlpr/ppocr/modeling/transforms/stn.py +0 -135
  252. pyxlpr/ppocr/modeling/transforms/tps.py +0 -308
  253. pyxlpr/ppocr/modeling/transforms/tps_spatial_transformer.py +0 -156
  254. pyxlpr/ppocr/optimizer/__init__.py +0 -61
  255. pyxlpr/ppocr/optimizer/learning_rate.py +0 -228
  256. pyxlpr/ppocr/optimizer/lr_scheduler.py +0 -49
  257. pyxlpr/ppocr/optimizer/optimizer.py +0 -160
  258. pyxlpr/ppocr/optimizer/regularizer.py +0 -52
  259. pyxlpr/ppocr/postprocess/__init__.py +0 -55
  260. pyxlpr/ppocr/postprocess/cls_postprocess.py +0 -33
  261. pyxlpr/ppocr/postprocess/db_postprocess.py +0 -234
  262. pyxlpr/ppocr/postprocess/east_postprocess.py +0 -143
  263. pyxlpr/ppocr/postprocess/locality_aware_nms.py +0 -200
  264. pyxlpr/ppocr/postprocess/pg_postprocess.py +0 -52
  265. pyxlpr/ppocr/postprocess/pse_postprocess/__init__.py +0 -15
  266. pyxlpr/ppocr/postprocess/pse_postprocess/pse/__init__.py +0 -29
  267. pyxlpr/ppocr/postprocess/pse_postprocess/pse/setup.py +0 -14
  268. pyxlpr/ppocr/postprocess/pse_postprocess/pse_postprocess.py +0 -118
  269. pyxlpr/ppocr/postprocess/rec_postprocess.py +0 -654
  270. pyxlpr/ppocr/postprocess/sast_postprocess.py +0 -355
  271. pyxlpr/ppocr/tools/__init__.py +0 -14
  272. pyxlpr/ppocr/tools/eval.py +0 -83
  273. pyxlpr/ppocr/tools/export_center.py +0 -77
  274. pyxlpr/ppocr/tools/export_model.py +0 -129
  275. pyxlpr/ppocr/tools/infer/predict_cls.py +0 -151
  276. pyxlpr/ppocr/tools/infer/predict_det.py +0 -300
  277. pyxlpr/ppocr/tools/infer/predict_e2e.py +0 -169
  278. pyxlpr/ppocr/tools/infer/predict_rec.py +0 -414
  279. pyxlpr/ppocr/tools/infer/predict_system.py +0 -204
  280. pyxlpr/ppocr/tools/infer/utility.py +0 -629
  281. pyxlpr/ppocr/tools/infer_cls.py +0 -83
  282. pyxlpr/ppocr/tools/infer_det.py +0 -134
  283. pyxlpr/ppocr/tools/infer_e2e.py +0 -122
  284. pyxlpr/ppocr/tools/infer_kie.py +0 -153
  285. pyxlpr/ppocr/tools/infer_rec.py +0 -146
  286. pyxlpr/ppocr/tools/infer_table.py +0 -107
  287. pyxlpr/ppocr/tools/program.py +0 -596
  288. pyxlpr/ppocr/tools/test_hubserving.py +0 -117
  289. pyxlpr/ppocr/tools/train.py +0 -163
  290. pyxlpr/ppocr/tools/xlprog.py +0 -748
  291. pyxlpr/ppocr/utils/EN_symbol_dict.txt +0 -94
  292. pyxlpr/ppocr/utils/__init__.py +0 -24
  293. pyxlpr/ppocr/utils/dict/ar_dict.txt +0 -117
  294. pyxlpr/ppocr/utils/dict/arabic_dict.txt +0 -162
  295. pyxlpr/ppocr/utils/dict/be_dict.txt +0 -145
  296. pyxlpr/ppocr/utils/dict/bg_dict.txt +0 -140
  297. pyxlpr/ppocr/utils/dict/chinese_cht_dict.txt +0 -8421
  298. pyxlpr/ppocr/utils/dict/cyrillic_dict.txt +0 -163
  299. pyxlpr/ppocr/utils/dict/devanagari_dict.txt +0 -167
  300. pyxlpr/ppocr/utils/dict/en_dict.txt +0 -63
  301. pyxlpr/ppocr/utils/dict/fa_dict.txt +0 -136
  302. pyxlpr/ppocr/utils/dict/french_dict.txt +0 -136
  303. pyxlpr/ppocr/utils/dict/german_dict.txt +0 -143
  304. pyxlpr/ppocr/utils/dict/hi_dict.txt +0 -162
  305. pyxlpr/ppocr/utils/dict/it_dict.txt +0 -118
  306. pyxlpr/ppocr/utils/dict/japan_dict.txt +0 -4399
  307. pyxlpr/ppocr/utils/dict/ka_dict.txt +0 -153
  308. pyxlpr/ppocr/utils/dict/korean_dict.txt +0 -3688
  309. pyxlpr/ppocr/utils/dict/latin_dict.txt +0 -185
  310. pyxlpr/ppocr/utils/dict/mr_dict.txt +0 -153
  311. pyxlpr/ppocr/utils/dict/ne_dict.txt +0 -153
  312. pyxlpr/ppocr/utils/dict/oc_dict.txt +0 -96
  313. pyxlpr/ppocr/utils/dict/pu_dict.txt +0 -130
  314. pyxlpr/ppocr/utils/dict/rs_dict.txt +0 -91
  315. pyxlpr/ppocr/utils/dict/rsc_dict.txt +0 -134
  316. pyxlpr/ppocr/utils/dict/ru_dict.txt +0 -125
  317. pyxlpr/ppocr/utils/dict/ta_dict.txt +0 -128
  318. pyxlpr/ppocr/utils/dict/table_dict.txt +0 -277
  319. pyxlpr/ppocr/utils/dict/table_structure_dict.txt +0 -2759
  320. pyxlpr/ppocr/utils/dict/te_dict.txt +0 -151
  321. pyxlpr/ppocr/utils/dict/ug_dict.txt +0 -114
  322. pyxlpr/ppocr/utils/dict/uk_dict.txt +0 -142
  323. pyxlpr/ppocr/utils/dict/ur_dict.txt +0 -137
  324. pyxlpr/ppocr/utils/dict/xi_dict.txt +0 -110
  325. pyxlpr/ppocr/utils/dict90.txt +0 -90
  326. pyxlpr/ppocr/utils/e2e_metric/Deteval.py +0 -574
  327. pyxlpr/ppocr/utils/e2e_metric/polygon_fast.py +0 -83
  328. pyxlpr/ppocr/utils/e2e_utils/extract_batchsize.py +0 -87
  329. pyxlpr/ppocr/utils/e2e_utils/extract_textpoint_fast.py +0 -457
  330. pyxlpr/ppocr/utils/e2e_utils/extract_textpoint_slow.py +0 -592
  331. pyxlpr/ppocr/utils/e2e_utils/pgnet_pp_utils.py +0 -162
  332. pyxlpr/ppocr/utils/e2e_utils/visual.py +0 -162
  333. pyxlpr/ppocr/utils/en_dict.txt +0 -95
  334. pyxlpr/ppocr/utils/gen_label.py +0 -81
  335. pyxlpr/ppocr/utils/ic15_dict.txt +0 -36
  336. pyxlpr/ppocr/utils/iou.py +0 -54
  337. pyxlpr/ppocr/utils/logging.py +0 -69
  338. pyxlpr/ppocr/utils/network.py +0 -84
  339. pyxlpr/ppocr/utils/ppocr_keys_v1.txt +0 -6623
  340. pyxlpr/ppocr/utils/profiler.py +0 -110
  341. pyxlpr/ppocr/utils/save_load.py +0 -150
  342. pyxlpr/ppocr/utils/stats.py +0 -72
  343. pyxlpr/ppocr/utils/utility.py +0 -80
  344. pyxlpr/ppstructure/__init__.py +0 -13
  345. pyxlpr/ppstructure/predict_system.py +0 -187
  346. pyxlpr/ppstructure/table/__init__.py +0 -13
  347. pyxlpr/ppstructure/table/eval_table.py +0 -72
  348. pyxlpr/ppstructure/table/matcher.py +0 -192
  349. pyxlpr/ppstructure/table/predict_structure.py +0 -136
  350. pyxlpr/ppstructure/table/predict_table.py +0 -221
  351. pyxlpr/ppstructure/table/table_metric/__init__.py +0 -16
  352. pyxlpr/ppstructure/table/table_metric/parallel.py +0 -51
  353. pyxlpr/ppstructure/table/table_metric/table_metric.py +0 -247
  354. pyxlpr/ppstructure/table/tablepyxl/__init__.py +0 -13
  355. pyxlpr/ppstructure/table/tablepyxl/style.py +0 -283
  356. pyxlpr/ppstructure/table/tablepyxl/tablepyxl.py +0 -118
  357. pyxlpr/ppstructure/utility.py +0 -71
  358. pyxlpr/xlai.py +0 -10
@@ -1,326 +1,326 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- # @Author : 陈坤泽
4
- # @Email : 877362867@qq.com
5
- # @Date : 2020/06/01
6
-
7
-
8
- """很久以前搞得一个,按照中文域宽对齐相关操作
9
- 也是 pyxllib v0.0.xx 最底层基础的__str.py 文件
10
- """
11
-
12
- import copy
13
- import re
14
- import textwrap
15
-
16
- from pyxllib.prog.newbie import len_in_dim2, GrowingList
17
- from pyxllib.prog.pupil import run_once
18
-
19
-
20
- def strwidth(s):
21
- """ string width
22
-
23
- 中英字符串实际宽度
24
- >>> strwidth('ab')
25
- 2
26
- >>> strwidth('a⑪中⑩')
27
- 7
28
-
29
- ⑩等字符的宽度还是跟字体有关的,不过在大部分地方好像都是域宽2,目前算法问题不大
30
- """
31
- try:
32
- res = len(s.encode('gbk'))
33
- except UnicodeEncodeError:
34
- count = len(s)
35
- for x in s:
36
- if ord(x) > 127:
37
- count += 1
38
- res = count
39
- return res
40
-
41
-
42
- @run_once('str')
43
- def get_strwidth(s):
44
- """ 带缓存的版本 """
45
- return strwidth(s)
46
-
47
-
48
- def strwidth_proc(s, fmt='r', chinese_char_width=1.8):
49
- """ 此函数可以用于每个汉字域宽是w=1.8等奇怪的情况
50
-
51
- 为了让字符串域宽为一个整数,需要补充中文空格,会对原始字符串进行修改。
52
- 故返回值有2个,第1个是修正后的字符串s,第2个是实际宽度w。
53
-
54
- :param s: 一个字符串
55
- :param fmt: 目标对齐格式
56
- :param chinese_char_width: 每个汉字字符宽度
57
- :return: (s, w)
58
- s: 修正后的字符串值s
59
- w: 修正后字符串的实际宽度
60
-
61
- >>> strwidth_proc('哈哈a', chinese_char_width=1.8)
62
- ('   哈哈a', 10)
63
- """
64
- # 1 计算一些参数值
65
- s = str(s) # 确保是字符串类型
66
- l1 = len(s)
67
- l2 = strwidth(s)
68
- y = l2 - l1 # 中文字符数
69
- x = l1 - y # 英文字符数
70
- ch = chr(12288) # 中文空格
71
- w = x + y * chinese_char_width # 当前字符串宽度
72
- # 2 计算需要补充t个中文空格
73
- error = 0.05 # 允许误差范围
74
- t = 0 # 需要补充中文字符数
75
- while error < w % 1 < 1 - error: # 小数部分超过误差
76
- t += 1
77
- w += chinese_char_width
78
- # 3 补充中文字符
79
- if t:
80
- if fmt == 'r':
81
- s = ch * t + s
82
- elif fmt == 'l':
83
- s = s + ch * t
84
- else:
85
- s = ch * (t - t // 2) + s + ch * (t // 2)
86
- return s, int(w)
87
-
88
-
89
- def realign(text, least_blank=4, tab2blank=4, support_chinese=False, sep=None):
90
- r""" 一列文本的对齐
91
- :param text: 一段文本
92
- 支持每行列数不同
93
- :param least_blank: 每列最少间距空格数
94
- :param tab2blank:
95
- :param support_chinese: 支持中文域宽计算
96
- :param sep: 每列分隔符,默认为least_blank个空格
97
- :return: 对齐美化的一段文本
98
-
99
- >>> realign(' Aget keep hold show\nmaking selling giving collecting')
100
- 'Aget keep hold show\nmaking selling giving collecting'
101
- """
102
- # 1 预处理
103
- s = text.replace('\t', ' ' * tab2blank)
104
- s = re.sub(' {' + str(least_blank) + ',}', r'\t', s) # 统一用\t作为分隔符
105
- lenfunc = strwidth if support_chinese else len
106
- if sep is None: sep = ' ' * least_blank
107
-
108
- # 2 计算出每一列的最大宽度
109
- lines = s.splitlines()
110
- n = len(lines)
111
- max_width = GrowingList() # 因为不知道有多少列,用自增长的list来存储每一列的最大宽度
112
- for i, line in enumerate(lines):
113
- line = line.strip().split('\t')
114
- m = len(line)
115
- for j in range(m): max_width[j] = max(max_width[j] or 0, lenfunc(line[j]))
116
- lines[i] = line
117
- if len(max_width) == 1: return '\n'.join(map(lambda x: x[0], lines))
118
-
119
- # 3 重组内容
120
- for i, line in enumerate(lines):
121
- for j in range(len(line) - 1): line[j] += ' ' * (max_width[j] - lenfunc(line[j])) # 注意最后一列就不用加空格了
122
- lines[i] = sep.join(line)
123
- return '\n'.join(lines)
124
-
125
-
126
- def listalign(ls, fmt='r', *, width=None, fillchar=' ', prefix='', suffix='', chinese_char_width=2):
127
- """文档: https://blog.csdn.net/code4101/article/details/80985218(不过文档有些过时了)
128
-
129
- listalign列表对齐
130
- py3中str的len是计算字符数量,例如len('ab') --> 2, len('a中b') --> 3。
131
- 但在对齐等操作中,是需要将每个汉字当成宽度2来处理,计算字符串实际宽度的。
132
- 所以我们需要开发一个strwidth函数,效果: strwidth('ab') --> 2,strwidth('a中b') --> 4。
133
-
134
- :param ls:
135
- 要处理的列表,会对所有元素调用str处理,确保全部转为string类型
136
- 且会将换行符转为\n显示
137
- :param fmt: (format)
138
- l: left,左对齐
139
- c: center,居中
140
- r: right,右对齐
141
- 多个字符: 扩展fmt长度跟ls一样,每一个元素单独设置对齐格式。如果fmt长度小于ls,则扩展的格式按照fmt[-1]设置
142
- :param width:
143
- None或者设置值小于最长字符串: 不设域宽,直接按照最长的字符串为准
144
- :param fillchar: 填充字符
145
- :param prefix: 添加前缀
146
- :param suffix: 添加后缀
147
- :param chinese_char_width: 每个汉字字符宽度
148
-
149
- :return:
150
- 对齐后的数组ls,每个元素会转为str类型
151
-
152
- >>> listalign(['a', '哈哈', 'ccd'])
153
- [' a', '哈哈', ' ccd']
154
- >>> listalign(['a', '哈哈', 'ccd'], chinese_char_width=1.8)
155
- [' a', '   哈哈', ' ccd']
156
- """
157
- # 1 处理fmt数组
158
- if len(fmt) == 1:
159
- fmt = [fmt] * len(ls)
160
- elif len(fmt) < len(ls):
161
- fmt = list(fmt) + [fmt[-1]] * (len(ls) - len(fmt))
162
-
163
- # 2 算出需要域宽
164
- if chinese_char_width == 2:
165
- strs = [str(x).replace('\n', r'\n') for x in ls] # 存储转成字符串的元素
166
- lens = [strwidth(x) for x in strs] # 存储每个元素的实际域宽
167
- else:
168
- strs = [] # 存储转成字符串的元素
169
- lens = [] # 存储每个元素的实际域宽
170
- for i, t in enumerate(ls):
171
- t, n = strwidth_proc(t, fmt[i], chinese_char_width)
172
- strs.append(t)
173
- lens.append(n)
174
- w = max(lens)
175
- if width and isinstance(width, int) and width > w:
176
- w = width
177
-
178
- # 3 对齐操作
179
- for i, s in enumerate(strs):
180
- if fmt[i] == 'r':
181
- strs[i] = fillchar * (w - lens[i]) + strs[i]
182
- elif fmt[i] == 'l':
183
- strs[i] = strs[i] + fillchar * (w - lens[i])
184
- elif fmt[i] == 'c':
185
- t = w - lens[i]
186
- strs[i] = fillchar * (t - t // 2) + strs[i] + fillchar * (t // 2)
187
- strs[i] = prefix + strs[i] + suffix
188
- return strs
189
-
190
-
191
- def arr_hangclear(arr, depth=None):
192
- """ 清除连续相同值,简化表格内容
193
- >> arr_hangclear(arr, depth=2)
194
- 原表格:
195
- A B D
196
- A B E
197
- A C E
198
- A C E
199
- 新表格:
200
- A B D
201
- E
202
- C E
203
- E
204
-
205
- :param arr: 二维数组
206
- :param depth: 处理列上限
207
- 例如depth=1,则只处理第一层
208
- depth=None,则处理所有列
209
-
210
- >>> arr_hangclear([[1, 2, 4], [1, 2, 5], [1, 3, 5], [1, 3, 5]])
211
- [[1, 2, 4], ['', '', 5], ['', 3, 5], ['', '', 5]]
212
- >>> arr_hangclear([[1, 2, 4], [1, 2, 5], [2, 2, 5], [1, 2, 5]])
213
- [[1, 2, 4], ['', '', 5], [2, 2, 5], [1, 2, 5]]
214
- """
215
- m = depth or len_in_dim2(arr) - 1
216
- a = copy.deepcopy(arr)
217
-
218
- # 算法原理:从下到上,从右到左判断与上一行重叠了几列数据
219
- for i in range(len(arr) - 1, 0, -1):
220
- for j in range(m):
221
- if a[i][j] == a[i - 1][j]:
222
- a[i][j] = ''
223
- else:
224
- break
225
- return a
226
-
227
-
228
- def arr2table(arr, rowmerge=False):
229
- """ 数组转html表格代码
230
-
231
- :param arr: 需要处理的数组
232
- :param rowmerge: 行单元格合并
233
- :return: html文本格式的<table>
234
-
235
- 这个arr2table是用来画合并单元格的
236
- >> browser(arr2table([['A', 1, 'a'], ['', 2, 'b'], ['B', 3, 'c'], ['', '', 'd'], ['', 5, 'e']], True), 'a.html')
237
- 效果图:http://i1.fuimg.com/582188/c452f40b5a072f8d.png
238
- """
239
- n = len(arr)
240
- m = len_in_dim2(arr)
241
- res = ['<table border="1"><tbody>']
242
- for i, line in enumerate(arr):
243
- res.append('<tr>')
244
- for j, ele in enumerate(line):
245
- if rowmerge:
246
- if ele != '':
247
- cnt = 1
248
- while i + cnt < n and arr[i + cnt][j] == '':
249
- for k in range(j - 1, -1, -1):
250
- if arr[i + cnt][k] != '':
251
- break
252
- else:
253
- cnt += 1
254
- continue
255
- break
256
- if cnt > 1:
257
- res.append(f'<td rowspan="{cnt}">{ele}</td>')
258
- else:
259
- res.append(f'<td>{ele}</td>')
260
- elif j == m - 1:
261
- res.append(f'<td>{ele}</td>')
262
- else:
263
- res.append(f'<td>{ele}</td>')
264
- res.append('</tr>')
265
- res.append('</tbody></table>')
266
- return ''.join(res)
267
-
268
-
269
- def east_asian_len(s, ambiguous_width=None):
270
- import pandas.io.formats.format as fmt
271
- return fmt.EastAsianTextAdjustment().len(s)
272
-
273
-
274
- def east_asian_shorten(s, width=50, placeholder='...'):
275
- """考虑中文情况下的域宽截断
276
-
277
- :param s: 要处理的字符串
278
- :param width: 宽度上限,仅能达到width-1的宽度
279
- :param placeholder: 如果做了截断,末尾补足字符
280
-
281
- # width比placeholder还小
282
- >>> east_asian_shorten('a', 2)
283
- 'a'
284
- >>> east_asian_shorten('a啊b'*4, 3)
285
- '..'
286
- >>> east_asian_shorten('a啊b'*4, 4)
287
- '...'
288
-
289
- >>> east_asian_shorten('a啊b'*4, 5, '...')
290
- 'a...'
291
- >>> east_asian_shorten('a啊b'*4, 11)
292
- 'a啊ba啊...'
293
- >>> east_asian_shorten('a啊b'*4, 16, '...')
294
- 'a啊ba啊ba啊b...'
295
- >>> east_asian_shorten('a啊b'*4, 18, '...')
296
- 'a啊ba啊ba啊ba啊b'
297
- """
298
- # 一、如果字符串本身不到width设限,返回原值
299
- s = textwrap.shorten(s, width * 3, placeholder='') # 用textwrap的折行功能,尽量不删除文本
300
- n = east_asian_len(s)
301
- if n < width: return s
302
-
303
- # 二、如果输入的width比placeholder还短
304
- width -= 1
305
- m = east_asian_len(placeholder)
306
- if width <= m:
307
- return placeholder[:width]
308
-
309
- # 三、需要添加 placeholder
310
- # 1 计算长度
311
- width -= m
312
-
313
- # 2 截取s
314
- try:
315
- s = s.encode('gbk')[:width].decode('gbk', errors='ignore')
316
- except UnicodeEncodeError:
317
- i, count = 0, m
318
- while i < n and count <= width:
319
- if ord(s[i]) > 127:
320
- count += 2
321
- else:
322
- count += 1
323
- i += 1
324
- s = s[:i]
325
-
326
- return s + placeholder
1
+ #!/usr/bin/env python3
2
+ # -*- coding: utf-8 -*-
3
+ # @Author : 陈坤泽
4
+ # @Email : 877362867@qq.com
5
+ # @Date : 2020/06/01
6
+
7
+
8
+ """很久以前搞得一个,按照中文域宽对齐相关操作
9
+ 也是 pyxllib v0.0.xx 最底层基础的__str.py 文件
10
+ """
11
+
12
+ import copy
13
+ import re
14
+ import textwrap
15
+
16
+ from pyxllib.prog.newbie import len_in_dim2, GrowingList
17
+ from pyxllib.prog.pupil import run_once
18
+
19
+
20
+ def strwidth(s):
21
+ """ string width
22
+
23
+ 中英字符串实际宽度
24
+ >>> strwidth('ab')
25
+ 2
26
+ >>> strwidth('a⑪中⑩')
27
+ 7
28
+
29
+ ⑩等字符的宽度还是跟字体有关的,不过在大部分地方好像都是域宽2,目前算法问题不大
30
+ """
31
+ try:
32
+ res = len(s.encode('gbk'))
33
+ except UnicodeEncodeError:
34
+ count = len(s)
35
+ for x in s:
36
+ if ord(x) > 127:
37
+ count += 1
38
+ res = count
39
+ return res
40
+
41
+
42
+ @run_once('str')
43
+ def get_strwidth(s):
44
+ """ 带缓存的版本 """
45
+ return strwidth(s)
46
+
47
+
48
+ def strwidth_proc(s, fmt='r', chinese_char_width=1.8):
49
+ """ 此函数可以用于每个汉字域宽是w=1.8等奇怪的情况
50
+
51
+ 为了让字符串域宽为一个整数,需要补充中文空格,会对原始字符串进行修改。
52
+ 故返回值有2个,第1个是修正后的字符串s,第2个是实际宽度w。
53
+
54
+ :param s: 一个字符串
55
+ :param fmt: 目标对齐格式
56
+ :param chinese_char_width: 每个汉字字符宽度
57
+ :return: (s, w)
58
+ s: 修正后的字符串值s
59
+ w: 修正后字符串的实际宽度
60
+
61
+ >>> strwidth_proc('哈哈a', chinese_char_width=1.8)
62
+ ('   哈哈a', 10)
63
+ """
64
+ # 1 计算一些参数值
65
+ s = str(s) # 确保是字符串类型
66
+ l1 = len(s)
67
+ l2 = strwidth(s)
68
+ y = l2 - l1 # 中文字符数
69
+ x = l1 - y # 英文字符数
70
+ ch = chr(12288) # 中文空格
71
+ w = x + y * chinese_char_width # 当前字符串宽度
72
+ # 2 计算需要补充t个中文空格
73
+ error = 0.05 # 允许误差范围
74
+ t = 0 # 需要补充中文字符数
75
+ while error < w % 1 < 1 - error: # 小数部分超过误差
76
+ t += 1
77
+ w += chinese_char_width
78
+ # 3 补充中文字符
79
+ if t:
80
+ if fmt == 'r':
81
+ s = ch * t + s
82
+ elif fmt == 'l':
83
+ s = s + ch * t
84
+ else:
85
+ s = ch * (t - t // 2) + s + ch * (t // 2)
86
+ return s, int(w)
87
+
88
+
89
+ def realign(text, least_blank=4, tab2blank=4, support_chinese=False, sep=None):
90
+ r""" 一列文本的对齐
91
+ :param text: 一段文本
92
+ 支持每行列数不同
93
+ :param least_blank: 每列最少间距空格数
94
+ :param tab2blank:
95
+ :param support_chinese: 支持中文域宽计算
96
+ :param sep: 每列分隔符,默认为least_blank个空格
97
+ :return: 对齐美化的一段文本
98
+
99
+ >>> realign(' Aget keep hold show\nmaking selling giving collecting')
100
+ 'Aget keep hold show\nmaking selling giving collecting'
101
+ """
102
+ # 1 预处理
103
+ s = text.replace('\t', ' ' * tab2blank)
104
+ s = re.sub(' {' + str(least_blank) + ',}', r'\t', s) # 统一用\t作为分隔符
105
+ lenfunc = strwidth if support_chinese else len
106
+ if sep is None: sep = ' ' * least_blank
107
+
108
+ # 2 计算出每一列的最大宽度
109
+ lines = s.splitlines()
110
+ n = len(lines)
111
+ max_width = GrowingList() # 因为不知道有多少列,用自增长的list来存储每一列的最大宽度
112
+ for i, line in enumerate(lines):
113
+ line = line.strip().split('\t')
114
+ m = len(line)
115
+ for j in range(m): max_width[j] = max(max_width[j] or 0, lenfunc(line[j]))
116
+ lines[i] = line
117
+ if len(max_width) == 1: return '\n'.join(map(lambda x: x[0], lines))
118
+
119
+ # 3 重组内容
120
+ for i, line in enumerate(lines):
121
+ for j in range(len(line) - 1): line[j] += ' ' * (max_width[j] - lenfunc(line[j])) # 注意最后一列就不用加空格了
122
+ lines[i] = sep.join(line)
123
+ return '\n'.join(lines)
124
+
125
+
126
+ def listalign(ls, fmt='r', *, width=None, fillchar=' ', prefix='', suffix='', chinese_char_width=2):
127
+ """文档: https://blog.csdn.net/code4101/article/details/80985218(不过文档有些过时了)
128
+
129
+ listalign列表对齐
130
+ py3中str的len是计算字符数量,例如len('ab') --> 2, len('a中b') --> 3。
131
+ 但在对齐等操作中,是需要将每个汉字当成宽度2来处理,计算字符串实际宽度的。
132
+ 所以我们需要开发一个strwidth函数,效果: strwidth('ab') --> 2,strwidth('a中b') --> 4。
133
+
134
+ :param ls:
135
+ 要处理的列表,会对所有元素调用str处理,确保全部转为string类型
136
+ 且会将换行符转为\n显示
137
+ :param fmt: (format)
138
+ l: left,左对齐
139
+ c: center,居中
140
+ r: right,右对齐
141
+ 多个字符: 扩展fmt长度跟ls一样,每一个元素单独设置对齐格式。如果fmt长度小于ls,则扩展的格式按照fmt[-1]设置
142
+ :param width:
143
+ None或者设置值小于最长字符串: 不设域宽,直接按照最长的字符串为准
144
+ :param fillchar: 填充字符
145
+ :param prefix: 添加前缀
146
+ :param suffix: 添加后缀
147
+ :param chinese_char_width: 每个汉字字符宽度
148
+
149
+ :return:
150
+ 对齐后的数组ls,每个元素会转为str类型
151
+
152
+ >>> listalign(['a', '哈哈', 'ccd'])
153
+ [' a', '哈哈', ' ccd']
154
+ >>> listalign(['a', '哈哈', 'ccd'], chinese_char_width=1.8)
155
+ [' a', '   哈哈', ' ccd']
156
+ """
157
+ # 1 处理fmt数组
158
+ if len(fmt) == 1:
159
+ fmt = [fmt] * len(ls)
160
+ elif len(fmt) < len(ls):
161
+ fmt = list(fmt) + [fmt[-1]] * (len(ls) - len(fmt))
162
+
163
+ # 2 算出需要域宽
164
+ if chinese_char_width == 2:
165
+ strs = [str(x).replace('\n', r'\n') for x in ls] # 存储转成字符串的元素
166
+ lens = [strwidth(x) for x in strs] # 存储每个元素的实际域宽
167
+ else:
168
+ strs = [] # 存储转成字符串的元素
169
+ lens = [] # 存储每个元素的实际域宽
170
+ for i, t in enumerate(ls):
171
+ t, n = strwidth_proc(t, fmt[i], chinese_char_width)
172
+ strs.append(t)
173
+ lens.append(n)
174
+ w = max(lens)
175
+ if width and isinstance(width, int) and width > w:
176
+ w = width
177
+
178
+ # 3 对齐操作
179
+ for i, s in enumerate(strs):
180
+ if fmt[i] == 'r':
181
+ strs[i] = fillchar * (w - lens[i]) + strs[i]
182
+ elif fmt[i] == 'l':
183
+ strs[i] = strs[i] + fillchar * (w - lens[i])
184
+ elif fmt[i] == 'c':
185
+ t = w - lens[i]
186
+ strs[i] = fillchar * (t - t // 2) + strs[i] + fillchar * (t // 2)
187
+ strs[i] = prefix + strs[i] + suffix
188
+ return strs
189
+
190
+
191
+ def arr_hangclear(arr, depth=None):
192
+ """ 清除连续相同值,简化表格内容
193
+ >> arr_hangclear(arr, depth=2)
194
+ 原表格:
195
+ A B D
196
+ A B E
197
+ A C E
198
+ A C E
199
+ 新表格:
200
+ A B D
201
+ E
202
+ C E
203
+ E
204
+
205
+ :param arr: 二维数组
206
+ :param depth: 处理列上限
207
+ 例如depth=1,则只处理第一层
208
+ depth=None,则处理所有列
209
+
210
+ >>> arr_hangclear([[1, 2, 4], [1, 2, 5], [1, 3, 5], [1, 3, 5]])
211
+ [[1, 2, 4], ['', '', 5], ['', 3, 5], ['', '', 5]]
212
+ >>> arr_hangclear([[1, 2, 4], [1, 2, 5], [2, 2, 5], [1, 2, 5]])
213
+ [[1, 2, 4], ['', '', 5], [2, 2, 5], [1, 2, 5]]
214
+ """
215
+ m = depth or len_in_dim2(arr) - 1
216
+ a = copy.deepcopy(arr)
217
+
218
+ # 算法原理:从下到上,从右到左判断与上一行重叠了几列数据
219
+ for i in range(len(arr) - 1, 0, -1):
220
+ for j in range(m):
221
+ if a[i][j] == a[i - 1][j]:
222
+ a[i][j] = ''
223
+ else:
224
+ break
225
+ return a
226
+
227
+
228
+ def arr2table(arr, rowmerge=False):
229
+ """ 数组转html表格代码
230
+
231
+ :param arr: 需要处理的数组
232
+ :param rowmerge: 行单元格合并
233
+ :return: html文本格式的<table>
234
+
235
+ 这个arr2table是用来画合并单元格的
236
+ >> browser(arr2table([['A', 1, 'a'], ['', 2, 'b'], ['B', 3, 'c'], ['', '', 'd'], ['', 5, 'e']], True), 'a.html')
237
+ 效果图:http://i1.fuimg.com/582188/c452f40b5a072f8d.png
238
+ """
239
+ n = len(arr)
240
+ m = len_in_dim2(arr)
241
+ res = ['<table border="1"><tbody>']
242
+ for i, line in enumerate(arr):
243
+ res.append('<tr>')
244
+ for j, ele in enumerate(line):
245
+ if rowmerge:
246
+ if ele != '':
247
+ cnt = 1
248
+ while i + cnt < n and arr[i + cnt][j] == '':
249
+ for k in range(j - 1, -1, -1):
250
+ if arr[i + cnt][k] != '':
251
+ break
252
+ else:
253
+ cnt += 1
254
+ continue
255
+ break
256
+ if cnt > 1:
257
+ res.append(f'<td rowspan="{cnt}">{ele}</td>')
258
+ else:
259
+ res.append(f'<td>{ele}</td>')
260
+ elif j == m - 1:
261
+ res.append(f'<td>{ele}</td>')
262
+ else:
263
+ res.append(f'<td>{ele}</td>')
264
+ res.append('</tr>')
265
+ res.append('</tbody></table>')
266
+ return ''.join(res)
267
+
268
+
269
+ def east_asian_len(s, ambiguous_width=None):
270
+ import pandas.io.formats.format as fmt
271
+ return fmt.EastAsianTextAdjustment().len(s)
272
+
273
+
274
+ def east_asian_shorten(s, width=50, placeholder='...'):
275
+ """考虑中文情况下的域宽截断
276
+
277
+ :param s: 要处理的字符串
278
+ :param width: 宽度上限,仅能达到width-1的宽度
279
+ :param placeholder: 如果做了截断,末尾补足字符
280
+
281
+ # width比placeholder还小
282
+ >>> east_asian_shorten('a', 2)
283
+ 'a'
284
+ >>> east_asian_shorten('a啊b'*4, 3)
285
+ '..'
286
+ >>> east_asian_shorten('a啊b'*4, 4)
287
+ '...'
288
+
289
+ >>> east_asian_shorten('a啊b'*4, 5, '...')
290
+ 'a...'
291
+ >>> east_asian_shorten('a啊b'*4, 11)
292
+ 'a啊ba啊...'
293
+ >>> east_asian_shorten('a啊b'*4, 16, '...')
294
+ 'a啊ba啊ba啊b...'
295
+ >>> east_asian_shorten('a啊b'*4, 18, '...')
296
+ 'a啊ba啊ba啊ba啊b'
297
+ """
298
+ # 一、如果字符串本身不到width设限,返回原值
299
+ s = textwrap.shorten(s, width * 3, placeholder='') # 用textwrap的折行功能,尽量不删除文本
300
+ n = east_asian_len(s)
301
+ if n < width: return s
302
+
303
+ # 二、如果输入的width比placeholder还短
304
+ width -= 1
305
+ m = east_asian_len(placeholder)
306
+ if width <= m:
307
+ return placeholder[:width]
308
+
309
+ # 三、需要添加 placeholder
310
+ # 1 计算长度
311
+ width -= m
312
+
313
+ # 2 截取s
314
+ try:
315
+ s = s.encode('gbk')[:width].decode('gbk', errors='ignore')
316
+ except UnicodeEncodeError:
317
+ i, count = 0, m
318
+ while i < n and count <= width:
319
+ if ord(s[i]) > 127:
320
+ count += 2
321
+ else:
322
+ count += 1
323
+ i += 1
324
+ s = s[:i]
325
+
326
+ return s + placeholder