PatentRightService.java 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. package cn.cslg.pas.service;
  2. import cn.cslg.pas.common.model.params.PatentRightParams;
  3. import cn.cslg.pas.common.utils.PatentUtils;
  4. import cn.cslg.pas.common.utils.Response;
  5. import cn.cslg.pas.common.utils.StringUtils;
  6. import cn.cslg.pas.domain.Authority;
  7. import cn.cslg.pas.domain.Patent;
  8. import cn.cslg.pas.domain.PatentRight;
  9. import cn.cslg.pas.mapper.PatentRightMapper;
  10. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  11. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  12. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  13. import lombok.RequiredArgsConstructor;
  14. import org.springframework.context.annotation.Lazy;
  15. import org.springframework.stereotype.Service;
  16. import java.util.ArrayList;
  17. import java.util.Arrays;
  18. import java.util.List;
  19. import java.util.regex.Matcher;
  20. import java.util.regex.Pattern;
  21. import java.util.stream.Collectors;
  22. /**
  23. * @author Administrator
  24. * @description 针对表【os_patent_right(专利权利要求)】的数据库操作Service
  25. * @createDate 2022-04-16 10:09:24
  26. */
  27. @Service
  28. @RequiredArgsConstructor(onConstructor_ = {@Lazy})
  29. public class PatentRightService extends ServiceImpl<PatentRightMapper, PatentRight> {
  30. private final PatentService patentService;
  31. public List<PatentRight> getPatentRightByPatentNo(String patentNo) {
  32. Patent patent = patentService.getByPatentNo(patentNo);
  33. LambdaQueryWrapper<PatentRight> queryWrapper = new LambdaQueryWrapper<>();
  34. queryWrapper.eq(PatentRight::getPatentId, patent.getId());
  35. queryWrapper.orderByAsc(PatentRight::getSort);
  36. return this.list(queryWrapper);
  37. }
  38. public List<PatentRight> getPatentRightByPatentId(Integer patentId) {
  39. LambdaQueryWrapper<PatentRight> queryWrapper = new LambdaQueryWrapper<>();
  40. queryWrapper.eq(PatentRight::getPatentId, patentId);
  41. queryWrapper.orderByAsc(PatentRight::getSort);
  42. return this.list(queryWrapper);
  43. }
  44. public List<PatentRight> getPatentRightByPatentIds(List<Integer> patentIds) {
  45. if (patentIds == null || patentIds.size() == 0) {
  46. return new ArrayList<>();
  47. }
  48. LambdaQueryWrapper<PatentRight> queryWrapper = new LambdaQueryWrapper<>();
  49. queryWrapper.in(PatentRight::getPatentId, patentIds);
  50. queryWrapper.orderByAsc(PatentRight::getSort);
  51. return this.list(queryWrapper);
  52. }
  53. public void deleteByPatentId(Integer patentId) {
  54. this.remove(Wrappers.<PatentRight>lambdaQuery().eq(PatentRight::getPatentId, patentId));
  55. }
  56. public void importPatentRight(Integer localPatentId, Integer importPatentId, List<PatentRight> importPatentRightList) {
  57. this.deleteByPatentId(localPatentId);
  58. List<PatentRight> patentRightList = importPatentRightList.stream().filter(item -> item.getPatentId().equals(importPatentId)).collect(Collectors.toList());
  59. for (PatentRight patentRight : patentRightList) {
  60. patentRight.setId(null);
  61. patentRight.setPatentId(localPatentId);
  62. }
  63. this.saveOrUpdateBatch(patentRightList);
  64. }
  65. public void importAuthority(PatentRightParams params) {
  66. List<Authority> splits = splits(params);
  67. List<Authority> authorities = relationshipAuthority(splits);
  68. List<Authority> authorities1 = relationshipAuthority3(authorities);
  69. List<Authority> authorities2 = relationshipAuthority2(authorities1);
  70. List<Authority> authorities3 = relationshipAuthority4(authorities2);
  71. for (Authority a : authorities3) {
  72. Authority authority = new Authority();
  73. authority.setContent(a.getContent());
  74. String join = StringUtils.join(a.getFatherID(), ",");
  75. authority.setFID(join);
  76. String join1 = StringUtils.join(a.getSonID(), ",");
  77. authority.setSID(join1);
  78. authority.setPatentID(params.getPatentId());
  79. authority.setType(a.getType());
  80. authority.insert();
  81. }
  82. }
  83. public List<Authority> splits(PatentRightParams params) {
  84. //去掉全要开头的""
  85. List<Authority> list = new ArrayList<>();
  86. String selfContent = params.getContent();
  87. if (selfContent == null) {
  88. selfContent = "";
  89. }
  90. //청구항 2. 삭제(是否删除代办)
  91. // selfContent.replaceAll("청구항(\\s)(^\\d*$+)(\\s)삭제","");
  92. selfContent.replaceAll("''", "");
  93. selfContent.replaceAll("(^\\d*$+)-(^\\d*$+)(\\.)(\\s)(canceled)", "");
  94. // selfContent.replaceAll("(^\\d*$+)(.)(\\s)(canceled)","");
  95. selfContent.replaceAll("\n", " ");
  96. //找到1. 2. ...这种格式的正则表达式
  97. String str1 = "(^\\d*$+)(\\.)";
  98. //找到[001]或者[002]这种格式的
  99. String str2 = "(\\[)(^[1-9]/d*$+)(\\])";
  100. //【請求項 1】
  101. String str3 = "(\\【請求項)(^[1-9]/d*$+)(\\】)";
  102. //청구항 1()
  103. String str4 = "청구항(\\s)(^[1-9]/d*$+)(\\.)";
  104. Pattern p4 = Pattern.compile(str4);
  105. Matcher m4 = p4.matcher(selfContent);
  106. List<Integer> integers1 = new ArrayList<>();
  107. while (m4.find()) {
  108. integers1.add(m4.start());
  109. }
  110. if (integers1.size() != 0) {
  111. for (int i = integers1.size() - 1; i >= 0; i--) {
  112. String str = selfContent.substring(integers1.get(i));
  113. Authority authority = new Authority();
  114. authority.setContent(str);
  115. list.add(authority);
  116. }
  117. Authority authority = new Authority();
  118. authority.setContent(selfContent);
  119. list.add(authority);
  120. return list;
  121. }
  122. Pattern p = Pattern.compile(str1);
  123. Matcher m = p.matcher(selfContent);
  124. //判断找到的数量
  125. List<Integer> integers = new ArrayList<>();
  126. while (m.find()) {
  127. integers.add(m.start());
  128. }
  129. if (integers.size() != 0) {
  130. for (int i = integers.size() - 1; i > 0; i--) {
  131. String str = selfContent.substring(integers.get(i));
  132. Authority authority1 = new Authority();
  133. authority1.setContent(str);
  134. list.add(authority1);
  135. }
  136. Authority authority1 = new Authority();
  137. authority1.setContentOut(selfContent);
  138. list.add(authority1);
  139. return list;
  140. }
  141. Pattern compile = Pattern.compile(str2);
  142. Matcher matcher = compile.matcher(selfContent);
  143. List<Integer> start = new ArrayList<>();
  144. while (matcher.find()) {
  145. start.add(matcher.start());
  146. }
  147. if (start.size() != 0) {
  148. for (int i = start.size() - 1; i > 0; i--) {
  149. String str = selfContent.substring(integers.get(i));
  150. Authority authority2 = new Authority();
  151. authority2.setContent(str);
  152. list.add(authority2);
  153. }
  154. Authority authority2 = new Authority();
  155. authority2.setContent(selfContent);
  156. list.add(authority2);
  157. return list;
  158. }
  159. Pattern compile1 = Pattern.compile(str3);
  160. Matcher matcher1 = compile1.matcher(selfContent);
  161. List<Integer> start1 = new ArrayList<>();
  162. while (matcher1.find()) {
  163. start1.add(matcher1.start());
  164. }
  165. if (start1.size() != 0) {
  166. for (int i = start1.size() - 1; i >= 0; i--) {
  167. String str = selfContent.substring(integers.get(i));
  168. Authority authority3 = new Authority();
  169. authority3.setContent(str);
  170. list.add(authority3);
  171. }
  172. Authority authority3 = new Authority();
  173. authority3.setContent(selfContent);
  174. list.add(authority3);
  175. }
  176. return list;
  177. }
  178. /**
  179. * 英文下的处理方式(草稿)
  180. */
  181. private List<Authority> relationshipAuthority(List<Authority> list) {
  182. List<Authority> authorities = list;
  183. //英文下的claim 1,claim2 的正则表达式
  184. String str1 = "(claim)(\\s)(^\\d*$+)";
  185. Pattern p = Pattern.compile(str1);
  186. for (int i = 0; i < list.size(); i++) {
  187. //去掉空格
  188. authorities.get(i).getContent().replaceAll(" ", "");
  189. Matcher m = p.matcher(authorities.get(i).getContent());
  190. if (!m.find()) {
  191. list.get(i).setFID(null);
  192. list.get(i).setType(0);
  193. return list;
  194. } else {
  195. //找到了
  196. String group = m.group(0);
  197. //把claim去掉只剩下面的数字
  198. String substring = group.substring(5);
  199. int j = Integer.parseInt(substring);
  200. List<Integer> sonID = list.get(j - 1).getSonID();
  201. sonID.add(authorities.get(i).getId());
  202. list.get(j - 1).setSonID(sonID);
  203. List<Integer> fatherID = list.get(i).getFatherID();
  204. fatherID.add(list.get(j - 1).getId());
  205. list.get(i).setFatherID(fatherID);
  206. //设置为
  207. list.get(i).setType(1);
  208. }
  209. }
  210. return list;
  211. }
  212. /**
  213. * 小日子的语言下的处理模式
  214. */
  215. private List<Authority> relationshipAuthority3(List<Authority> list) {
  216. List<Authority> authorities = list;
  217. //英文下的claim 1,claim2 的正则表达式
  218. String str1 = "(前記第)(^\\d*$+)";
  219. Pattern p = Pattern.compile(str1);
  220. for (int i = 0; i < list.size(); i++) {
  221. Matcher m = p.matcher(authorities.get(i).getContent());
  222. if (!m.find()) {
  223. list.get(i).setFID(null);
  224. list.get(i).setType(0);
  225. return list;
  226. } else {
  227. //找到了
  228. String group = m.group(0);
  229. //把claim去掉只剩下面的数字
  230. String substring = group.substring(3);
  231. int j = Integer.parseInt(substring);
  232. List<Integer> sonID = list.get(j - 1).getSonID();
  233. sonID.add(authorities.get(i).getId());
  234. list.get(j - 1).setSonID(sonID);
  235. List<Integer> fatherID = list.get(i).getFatherID();
  236. fatherID.add(list.get(j - 1).getId());
  237. list.get(i).setFatherID(fatherID);
  238. //设置为
  239. list.get(i).setType(1);
  240. }
  241. }
  242. return list;
  243. }
  244. /**
  245. * 中文下的处理方式
  246. */
  247. public List<Authority> relationshipAuthority2(List<Authority> list) {
  248. //中文下权利要求1,权利要求2,权利要求3
  249. String str1 = "(权利要求)(^\\d*$+)";
  250. //中文下权利要求1至
  251. String str2 = "(权利要求)(^\\d*$+)(至)(^\\d*$+)";
  252. //中文下权利要求 或
  253. String str3 = "(权利要求)(^\\d*$+)(或)(^\\d*$+)";
  254. Pattern p = Pattern.compile(str1);
  255. Pattern p1 = Pattern.compile(str2);
  256. Pattern p2 = Pattern.compile(str3);
  257. for (int i = 0; i < list.size(); i++) {
  258. Matcher matcher = p.matcher(list.get(i).getContent());
  259. if (matcher.find()) {
  260. list.get(i).setType(1);
  261. //找到满足第一情况
  262. Matcher matcher1 = p1.matcher(list.get(i).getContent());
  263. if (matcher1.find()) {
  264. //找到满足第一和第二种情况按第二种情况处理
  265. String group = matcher1.group(0);
  266. String str5 = "^\\d*$+";
  267. Pattern p3 = Pattern.compile(str5);
  268. Matcher matcher2 = p3.matcher(group);
  269. if (matcher2.find()) {
  270. String group1 = matcher2.group(0);
  271. String group2 = matcher2.group(1);
  272. Integer j = Integer.parseInt(group1);
  273. Integer k = Integer.parseInt(group2);
  274. for (int l = j - 1; l < k; l++) {
  275. List<Integer> sonID = list.get(l).getSonID();
  276. sonID.add(list.get(i).getId());
  277. list.get(l).setSonID(sonID);
  278. List<Integer> fatherID = list.get(i).getFatherID();
  279. fatherID.add(list.get(l).getId());
  280. list.get(i).setFatherID(fatherID);
  281. }
  282. }
  283. } else {
  284. Matcher matcher2 = p2.matcher(list.get(i).getContent());
  285. if (matcher2.find()) {
  286. //找到满足第三和第一情况按第三中情况处理
  287. String group = matcher1.group(0);
  288. String str6 = "^\\d*$+";
  289. Pattern p3 = Pattern.compile(str6);
  290. Matcher matcher3 = p3.matcher(group);
  291. if (matcher3.find()) {
  292. String group1 = matcher2.group(0);
  293. String group2 = matcher2.group(1);
  294. Integer j = Integer.parseInt(group1);
  295. Integer k = Integer.parseInt(group2);
  296. List<Integer> sonID = list.get(j).getSonID();
  297. sonID.add(list.get(i).getId());
  298. list.get(j).setSonID(sonID);
  299. List<Integer> fatherID = list.get(i).getFatherID();
  300. fatherID.add(list.get(j).getId());
  301. list.get(i).setFatherID(fatherID);
  302. List<Integer> sonID1 = list.get(k).getSonID();
  303. sonID1.add(list.get(i).getId());
  304. list.get(k).setSonID(sonID1);
  305. List<Integer> fatherID1 = list.get(i).getFatherID();
  306. fatherID1.add(list.get(k).getId());
  307. list.get(i).setFatherID(fatherID1);
  308. }
  309. } else {
  310. //只满足第一中情况
  311. String group = matcher.group(0);
  312. String str7 = "^\\d*$+";
  313. Pattern p3 = Pattern.compile(str7);
  314. Matcher matcher3 = p3.matcher(group);
  315. if (matcher3.find()) {
  316. String group1 = matcher2.group(0);
  317. Integer j = Integer.parseInt(group1);
  318. List<Integer> sonID = list.get(j).getSonID();
  319. sonID.add(list.get(i).getId());
  320. list.get(j).setSonID(sonID);
  321. List<Integer> fatherID = list.get(i).getFatherID();
  322. fatherID.add(list.get(j).getId());
  323. list.get(i).setFatherID(fatherID);
  324. }
  325. }
  326. }
  327. } else {
  328. list.get(i).setType(0);
  329. list.get(i).setFID(null);
  330. }
  331. }
  332. return list;
  333. }
  334. /**
  335. * 韩文下的处理
  336. */
  337. public List<Authority> relationshipAuthority4(List<Authority> list) {
  338. //韩文情况下的正则表达式
  339. String str1 = "제(\\s)(^\\d*$+)항"; //"제 1항에" ;
  340. String str3 = "제(\\s)(^\\d*$+)항(\\s)또는(\\s)제(^\\d*$+)항";//제 1항 또는 제 2항에 있어서 这种情况下的正则表达式
  341. Pattern p = Pattern.compile(str1);
  342. for (int i = 0; i < list.size(); i++) {
  343. // list.get(i).getContent().replaceAll(" ", "");
  344. Matcher m = p.matcher(list.get(i).getContent());
  345. if (!m.find()) {
  346. list.get(i).setFID(null);
  347. list.get(i).setType(0);
  348. } else {
  349. //找到了
  350. Pattern compile = Pattern.compile(str3);
  351. Matcher matcher1 = compile.matcher(list.get(i).getContent());
  352. if (matcher1.find()) {
  353. String group = m.group(0);
  354. String str2 = "(^\\d*$+)";
  355. Pattern p1 = Pattern.compile(str1);
  356. Matcher matcher = p1.matcher(group);
  357. String group1 = matcher.group(0);
  358. String group2 = matcher.group(1);
  359. Integer j = Integer.parseInt(group1);
  360. Integer k = Integer.parseInt(group2);
  361. List<Integer> sonID = list.get(j).getSonID();
  362. sonID.add(list.get(i).getId());
  363. list.get(j).setSonID(sonID);
  364. List<Integer> fatherID = list.get(i).getFatherID();
  365. fatherID.add(list.get(j).getId());
  366. list.get(i).setFatherID(fatherID);
  367. List<Integer> sonID1 = list.get(k).getSonID();
  368. sonID1.add(list.get(i).getId());
  369. list.get(k).setSonID(sonID1);
  370. List<Integer> fatherID1 = list.get(i).getFatherID();
  371. fatherID1.add(list.get(k).getId());
  372. list.get(i).setFatherID(fatherID1);
  373. } else {
  374. String group = m.group(0);
  375. String str2 = "(^\\d*$+)";
  376. Pattern p1 = Pattern.compile(str1);
  377. Matcher matcher = p1.matcher(group);
  378. String substring = matcher.group(0);
  379. int j = Integer.parseInt(substring);
  380. List<Integer> sonID = list.get(j - 1).getSonID();
  381. sonID.add(list.get(i).getId());
  382. list.get(j - 1).setSonID(sonID);
  383. List<Integer> fatherID = list.get(i).getFatherID();
  384. fatherID.add(list.get(j - 1).getId());
  385. list.get(i).setFatherID(fatherID);
  386. //设置为
  387. list.get(i).setType(1);
  388. }
  389. }
  390. }
  391. return list;
  392. }
  393. public void updatePatentRight(PatentRightParams params) {
  394. // 获取国家 公开号前两位
  395. String country = PatentUtils.getPatentCountry(params.getPatentNo());
  396. //权利要求原文
  397. String content = params.getContent();
  398. //权利要求译文
  399. String contentOut = params.getContentOut();
  400. if (StringUtils.isNotEmpty(content)) {
  401. //先删除库表中原有该权要
  402. this.deleteByPatentId(params.getPatentId());
  403. // String[] contentArray = null;
  404. // String[] contentOutArray = null;
  405. // String[] selfContentArray = null;
  406. // switch (country) {
  407. // case "JP":
  408. // case "CN":
  409. // code = "。";
  410. // if (StringUtils.isNotEmpty(contentOut)) {
  411. // contentOut = contentOut.replaceAll("\n", "");
  412. // contentOutArray = StringUtils.split(contentOut, code);
  413. // }
  414. // if (StringUtils.isNotEmpty(selfContent)) {
  415. // selfContent = selfContent.replaceAll("\n", "");
  416. // selfContentArray = StringUtils.split(selfContent, code);
  417. // }
  418. // content = content.replaceAll("\n", "");
  419. // contentArray = StringUtils.split(content, code);
  420. // break;
  421. // default:
  422. // code = "\n";
  423. // if (StringUtils.isNotEmpty(contentOut)) {
  424. // contentOutArray = StringUtils.split(contentOut, code);
  425. // }
  426. // if (StringUtils.isNotEmpty(selfContent)) {
  427. // selfContentArray = StringUtils.split(selfContent, code);
  428. // }
  429. // contentArray = StringUtils.split(content, code);
  430. // }
  431. // for (int i = 0; i < contentArray.length; i++) {
  432. // if (StringUtils.isEmpty(contentArray[i])) {
  433. // continue;
  434. // }
  435. // PatentRight patentRight = new PatentRight();
  436. // patentRight.setPatentId(params.getPatentId());
  437. // patentRight.setContent(contentArray[i]);
  438. // patentRight.setType(0);
  439. // patentRight.setSort(i);
  440. // if (contentOutArray != null && i < contentOutArray.length) {
  441. // patentRight.setContentOut(contentOutArray[i]);
  442. // }
  443. // if (selfContentArray != null) {
  444. // String temp = Arrays.stream(selfContentArray).filter(item -> item.equals(patentRight.getContent())).findFirst().orElse(null);
  445. // if (temp != null) {
  446. // patentRight.setType(1);
  447. // }
  448. // }
  449. ArrayList<PatentRight> patentRights = new ArrayList<>();
  450. //先去掉所有换行符,使所有内容连起来
  451. if (content.contains("\r\n")) {
  452. content = content.replaceAll("\r\n", "");
  453. } else {
  454. content = content.replaceAll("\n", "");
  455. }
  456. if (contentOut == null) {
  457. contentOut = "";
  458. }
  459. if (contentOut.contains("\r\n")) {
  460. contentOut = contentOut.replaceAll("\r\n", "");
  461. } else {
  462. contentOut = contentOut.replaceAll("\n", "");
  463. }
  464. //去掉译文的所有空格
  465. contentOut = contentOut.replaceAll(" +", "");
  466. //中文专利的权要拆分 ↓
  467. if (country.equals("CN") || country.equals("JP")) {
  468. String regex;
  469. if (content.contains("。2.")) {
  470. regex = "。[0-9]+\\.";
  471. } else if (content.contains("。2、")) {
  472. regex = "。[0-9]+[、]";
  473. } else if (content.contains("[001]")) {
  474. regex = "\\[[0-9]+]";
  475. } else if (content.contains("請求項")) {
  476. regex = "。【請求項[0-9]+】";
  477. } else {
  478. regex = "";
  479. }
  480. Matcher matcher = Pattern.compile(regex).matcher(content);
  481. Matcher matcherOut = Pattern.compile(regex).matcher(contentOut);
  482. while (matcher.find()) {
  483. if (matcher.group().contains(".")) {
  484. String matcherGroup = matcher.group().replace(".", "\\.");
  485. content = content.replaceFirst(matcherGroup, "。\n" + matcherGroup.substring(matcherGroup.indexOf("。") + 1, matcherGroup.indexOf("\\")) + ".");
  486. } else if (matcher.group().contains("、") || matcher.group().contains("請求項")) {
  487. content = content.replaceFirst(matcher.group(), "。\n" + matcher.group().substring(matcher.group().indexOf("。") + 1));
  488. }
  489. }
  490. String[] strs = content.split("\n");
  491. while (matcherOut.find()) {
  492. if (matcherOut.group().contains(".")) {
  493. String matcherOutGroup = matcherOut.group().replace(".", "\\.");
  494. contentOut = contentOut.replaceFirst(matcherOutGroup, "。\n" + matcherOutGroup.substring(matcherOutGroup.indexOf("。") + 1, matcherOutGroup.indexOf("\\")) + ".");
  495. } else if (matcherOut.group().contains("、")) {
  496. contentOut = contentOut.replaceFirst(matcherOut.group(), "。\n" + matcherOut.group().substring(matcherOut.group().indexOf("。") + 1));
  497. }
  498. }
  499. String[] strsOut = contentOut.split("\n");
  500. //定义父权要排序号
  501. String regex1 = "权利要求[0-9]+";
  502. String regex2 = "权利要求[0-9]+[至或~-]+[0-9]+";
  503. for (int i = 0; i < strs.length; i++) {
  504. if (strs[i].contains("权利要求")) {
  505. Matcher matcher1 = Pattern.compile(regex1).matcher(strs[i]);
  506. Matcher matcher2 = Pattern.compile(regex2).matcher(strs[i]);
  507. if (matcher2.find()) {
  508. String parentNum = matcher2.group().substring(matcher2.group().indexOf("求") + 1);
  509. String[] parentNums;
  510. if (parentNum.contains("~")) {
  511. parentNums = parentNum.split("~");
  512. } else if (parentNum.contains("-")) {
  513. parentNums = parentNum.split("-");
  514. } else if (parentNum.contains("至")) {
  515. parentNums = parentNum.split("至");
  516. } else if (parentNum.contains("或")) {
  517. parentNums = parentNum.split("或");
  518. } else {
  519. parentNums = new String[0];
  520. }
  521. StringBuilder builder = new StringBuilder();
  522. for (int j = Integer.parseInt(parentNums[0]) - 1; j < Integer.parseInt(parentNums[parentNums.length - 1]); j++) {
  523. if ((builder + "").equals("")) {
  524. builder.append(j);
  525. } else {
  526. builder.append(",").append(j);
  527. }
  528. }
  529. PatentRight patentRight = new PatentRight()
  530. .setPatentId(params.getPatentId())
  531. .setType(1)
  532. .setContent(strs[i])
  533. .setSort(i)
  534. .setParentSort(builder + "");
  535. if (strsOut.length - 1 >= i) {
  536. patentRight.setContentOut(strsOut[i]);
  537. }
  538. patentRights.add(patentRight);
  539. } else if (matcher1.find()) {
  540. String parentNum = matcher1.group().substring(matcher1.group().indexOf("求") + 1);
  541. PatentRight patentRight = new PatentRight()
  542. .setPatentId(params.getPatentId())
  543. .setType(1)
  544. .setContent(strs[i])
  545. .setSort(i)
  546. .setParentSort((Integer.parseInt(parentNum) - 1) + "");
  547. if (strsOut.length - 1 >= i) {
  548. patentRight.setContentOut(strsOut[i]);
  549. }
  550. patentRights.add(patentRight);
  551. }
  552. } else {
  553. PatentRight patentRight = new PatentRight()
  554. .setPatentId(params.getPatentId())
  555. .setType(0)
  556. .setContent(strs[i])
  557. .setSort(i)
  558. .setParentSort("-1");
  559. if (strsOut.length - 1 >= i) {
  560. patentRight.setContentOut(strsOut[i]);
  561. }
  562. patentRights.add(patentRight);
  563. }
  564. }
  565. //英文专利的权要拆分 ↓
  566. } else {
  567. content = content.substring(content.indexOf("1."));
  568. contentOut = contentOut.substring(contentOut.indexOf("1."));
  569. String regex;
  570. if (content.contains("1.")) {
  571. regex = "\\.[0-9]+\\. ";
  572. } else if (content.contains("1、")) {
  573. regex = "\\.[0-9]+\\. ";
  574. } else if (content.contains("[001]")) {
  575. regex = "\\[[0-9]+]";
  576. } else {
  577. regex = "";
  578. }
  579. Matcher matcher = Pattern.compile(regex).matcher(content);
  580. Matcher matcherOut = Pattern.compile("。[0-9]+\\.").matcher(contentOut);
  581. while (matcher.find()) {
  582. String matcherGroup = matcher.group().replace(".", "\\.");
  583. content = content.replaceFirst(matcherGroup, ".\n" + matcherGroup.substring(matcherGroup.indexOf(".") + 1, matcherGroup.lastIndexOf("\\")) + ". ");
  584. }
  585. String[] strs = content.split("\n");
  586. while (matcherOut.find()) {
  587. String matcherOutGroup = matcherOut.group().replace(".", "\\.");
  588. contentOut = contentOut.replaceFirst(matcherOutGroup, "。\n" + matcherOutGroup.substring(matcherOutGroup.indexOf("。") + 1, matcherOutGroup.indexOf("\\")) + ".");
  589. }
  590. String[] strsOut = contentOut.split("\n");
  591. //定义父权要排序号
  592. String regex1 = "claim [0-9]+";
  593. String regex2 = "claims [0-9]+ or [0-9]+";
  594. for (int i = 0; i < strs.length; i++) {
  595. if (strs[i].contains("claim")) {
  596. Matcher matcher1 = Pattern.compile(regex1).matcher(strs[i]);
  597. Matcher matcher2 = Pattern.compile(regex2).matcher(strs[i]);
  598. if (matcher2.find()) {
  599. String parentNum = matcher2.group().substring(matcher2.group().indexOf("s") + 2);
  600. String[] parentNums;
  601. if (parentNum.contains(" or ")) {
  602. parentNums = parentNum.split(" or ");
  603. } else if (parentNum.contains(" - ")) {
  604. parentNums = parentNum.split(" - ");
  605. } else if (parentNum.contains(" to ")) {
  606. parentNums = parentNum.split(" to ");
  607. } else if (parentNum.contains("或")) {
  608. parentNums = parentNum.split("或");
  609. } else {
  610. parentNums = new String[0];
  611. }
  612. StringBuilder builder = new StringBuilder();
  613. for (int j = Integer.parseInt(parentNums[0]) - 1; j < Integer.parseInt(parentNums[parentNums.length - 1]); j++) {
  614. if ((builder + "").equals("")) {
  615. builder.append(j);
  616. } else {
  617. builder.append(",").append(j);
  618. }
  619. }
  620. PatentRight patentRight = new PatentRight()
  621. .setPatentId(params.getPatentId())
  622. .setType(1)
  623. .setContent(strs[i])
  624. .setSort(i)
  625. .setParentSort(builder + "");
  626. if (strsOut.length - 1 >= i) {
  627. patentRight.setContentOut(strsOut[i]);
  628. }
  629. patentRights.add(patentRight);
  630. } else if (matcher1.find()) {
  631. String parentNum = matcher1.group().substring(matcher1.group().indexOf("m") + 2);
  632. PatentRight patentRight = new PatentRight()
  633. .setPatentId(params.getPatentId())
  634. .setType(1)
  635. .setContent(strs[i])
  636. .setSort(i)
  637. .setParentSort((Integer.parseInt(parentNum) - 1) + "");
  638. if (strsOut.length - 1 >= i) {
  639. patentRight.setContentOut(strsOut[i]);
  640. }
  641. patentRights.add(patentRight);
  642. }
  643. } else {
  644. PatentRight patentRight = new PatentRight()
  645. .setPatentId(params.getPatentId())
  646. .setType(0)
  647. .setContent(strs[i])
  648. .setSort(i)
  649. .setParentSort("-1");
  650. if (strsOut.length - 1 >= i) {
  651. patentRight.setContentOut(strsOut[i]);
  652. }
  653. patentRights.add(patentRight);
  654. }
  655. }
  656. }
  657. this.saveOrUpdateBatch(patentRights);
  658. }
  659. }
  660. }