PatentStarServiceTests.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package cn.cslg.pas.service;
  2. import cn.cslg.pas.common.core.IgnoreDTDEntityResolver;
  3. import cn.cslg.pas.common.dto.PatentStarListDTO;
  4. import cn.cslg.pas.common.model.cronModel.Records;
  5. import cn.cslg.pas.common.utils.FormatUtil;
  6. import cn.cslg.pas.common.utils.RedisUtil;
  7. import cn.cslg.pas.common.utils.StringUtils;
  8. import cn.cslg.pas.common.vo.PatentWithIdVO;
  9. import cn.cslg.pas.domain.es.Patent;
  10. import cn.cslg.pas.service.business.es.EsService;
  11. import cn.cslg.pas.service.common.PatentStarApiService;
  12. import cn.cslg.pas.service.importPatent.SchedulingTaskService;
  13. import org.dom4j.Document;
  14. import org.dom4j.Element;
  15. import org.dom4j.XPath;
  16. import org.dom4j.io.SAXReader;
  17. import org.junit.jupiter.api.Test;
  18. import org.springframework.beans.BeanUtils;
  19. import org.springframework.beans.factory.annotation.Autowired;
  20. import org.springframework.boot.test.context.SpringBootTest;
  21. import java.io.Reader;
  22. import java.io.StringReader;
  23. import java.util.ArrayList;
  24. import java.util.List;
  25. import java.util.Map;
  26. /**
  27. * @author chenyu
  28. * @date 2023/9/6
  29. */
  30. @SpringBootTest
  31. public class PatentStarServiceTests {
  32. @Autowired
  33. private EsService esService;
  34. @Autowired
  35. private RedisUtil redisUtil;
  36. @Autowired
  37. private SchedulingTaskService importTaskAdd;
  38. @Autowired
  39. private PatentStarApiService patentStarApiService;
  40. @Test
  41. void addPatent() throws Exception {
  42. PatentStarListDTO patentStarListDTO = new PatentStarListDTO();
  43. patentStarListDTO.setCurrentQuery(" TI=计算机");
  44. patentStarListDTO.setDBType("CN");
  45. patentStarListDTO.setOrderBy("AD");
  46. patentStarListDTO.setPageNum(1);
  47. patentStarListDTO.setRowCount(10);
  48. patentStarListDTO.setOrderByType("DESC");
  49. Records records = patentStarApiService.patentStarSearchLocal(patentStarListDTO);
  50. System.out.println(records);
  51. }
  52. @Test
  53. void getPatentByPatentNo() throws Exception {
  54. //根据专利号获得id
  55. PatentWithIdVO patentWithIdVO = esService.getIdByPatentNo("CN201114765Y");
  56. Patent patent = new Patent();
  57. patent.setAgency("张三");
  58. Patent orgPatent = patentWithIdVO.getPatent();
  59. BeanUtils.copyProperties(patent, orgPatent, FormatUtil.getNullPropertyNames(patent));
  60. esService.updateDocument(orgPatent, patentWithIdVO.getId());
  61. }
  62. @Test
  63. void updatePatent() throws Exception {
  64. String a = patentStarApiService.getCnFullXmlApi("CN2006200179281");
  65. SAXReader reader = new SAXReader();
  66. reader.setEntityResolver(new IgnoreDTDEntityResolver());
  67. Reader stringReader = new StringReader(a);
  68. Document document = reader.read(stringReader);
  69. XPath xpath = document.createXPath("//claim-text");
  70. List<Element> element = (List<Element>) xpath.selectNodes(document);
  71. if (element.size() == 0) {
  72. xpath = document.createXPath("//business:ClaimText");
  73. element = (List<Element>) xpath.selectNodes(document);
  74. }
  75. List<String> reStrs = new ArrayList<>();
  76. element.forEach(item -> {
  77. String claim = item.getText();
  78. claim = claim.replaceAll("\r\n|\r|\n| ", "");
  79. claim = claim.replaceAll(" ", "");
  80. reStrs.add(claim);
  81. });
  82. String reStr = "";
  83. if (reStrs.size() != 0) {
  84. reStr = StringUtils.join(reStrs, "\r\n");
  85. }
  86. Element root = document.getRootElement();
  87. //获取根元素的名称
  88. String rootName = root.getName();
  89. System.out.println(rootName);
  90. }
  91. @Test
  92. void updatePatent1() throws Exception {
  93. String a = patentStarApiService.getCnFullXmlApi("201210398357");
  94. SAXReader reader = new SAXReader();
  95. reader.setEntityResolver(new IgnoreDTDEntityResolver());
  96. Reader stringReader = new StringReader(a);
  97. Document document = reader.read(stringReader);
  98. XPath xpath = document.createXPath("//description//p");
  99. List<Element> elements = (List<Element>) xpath.selectNodes(document);
  100. if (elements.size() == 0) {
  101. xpath = document.createXPath("//business:Description//base:Paragraphs");
  102. elements = (List<Element>) xpath.selectNodes(document);
  103. }
  104. List<String> reStrs = new ArrayList<>();
  105. Integer count = 1;
  106. for (Element item : elements) {
  107. String claim = item.getText().replaceAll("<br/>", "");
  108. if (!claim.trim().equals("技术领域")
  109. && !claim.trim().equals("发明内容")
  110. && !claim.trim().equals("附图说明")
  111. && !claim.trim().equals("具体实施方式")
  112. && !claim.trim().equals("背景技术")) {
  113. String formattedNum = String.format("%04d", count);
  114. claim = "[" + formattedNum + "]" + claim;
  115. count++;
  116. }
  117. reStrs.add(claim);
  118. }
  119. String reStr = "";
  120. if (reStrs.size() != 0) {
  121. reStr = StringUtils.join(reStrs, "\r\n");
  122. }
  123. System.out.println(reStr);
  124. Element root = document.getRootElement();
  125. //获取根元素的名称
  126. String rootName = root.getName();
  127. System.out.println(rootName);
  128. }
  129. @Test
  130. void addImportTask() throws Exception {
  131. List<Patent> patentList = esService.searchChild("1", 1, 10);
  132. System.out.println(patentList);
  133. Thread.sleep(1000000);
  134. }
  135. @Test
  136. void getLegalEvent() throws Exception {
  137. String a = patentStarApiService.getCnLegalApi("201210398357");
  138. System.out.println(a);
  139. Thread.sleep(1000000);
  140. }
  141. @Test
  142. void getFamilyPatent() throws Exception {
  143. String a = patentStarApiService.getFamilyByPubNoApi("CN116825114A");
  144. System.out.println(a);
  145. Thread.sleep(1000000);
  146. }
  147. }