OcrRecApplicationTests.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. // package com.pavis.rec.ocrrec;
  2. //
  3. // import com.alibaba.fastjson.JSON;
  4. // import com.alibaba.fastjson.JSONArray;
  5. // import com.alibaba.fastjson.JSONObject;
  6. // import com.pavis.rec.ocrrec.common.config.OcrRecConstants;
  7. // import com.pavis.rec.ocrrec.common.utils.AipOcrUtils;
  8. // import com.pavis.rec.ocrrec.common.utils.TransApiUtils;
  9. // import com.pavis.rec.ocrrec.dto.ResRecInfo;
  10. // import com.pavis.rec.ocrrec.mapper.MailTypesMapper;
  11. // import com.pavis.rec.ocrrec.model.MailTypes;
  12. // import com.pavis.rec.ocrrec.service.OcrRecService;
  13. // import lombok.extern.slf4j.Slf4j;
  14. // import org.apache.commons.lang3.StringUtils;
  15. // import org.junit.Test;
  16. // import org.junit.runner.RunWith;
  17. // import org.springframework.beans.factory.annotation.Autowired;
  18. // import org.springframework.boot.test.context.SpringBootTest;
  19. // import org.springframework.test.context.junit4.SpringRunner;
  20. //
  21. // import java.util.ArrayList;
  22. // import java.util.HashMap;
  23. // import java.util.List;
  24. // import java.util.Map;
  25. //
  26. // @Slf4j
  27. // @RunWith(SpringRunner.class)
  28. // @SpringBootTest
  29. // public class OcrRecApplicationTests {
  30. //
  31. // @Autowired
  32. // private MailTypesMapper mailTypesMapper;
  33. //
  34. // @Autowired
  35. // private OcrRecService ocrRecService;
  36. //
  37. // @Test
  38. // public void testMail(){
  39. // // List<String> strs = ocrRecService.mails();
  40. // // List<String> strs = new ArrayList<>();
  41. // // strs.add("Priority Mail");
  42. // // strs.add("Postal Parcel");
  43. // // strs.add("Custom Declaration(CN23)invoice");
  44. // // strs.add("Postnl EMS");
  45. // // strs.add("EMS-ChungHwa");
  46. // // strs.add("EMS-EK");
  47. // // strs.add("EMS-Japan");
  48. // // strs.add("EMS-Japan Post");
  49. // // strs.add("EMS-Korea");
  50. // // strs.add("EMS-Malaysia");
  51. // // strs.add("CN22 customs declaration");
  52. // // strs.add("中华邮政");
  53. // // strs.add("Royal Mail");
  54. // // for (String str : strs) {
  55. // // MailTypes mailTypes = MailTypes.builder()
  56. // // .mailType(str)
  57. // // .isUsed("0")
  58. // // .build();
  59. // // mailTypesMapper.insert(mailTypes);
  60. // // }
  61. //
  62. //
  63. // // MailTypes mailTypes = mailTypesMapper.selectById("1216603053680066562");
  64. // // System.err.println(JSON.toJSONString(mailTypes));
  65. //
  66. // }
  67. //
  68. // @Test
  69. // public void testRec(){
  70. // // AipOcrUtils.rec(AipOcrUtils.initAipOcr());
  71. // String result = getResult();
  72. // JSONObject jsonObject = JSONObject.parseObject(result);
  73. // JSONArray jsonArray = JSONArray.parseArray(JSONObject.parseObject(jsonObject.get("data").toString()).get("ret").toString());
  74. // System.out.println(JSON.toJSONString(jsonArray));
  75. // List<ResRecInfo> resRecInfos = new ArrayList<>();
  76. // ResRecInfo resRecInfo;
  77. // resRecInfo = ResRecInfo.builder()
  78. // .fromInfo(JSONObject.parseObject(jsonArray.get(0).toString()).get("word").toString())
  79. // .toInfo(JSONObject.parseObject(jsonArray.get(1).toString()).get("word").toString())
  80. // .build();
  81. // System.err.println(JSON.toJSONString(resRecInfo));
  82. // }
  83. //
  84. // public String getResult(){
  85. // return "{\n" +
  86. // " \"log_id\": \"157775667218958\",\n" +
  87. // " \"error_msg\": \"\",\n" +
  88. // " \"data\": {\n" +
  89. // " \"ret\": [\n" +
  90. // " {\n" +
  91. // " \"probability\": {\n" +
  92. // " \"average\": 1,\n" +
  93. // " \"min\": 1,\n" +
  94. // " \"variance\": 0\n" +
  95. // " },\n" +
  96. // " \"location\": {\n" +
  97. // " \"top\": 180,\n" +
  98. // " \"left\": 1171,\n" +
  99. // " \"width\": 255,\n" +
  100. // " \"height\": 682\n" +
  101. // " },\n" +
  102. // " \"word_name\": \"from_info\",\n" +
  103. // " \"word\": \"626-455-0558SUNING U1N23I0T DS ANTA ANITE AVE OUTH EL MONTE CA 91733 SUnited States\"\n" +
  104. // " },\n" +
  105. // " {\n" +
  106. // " \"probability\": {\n" +
  107. // " \"average\": 1,\n" +
  108. // " \"min\": 1,\n" +
  109. // " \"variance\": 0\n" +
  110. // " },\n" +
  111. // " \"location\": {\n" +
  112. // " \"top\": 264,\n" +
  113. // " \"left\": 98,\n" +
  114. // " \"width\": 206,\n" +
  115. // " \"height\": 947\n" +
  116. // " },\n" +
  117. // " \"word_name\": \"to_info\",\n" +
  118. // " \"word\": \"BGang Xu 13512111418ei Ai Lu 1200 Nong 3 Hao 502 Shi SN10685467617 Shang Hai Shi Shang Hai 201210 CHINA\"\n" +
  119. // " }\n" +
  120. // " ],\n" +
  121. // " \"templateSign\": \"b7bfd701206d66e5942a56a9fa67532d\",\n" +
  122. // " \"templateName\": \"20190624_014052\",\n" +
  123. // " \"scores\": 1,\n" +
  124. // " \"isStructured\": true,\n" +
  125. // " \"logId\": \"157775667218958\",\n" +
  126. // " \"templateMatchDegree\": 0.9748448714269653,\n" +
  127. // " \"clockwiseAngle\": 269.83\n" +
  128. // " },\n" +
  129. // " \"error_code\": 0\n" +
  130. // "}";
  131. // }
  132. //
  133. // @Test
  134. // public void testTranslate(){
  135. // JSONObject resJson = JSONObject.parseObject(TransApiUtils.transEnToZh("hello"));
  136. // JSONArray resArr = JSONArray.parseArray(resJson.get("trans_result").toString());
  137. // JSONObject res = JSONObject.parseObject(resArr.get(0).toString());
  138. // System.out.println(res.get("dst"));
  139. // }
  140. //
  141. // @Test
  142. // public void testStr(){
  143. // String name = "Gang Xu";
  144. // String tel = "13512111418";
  145. // String info = "Gang Xu 13512111418120 0 Nong Hao 502 BSehii ASiN 1L0u6 85467617 Shang Hai Shi Shang Hai 201210 CHINAS Form 2976-A-";
  146. // String[] repeat = {name,tel};
  147. // // System.err.println(StringUtils.replaceEachRepeatedly(info,repeat,repeat));
  148. // System.err.println(StringUtils.remove(StringUtils.remove(info,name),tel));
  149. //
  150. // }
  151. //
  152. // @Test
  153. // public void testResP(){
  154. // JSONObject jsonObject = JSONObject.parseObject(getResultP());
  155. // System.err.println(jsonObject);
  156. // JSONArray resArr = JSON.parseArray(JSONObject.parseObject(jsonObject.get("data").toString()).get("ret").toString());
  157. // Map<String,Object> map = new HashMap<>();
  158. // for (Object o : resArr) {
  159. // JSONObject j = (JSONObject)o;
  160. // if (j.get("word_name").equals("from_addr")){
  161. // map.put("from_addr",j.get("word"));
  162. // }
  163. //
  164. // if (j.get("word_name").equals("from_tel")){
  165. // map.put("from_tel",j.get("word"));
  166. // }
  167. //
  168. // if (j.get("word_name").equals("to_addr")){
  169. // map.put("to_addr",j.get("word"));
  170. // }
  171. //
  172. // if (j.get("word_name").equals("to_zh")){
  173. // map.put("to_zh",j.get("word"));
  174. // }
  175. //
  176. // if (j.get("word_name").equals("to_name")){
  177. // map.put("to_name",j.get("word"));
  178. // }
  179. //
  180. // if (j.get("word_name").equals("from_info")){
  181. // map.put("from_info",j.get("word"));
  182. // }
  183. //
  184. // if (j.get("word_name").equals("to_info")){
  185. // map.put("to_info",j.get("word"));
  186. // }
  187. //
  188. // if (j.get("word_name").equals("from_name")){
  189. // map.put("from_name",j.get("word"));
  190. // }
  191. //
  192. // if (j.get("word_name").equals("to_tel")){
  193. // map.put("to_tel",j.get("word"));
  194. // }
  195. // }
  196. // ResRecInfo resRecInfo = ResRecInfo.builder()
  197. // .imgUrl("hhtp:***.***.***.***/rec/1.jpg")
  198. // .fromName(map.get("from_name").toString())
  199. // .fromZhName(map.get("from_name").toString())
  200. // .fromTel(map.get("from_tel").toString())
  201. // .fromInfo(map.get("from_info").toString())
  202. // .fromZhAddr(StringUtils.remove(StringUtils.remove(map.get("from_info").toString(),map.get("from_name").toString()),map.get("from_tel").toString()))
  203. // .toName(map.get("to_name").toString())
  204. // .toZhName(map.get("to_name").toString())
  205. // .toTel(map.get("to_tel").toString())
  206. // .toInfo(StringUtils.remove(StringUtils.remove(map.get("to_info").toString(),map.get("to_name").toString()),map.get("to_tel").toString()))
  207. // .toZhAddr(map.get("to_info").toString())
  208. // .build();
  209. // System.err.println(JSON.toJSONString(resRecInfo));
  210. // }
  211. //
  212. // public String getResultP(){
  213. // return "{\n" +
  214. // " \"log_id\": \"157777134713797\",\n" +
  215. // " \"error_msg\": \"\",\n" +
  216. // " \"data\": {\n" +
  217. // " \"ret\": [\n" +
  218. // " {\n" +
  219. // " \"probability\": {\n" +
  220. // " \"average\": 1,\n" +
  221. // " \"min\": 1,\n" +
  222. // " \"variance\": 0\n" +
  223. // " },\n" +
  224. // " \"location\": {\n" +
  225. // " \"top\": 196,\n" +
  226. // " \"left\": 1215,\n" +
  227. // " \"width\": 115,\n" +
  228. // " \"height\": 525\n" +
  229. // " },\n" +
  230. // " \"word_name\": \"from_addr\",\n" +
  231. // " \"word\": \"70 TURNBULL CANYON RD ITY OF INDUSTRY CA 91745-1009 United States\"\n" +
  232. // " },\n" +
  233. // " {\n" +
  234. // " \"probability\": {\n" +
  235. // " \"average\": 1,\n" +
  236. // " \"min\": 1,\n" +
  237. // " \"variance\": 0\n" +
  238. // " },\n" +
  239. // " \"location\": {\n" +
  240. // " \"top\": 282,\n" +
  241. // " \"left\": 79,\n" +
  242. // " \"width\": 203,\n" +
  243. // " \"height\": 587\n" +
  244. // " },\n" +
  245. // " \"word_name\": \"to_addr\",\n" +
  246. // " \"word\": \"Room 303, Building 2, Lane 76 Yuzhong Road, Xiqiao Town, Qingpu District,Shanghai, China Shanghai Shanghai 200000 CHINA\"\n" +
  247. // " },\n" +
  248. // " {\n" +
  249. // " \"probability\": {\n" +
  250. // " \"average\": 0.985547,\n" +
  251. // " \"min\": 0.889448,\n" +
  252. // " \"variance\": 9.97E-4\n" +
  253. // " },\n" +
  254. // " \"location\": {\n" +
  255. // " \"top\": 604,\n" +
  256. // " \"left\": 1390,\n" +
  257. // " \"width\": 50,\n" +
  258. // " \"height\": 276\n" +
  259. // " },\n" +
  260. // " \"word_name\": \"from_tel\",\n" +
  261. // " \"word\": \"626-855-3088\"\n" +
  262. // " },\n" +
  263. // " {\n" +
  264. // " \"probability\": {\n" +
  265. // " \"average\": 0.996893,\n" +
  266. // " \"min\": 0.961107,\n" +
  267. // " \"variance\": 7.8E-5\n" +
  268. // " },\n" +
  269. // " \"location\": {\n" +
  270. // " \"top\": 277,\n" +
  271. // " \"left\": 320,\n" +
  272. // " \"width\": 104,\n" +
  273. // " \"height\": 931\n" +
  274. // " },\n" +
  275. // " \"word_name\": \"to_zh\",\n" +
  276. // " \"word\": \"上海上海市青浦区西岑镇岑中路76弄2号楼303室青浦区西岑镇中路76弄2号楼303室\"\n" +
  277. // " },\n" +
  278. // " {\n" +
  279. // " \"probability\": {\n" +
  280. // " \"average\": 1,\n" +
  281. // " \"min\": 1,\n" +
  282. // " \"variance\": 0\n" +
  283. // " },\n" +
  284. // " \"location\": {\n" +
  285. // " \"top\": 276,\n" +
  286. // " \"left\": 265,\n" +
  287. // " \"width\": 43,\n" +
  288. // " \"height\": 189\n" +
  289. // " },\n" +
  290. // " \"word_name\": \"to_name\",\n" +
  291. // " \"word\": \"Song Luo.\"\n" +
  292. // " },\n" +
  293. // " {\n" +
  294. // " \"probability\": {\n" +
  295. // " \"average\": 1,\n" +
  296. // " \"min\": 1,\n" +
  297. // " \"variance\": 0\n" +
  298. // " },\n" +
  299. // " \"location\": {\n" +
  300. // " \"top\": 192,\n" +
  301. // " \"left\": 1215,\n" +
  302. // " \"width\": 227,\n" +
  303. // " \"height\": 688\n" +
  304. // " },\n" +
  305. // " \"word_name\": \"from_info\",\n" +
  306. // " \"word\": \"626-855-3088W7ORLD CPS INC I0 TURNBULL CANYON RD TY OF INDUSTRY CA 91745-1009 United States\"\n" +
  307. // " },\n" +
  308. // " {\n" +
  309. // " \"probability\": {\n" +
  310. // " \"average\": 1,\n" +
  311. // " \"min\": 1,\n" +
  312. // " \"variance\": 0\n" +
  313. // " },\n" +
  314. // " \"location\": {\n" +
  315. // " \"top\": 276,\n" +
  316. // " \"left\": 78,\n" +
  317. // " \"width\": 346,\n" +
  318. // " \"height\": 932\n" +
  319. // " },\n" +
  320. // " \"word_name\": \"to_info\",\n" +
  321. // " \"word\": \"上海上海市青浦区西岑镇岑中路76弄2号楼303室青浦区西岑镇中路76弄2号楼303室Song Luo. 1366189944Room 303, Building 2, Lane 76 Yuzhong Road, Xiqiao Town, Qingpu District,Shanghai, China Shanghai Shanghai 200000 CHINA\"\n" +
  322. // " },\n" +
  323. // " {\n" +
  324. // " \"probability\": {\n" +
  325. // " \"average\": 1,\n" +
  326. // " \"min\": 1,\n" +
  327. // " \"variance\": 0\n" +
  328. // " },\n" +
  329. // " \"location\": {\n" +
  330. // " \"top\": 209,\n" +
  331. // " \"left\": 1320,\n" +
  332. // " \"width\": 42,\n" +
  333. // " \"height\": 234\n" +
  334. // " },\n" +
  335. // " \"word_name\": \"from_name\",\n" +
  336. // " \"word\": \"ORLD CPS INC\"\n" +
  337. // " },\n" +
  338. // " {\n" +
  339. // " \"probability\": {\n" +
  340. // " \"average\": 0.997706,\n" +
  341. // " \"min\": 0.986069,\n" +
  342. // " \"variance\": 1.7E-5\n" +
  343. // " },\n" +
  344. // " \"location\": {\n" +
  345. // " \"top\": 967,\n" +
  346. // " \"left\": 284,\n" +
  347. // " \"width\": 47,\n" +
  348. // " \"height\": 223\n" +
  349. // " },\n" +
  350. // " \"word_name\": \"to_tel\",\n" +
  351. // " \"word\": \"1366189944\"\n" +
  352. // " }\n" +
  353. // " ],\n" +
  354. // " \"templateSign\": \"5aab7664cc5497d2f6f75ce99f1b133b\",\n" +
  355. // " \"templateName\": \"20190622_105813\",\n" +
  356. // " \"scores\": 1,\n" +
  357. // " \"isStructured\": true,\n" +
  358. // " \"logId\": \"157777134713797\",\n" +
  359. // " \"templateMatchDegree\": 0.9929515290405418,\n" +
  360. // " \"clockwiseAngle\": 269.81\n" +
  361. // " },\n" +
  362. // " \"error_code\": 0\n" +
  363. // "}";
  364. // }
  365. //
  366. // }