| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- // package com.pavis.rec.ocrrec;
- //
- // import com.alibaba.fastjson.JSON;
- // import com.alibaba.fastjson.JSONArray;
- // import com.alibaba.fastjson.JSONObject;
- // import com.pavis.rec.ocrrec.common.config.OcrRecConstants;
- // import com.pavis.rec.ocrrec.common.utils.AipOcrUtils;
- // import com.pavis.rec.ocrrec.common.utils.TransApiUtils;
- // import com.pavis.rec.ocrrec.dto.ResRecInfo;
- // import com.pavis.rec.ocrrec.mapper.MailTypesMapper;
- // import com.pavis.rec.ocrrec.model.MailTypes;
- // import com.pavis.rec.ocrrec.service.OcrRecService;
- // import lombok.extern.slf4j.Slf4j;
- // import org.apache.commons.lang3.StringUtils;
- // import org.junit.Test;
- // import org.junit.runner.RunWith;
- // import org.springframework.beans.factory.annotation.Autowired;
- // import org.springframework.boot.test.context.SpringBootTest;
- // import org.springframework.test.context.junit4.SpringRunner;
- //
- // import java.util.ArrayList;
- // import java.util.HashMap;
- // import java.util.List;
- // import java.util.Map;
- //
- // @Slf4j
- // @RunWith(SpringRunner.class)
- // @SpringBootTest
- // public class OcrRecApplicationTests {
- //
- // @Autowired
- // private MailTypesMapper mailTypesMapper;
- //
- // @Autowired
- // private OcrRecService ocrRecService;
- //
- // @Test
- // public void testMail(){
- // // List<String> strs = ocrRecService.mails();
- // // List<String> strs = new ArrayList<>();
- // // strs.add("Priority Mail");
- // // strs.add("Postal Parcel");
- // // strs.add("Custom Declaration(CN23)invoice");
- // // strs.add("Postnl EMS");
- // // strs.add("EMS-ChungHwa");
- // // strs.add("EMS-EK");
- // // strs.add("EMS-Japan");
- // // strs.add("EMS-Japan Post");
- // // strs.add("EMS-Korea");
- // // strs.add("EMS-Malaysia");
- // // strs.add("CN22 customs declaration");
- // // strs.add("中华邮政");
- // // strs.add("Royal Mail");
- // // for (String str : strs) {
- // // MailTypes mailTypes = MailTypes.builder()
- // // .mailType(str)
- // // .isUsed("0")
- // // .build();
- // // mailTypesMapper.insert(mailTypes);
- // // }
- //
- //
- // // MailTypes mailTypes = mailTypesMapper.selectById("1216603053680066562");
- // // System.err.println(JSON.toJSONString(mailTypes));
- //
- // }
- //
- // @Test
- // public void testRec(){
- // // AipOcrUtils.rec(AipOcrUtils.initAipOcr());
- // String result = getResult();
- // JSONObject jsonObject = JSONObject.parseObject(result);
- // JSONArray jsonArray = JSONArray.parseArray(JSONObject.parseObject(jsonObject.get("data").toString()).get("ret").toString());
- // System.out.println(JSON.toJSONString(jsonArray));
- // List<ResRecInfo> resRecInfos = new ArrayList<>();
- // ResRecInfo resRecInfo;
- // resRecInfo = ResRecInfo.builder()
- // .fromInfo(JSONObject.parseObject(jsonArray.get(0).toString()).get("word").toString())
- // .toInfo(JSONObject.parseObject(jsonArray.get(1).toString()).get("word").toString())
- // .build();
- // System.err.println(JSON.toJSONString(resRecInfo));
- // }
- //
- // public String getResult(){
- // return "{\n" +
- // " \"log_id\": \"157775667218958\",\n" +
- // " \"error_msg\": \"\",\n" +
- // " \"data\": {\n" +
- // " \"ret\": [\n" +
- // " {\n" +
- // " \"probability\": {\n" +
- // " \"average\": 1,\n" +
- // " \"min\": 1,\n" +
- // " \"variance\": 0\n" +
- // " },\n" +
- // " \"location\": {\n" +
- // " \"top\": 180,\n" +
- // " \"left\": 1171,\n" +
- // " \"width\": 255,\n" +
- // " \"height\": 682\n" +
- // " },\n" +
- // " \"word_name\": \"from_info\",\n" +
- // " \"word\": \"626-455-0558SUNING U1N23I0T DS ANTA ANITE AVE OUTH EL MONTE CA 91733 SUnited States\"\n" +
- // " },\n" +
- // " {\n" +
- // " \"probability\": {\n" +
- // " \"average\": 1,\n" +
- // " \"min\": 1,\n" +
- // " \"variance\": 0\n" +
- // " },\n" +
- // " \"location\": {\n" +
- // " \"top\": 264,\n" +
- // " \"left\": 98,\n" +
- // " \"width\": 206,\n" +
- // " \"height\": 947\n" +
- // " },\n" +
- // " \"word_name\": \"to_info\",\n" +
- // " \"word\": \"BGang Xu 13512111418ei Ai Lu 1200 Nong 3 Hao 502 Shi SN10685467617 Shang Hai Shi Shang Hai 201210 CHINA\"\n" +
- // " }\n" +
- // " ],\n" +
- // " \"templateSign\": \"b7bfd701206d66e5942a56a9fa67532d\",\n" +
- // " \"templateName\": \"20190624_014052\",\n" +
- // " \"scores\": 1,\n" +
- // " \"isStructured\": true,\n" +
- // " \"logId\": \"157775667218958\",\n" +
- // " \"templateMatchDegree\": 0.9748448714269653,\n" +
- // " \"clockwiseAngle\": 269.83\n" +
- // " },\n" +
- // " \"error_code\": 0\n" +
- // "}";
- // }
- //
- // @Test
- // public void testTranslate(){
- // JSONObject resJson = JSONObject.parseObject(TransApiUtils.transEnToZh("hello"));
- // JSONArray resArr = JSONArray.parseArray(resJson.get("trans_result").toString());
- // JSONObject res = JSONObject.parseObject(resArr.get(0).toString());
- // System.out.println(res.get("dst"));
- // }
- //
- // @Test
- // public void testStr(){
- // String name = "Gang Xu";
- // String tel = "13512111418";
- // String info = "Gang Xu 13512111418120 0 Nong Hao 502 BSehii ASiN 1L0u6 85467617 Shang Hai Shi Shang Hai 201210 CHINAS Form 2976-A-";
- // String[] repeat = {name,tel};
- // // System.err.println(StringUtils.replaceEachRepeatedly(info,repeat,repeat));
- // System.err.println(StringUtils.remove(StringUtils.remove(info,name),tel));
- //
- // }
- //
- // @Test
- // public void testResP(){
- // JSONObject jsonObject = JSONObject.parseObject(getResultP());
- // System.err.println(jsonObject);
- // JSONArray resArr = JSON.parseArray(JSONObject.parseObject(jsonObject.get("data").toString()).get("ret").toString());
- // Map<String,Object> map = new HashMap<>();
- // for (Object o : resArr) {
- // JSONObject j = (JSONObject)o;
- // if (j.get("word_name").equals("from_addr")){
- // map.put("from_addr",j.get("word"));
- // }
- //
- // if (j.get("word_name").equals("from_tel")){
- // map.put("from_tel",j.get("word"));
- // }
- //
- // if (j.get("word_name").equals("to_addr")){
- // map.put("to_addr",j.get("word"));
- // }
- //
- // if (j.get("word_name").equals("to_zh")){
- // map.put("to_zh",j.get("word"));
- // }
- //
- // if (j.get("word_name").equals("to_name")){
- // map.put("to_name",j.get("word"));
- // }
- //
- // if (j.get("word_name").equals("from_info")){
- // map.put("from_info",j.get("word"));
- // }
- //
- // if (j.get("word_name").equals("to_info")){
- // map.put("to_info",j.get("word"));
- // }
- //
- // if (j.get("word_name").equals("from_name")){
- // map.put("from_name",j.get("word"));
- // }
- //
- // if (j.get("word_name").equals("to_tel")){
- // map.put("to_tel",j.get("word"));
- // }
- // }
- // ResRecInfo resRecInfo = ResRecInfo.builder()
- // .imgUrl("hhtp:***.***.***.***/rec/1.jpg")
- // .fromName(map.get("from_name").toString())
- // .fromZhName(map.get("from_name").toString())
- // .fromTel(map.get("from_tel").toString())
- // .fromInfo(map.get("from_info").toString())
- // .fromZhAddr(StringUtils.remove(StringUtils.remove(map.get("from_info").toString(),map.get("from_name").toString()),map.get("from_tel").toString()))
- // .toName(map.get("to_name").toString())
- // .toZhName(map.get("to_name").toString())
- // .toTel(map.get("to_tel").toString())
- // .toInfo(StringUtils.remove(StringUtils.remove(map.get("to_info").toString(),map.get("to_name").toString()),map.get("to_tel").toString()))
- // .toZhAddr(map.get("to_info").toString())
- // .build();
- // System.err.println(JSON.toJSONString(resRecInfo));
- // }
- //
- // public String getResultP(){
- // return "{\n" +
- // " \"log_id\": \"157777134713797\",\n" +
- // " \"error_msg\": \"\",\n" +
- // " \"data\": {\n" +
- // " \"ret\": [\n" +
- // " {\n" +
- // " \"probability\": {\n" +
- // " \"average\": 1,\n" +
- // " \"min\": 1,\n" +
- // " \"variance\": 0\n" +
- // " },\n" +
- // " \"location\": {\n" +
- // " \"top\": 196,\n" +
- // " \"left\": 1215,\n" +
- // " \"width\": 115,\n" +
- // " \"height\": 525\n" +
- // " },\n" +
- // " \"word_name\": \"from_addr\",\n" +
- // " \"word\": \"70 TURNBULL CANYON RD ITY OF INDUSTRY CA 91745-1009 United States\"\n" +
- // " },\n" +
- // " {\n" +
- // " \"probability\": {\n" +
- // " \"average\": 1,\n" +
- // " \"min\": 1,\n" +
- // " \"variance\": 0\n" +
- // " },\n" +
- // " \"location\": {\n" +
- // " \"top\": 282,\n" +
- // " \"left\": 79,\n" +
- // " \"width\": 203,\n" +
- // " \"height\": 587\n" +
- // " },\n" +
- // " \"word_name\": \"to_addr\",\n" +
- // " \"word\": \"Room 303, Building 2, Lane 76 Yuzhong Road, Xiqiao Town, Qingpu District,Shanghai, China Shanghai Shanghai 200000 CHINA\"\n" +
- // " },\n" +
- // " {\n" +
- // " \"probability\": {\n" +
- // " \"average\": 0.985547,\n" +
- // " \"min\": 0.889448,\n" +
- // " \"variance\": 9.97E-4\n" +
- // " },\n" +
- // " \"location\": {\n" +
- // " \"top\": 604,\n" +
- // " \"left\": 1390,\n" +
- // " \"width\": 50,\n" +
- // " \"height\": 276\n" +
- // " },\n" +
- // " \"word_name\": \"from_tel\",\n" +
- // " \"word\": \"626-855-3088\"\n" +
- // " },\n" +
- // " {\n" +
- // " \"probability\": {\n" +
- // " \"average\": 0.996893,\n" +
- // " \"min\": 0.961107,\n" +
- // " \"variance\": 7.8E-5\n" +
- // " },\n" +
- // " \"location\": {\n" +
- // " \"top\": 277,\n" +
- // " \"left\": 320,\n" +
- // " \"width\": 104,\n" +
- // " \"height\": 931\n" +
- // " },\n" +
- // " \"word_name\": \"to_zh\",\n" +
- // " \"word\": \"上海上海市青浦区西岑镇岑中路76弄2号楼303室青浦区西岑镇中路76弄2号楼303室\"\n" +
- // " },\n" +
- // " {\n" +
- // " \"probability\": {\n" +
- // " \"average\": 1,\n" +
- // " \"min\": 1,\n" +
- // " \"variance\": 0\n" +
- // " },\n" +
- // " \"location\": {\n" +
- // " \"top\": 276,\n" +
- // " \"left\": 265,\n" +
- // " \"width\": 43,\n" +
- // " \"height\": 189\n" +
- // " },\n" +
- // " \"word_name\": \"to_name\",\n" +
- // " \"word\": \"Song Luo.\"\n" +
- // " },\n" +
- // " {\n" +
- // " \"probability\": {\n" +
- // " \"average\": 1,\n" +
- // " \"min\": 1,\n" +
- // " \"variance\": 0\n" +
- // " },\n" +
- // " \"location\": {\n" +
- // " \"top\": 192,\n" +
- // " \"left\": 1215,\n" +
- // " \"width\": 227,\n" +
- // " \"height\": 688\n" +
- // " },\n" +
- // " \"word_name\": \"from_info\",\n" +
- // " \"word\": \"626-855-3088W7ORLD CPS INC I0 TURNBULL CANYON RD TY OF INDUSTRY CA 91745-1009 United States\"\n" +
- // " },\n" +
- // " {\n" +
- // " \"probability\": {\n" +
- // " \"average\": 1,\n" +
- // " \"min\": 1,\n" +
- // " \"variance\": 0\n" +
- // " },\n" +
- // " \"location\": {\n" +
- // " \"top\": 276,\n" +
- // " \"left\": 78,\n" +
- // " \"width\": 346,\n" +
- // " \"height\": 932\n" +
- // " },\n" +
- // " \"word_name\": \"to_info\",\n" +
- // " \"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" +
- // " },\n" +
- // " {\n" +
- // " \"probability\": {\n" +
- // " \"average\": 1,\n" +
- // " \"min\": 1,\n" +
- // " \"variance\": 0\n" +
- // " },\n" +
- // " \"location\": {\n" +
- // " \"top\": 209,\n" +
- // " \"left\": 1320,\n" +
- // " \"width\": 42,\n" +
- // " \"height\": 234\n" +
- // " },\n" +
- // " \"word_name\": \"from_name\",\n" +
- // " \"word\": \"ORLD CPS INC\"\n" +
- // " },\n" +
- // " {\n" +
- // " \"probability\": {\n" +
- // " \"average\": 0.997706,\n" +
- // " \"min\": 0.986069,\n" +
- // " \"variance\": 1.7E-5\n" +
- // " },\n" +
- // " \"location\": {\n" +
- // " \"top\": 967,\n" +
- // " \"left\": 284,\n" +
- // " \"width\": 47,\n" +
- // " \"height\": 223\n" +
- // " },\n" +
- // " \"word_name\": \"to_tel\",\n" +
- // " \"word\": \"1366189944\"\n" +
- // " }\n" +
- // " ],\n" +
- // " \"templateSign\": \"5aab7664cc5497d2f6f75ce99f1b133b\",\n" +
- // " \"templateName\": \"20190622_105813\",\n" +
- // " \"scores\": 1,\n" +
- // " \"isStructured\": true,\n" +
- // " \"logId\": \"157777134713797\",\n" +
- // " \"templateMatchDegree\": 0.9929515290405418,\n" +
- // " \"clockwiseAngle\": 269.81\n" +
- // " },\n" +
- // " \"error_code\": 0\n" +
- // "}";
- // }
- //
- // }
|