Forráskód Böngészése

3/31 权要树形式保存入库

chenyu 2 éve
szülő
commit
03686400d2

+ 18 - 10
PAS/src/main/java/cn/cslg/pas/domain/PatentRight.java

@@ -5,36 +5,44 @@ import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
+
 import java.io.Serializable;
+
 import lombok.Data;
+import lombok.experimental.Accessors;
 
 /**
  * 专利权利要求
+ *
  * @TableName os_patent_right
  */
 @Data
-@TableName(value ="os_patent_right")
+@Accessors(chain = true)
+@TableName(value = "os_patent_right")
 public class PatentRight extends BaseEntity<PatentRight> {
-
     /**
      * 专利ID
      */
     private Integer patentId;
-
     /**
-     * 内容
+     * 权利要求原文
      */
-    private String contentOut;
-
+    private String content;
     /**
-     * 内容
+     * 权利要求译文
      */
-    private String content;
-
+    private String contentOut;
     /**
      * 类型
      */
     private Integer type;
-
+    /**
+     * 排序号
+     */
     private Integer sort;
+    /**
+     * 父权要的排序号
+     */
+    private String parentSort;
+
 }

+ 174 - 79
PAS/src/main/java/cn/cslg/pas/service/PatentRightService.java

@@ -23,10 +23,10 @@ import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 /**
-* @author Administrator
-* @description 针对表【os_patent_right(专利权利要求)】的数据库操作Service
-* @createDate 2022-04-16 10:09:24
-*/
+ * @author Administrator
+ * @description 针对表【os_patent_right(专利权利要求)】的数据库操作Service
+ * @createDate 2022-04-16 10:09:24
+ */
 @Service
 @RequiredArgsConstructor(onConstructor_ = {@Lazy})
 public class PatentRightService extends ServiceImpl<PatentRightMapper, PatentRight> {
@@ -96,13 +96,13 @@ public class PatentRightService extends ServiceImpl<PatentRightMapper, PatentRig
         //去掉全要开头的""
         List<Authority> list = new ArrayList<>();
         String selfContent = params.getContent();
-        if(selfContent==null){
-            selfContent="";
+        if (selfContent == null) {
+            selfContent = "";
         }
         //청구항 2. 삭제(是否删除代办)
-      //  selfContent.replaceAll("청구항(\\s)(^\\d*$+)(\\s)삭제","");
+        //  selfContent.replaceAll("청구항(\\s)(^\\d*$+)(\\s)삭제","");
         selfContent.replaceAll("''", "");
-        selfContent.replaceAll("(^\\d*$+)-(^\\d*$+)(\\.)(\\s)(canceled)","");
+        selfContent.replaceAll("(^\\d*$+)-(^\\d*$+)(\\.)(\\s)(canceled)", "");
 //        selfContent.replaceAll("(^\\d*$+)(.)(\\s)(canceled)","");
         selfContent.replaceAll("\n", " ");
 
@@ -118,9 +118,9 @@ public class PatentRightService extends ServiceImpl<PatentRightMapper, PatentRig
         Matcher m4 = p4.matcher(selfContent);
         List<Integer> integers1 = new ArrayList<>();
         while (m4.find()) {
-                integers1.add(m4.start());
-            }
-        if(integers1.size()!=0) {
+            integers1.add(m4.start());
+        }
+        if (integers1.size() != 0) {
             for (int i = integers1.size() - 1; i >= 0; i--) {
                 String str = selfContent.substring(integers1.get(i));
                 Authority authority = new Authority();
@@ -370,8 +370,8 @@ public class PatentRightService extends ServiceImpl<PatentRightMapper, PatentRig
      */
     public List<Authority> relationshipAuthority4(List<Authority> list) {
         //韩文情况下的正则表达式
-        String str1="제(\\s)(^\\d*$+)항" ;     //"제 1항에" ;
-        String str3="제(\\s)(^\\d*$+)항(\\s)또는(\\s)제(^\\d*$+)항";//제 1항 또는 제 2항에 있어서 这种情况下的正则表达式
+        String str1 = "제(\\s)(^\\d*$+)항";     //"제 1항에" ;
+        String str3 = "제(\\s)(^\\d*$+)항(\\s)또는(\\s)제(^\\d*$+)항";//제 1항 또는 제 2항에 있어서 这种情况下的正则表达式
         Pattern p = Pattern.compile(str1);
         for (int i = 0; i < list.size(); i++) {
 
@@ -385,7 +385,7 @@ public class PatentRightService extends ServiceImpl<PatentRightMapper, PatentRig
                 //找到了
                 Pattern compile = Pattern.compile(str3);
                 Matcher matcher1 = compile.matcher(list.get(i).getContent());
-                if(matcher1.find()){
+                if (matcher1.find()) {
                     String group = m.group(0);
                     String str2 = "(^\\d*$+)";
                     Pattern p1 = Pattern.compile(str1);
@@ -408,21 +408,21 @@ public class PatentRightService extends ServiceImpl<PatentRightMapper, PatentRig
                     list.get(i).setFatherID(fatherID1);
 
 
-                }else {
-                String group = m.group(0);
-                String str2 = "(^\\d*$+)";
-                Pattern p1 = Pattern.compile(str1);
-                Matcher matcher = p1.matcher(group);
-                String substring = matcher.group(0);
-                int j = Integer.parseInt(substring);
-                List<Integer> sonID = list.get(j - 1).getSonID();
-                sonID.add(list.get(i).getId());
-                list.get(j - 1).setSonID(sonID);
-                List<Integer> fatherID = list.get(i).getFatherID();
-                fatherID.add(list.get(j - 1).getId());
-                list.get(i).setFatherID(fatherID);
-                //设置为
-                list.get(i).setType(1);
+                } else {
+                    String group = m.group(0);
+                    String str2 = "(^\\d*$+)";
+                    Pattern p1 = Pattern.compile(str1);
+                    Matcher matcher = p1.matcher(group);
+                    String substring = matcher.group(0);
+                    int j = Integer.parseInt(substring);
+                    List<Integer> sonID = list.get(j - 1).getSonID();
+                    sonID.add(list.get(i).getId());
+                    list.get(j - 1).setSonID(sonID);
+                    List<Integer> fatherID = list.get(i).getFatherID();
+                    fatherID.add(list.get(j - 1).getId());
+                    list.get(i).setFatherID(fatherID);
+                    //设置为
+                    list.get(i).setType(1);
                 }
             }
         }
@@ -432,67 +432,162 @@ public class PatentRightService extends ServiceImpl<PatentRightMapper, PatentRig
 
 
     public void updatePatentRight(PatentRightParams params) {
-        List<PatentRight> patentRightList = new ArrayList<>();
-        //获取国家 公开号前两位
-        String country = PatentUtils.getPatentCountry(params.getPatentNo());
-        String code;
-        //权利要求
+//        List<PatentRight> patentRightList = new ArrayList<>();
+//        获取国家 公开号前两位
+//        String country = PatentUtils.getPatentCountry(params.getPatentNo());
+//        String code;
+
+        //权利要求原文
         String content = params.getContent();
-        //权利要求(译)
+        //权利要求译文
         String contentOut = params.getContentOut();
         //独立权利要求
         String selfContent = params.getSelfContent();
         if (StringUtils.isNotEmpty(content)) {
-            this.deleteByPatentId(params.getPatentId());
-            String[] contentArray = null;
-            String[] contentOutArray = null;
-            String[] selfContentArray = null;
-            switch (country) {
-                case "JP":
-                case "CN":
-                    code = "。";
-                    if (StringUtils.isNotEmpty(contentOut)) {
-                        contentOut = contentOut.replaceAll("\n", "");
-                        contentOutArray = StringUtils.split(contentOut, code);
-                    }
-                    if (StringUtils.isNotEmpty(selfContent)) {
-                        selfContent = selfContent.replaceAll("\n", "");
-                        selfContentArray = StringUtils.split(selfContent, code);
-                    }
-                    content = content.replaceAll("\n", "");
-                    contentArray = StringUtils.split(content, code);
-                    break;
-                default:
-                    code = "\n";
-                    if (StringUtils.isNotEmpty(contentOut)) {
-                        contentOutArray = StringUtils.split(contentOut, code);
-                    }
-                    if (StringUtils.isNotEmpty(selfContent)) {
-                        selfContentArray = StringUtils.split(selfContent, code);
-                    }
-                    contentArray = StringUtils.split(content, code);
+//            this.deleteByPatentId(params.getPatentId());
+//            String[] contentArray = null;
+//            String[] contentOutArray = null;
+//            String[] selfContentArray = null;
+//            switch (country) {
+//                case "JP":
+//                case "CN":
+//                    code = "。";
+//                    if (StringUtils.isNotEmpty(contentOut)) {
+//                        contentOut = contentOut.replaceAll("\n", "");
+//                        contentOutArray = StringUtils.split(contentOut, code);
+//                    }
+//                    if (StringUtils.isNotEmpty(selfContent)) {
+//                        selfContent = selfContent.replaceAll("\n", "");
+//                        selfContentArray = StringUtils.split(selfContent, code);
+//                    }
+//                    content = content.replaceAll("\n", "");
+//                    contentArray = StringUtils.split(content, code);
+//                    break;
+//                default:
+//                    code = "\n";
+//                    if (StringUtils.isNotEmpty(contentOut)) {
+//                        contentOutArray = StringUtils.split(contentOut, code);
+//                    }
+//                    if (StringUtils.isNotEmpty(selfContent)) {
+//                        selfContentArray = StringUtils.split(selfContent, code);
+//                    }
+//                    contentArray = StringUtils.split(content, code);
+//            }
+//            for (int i = 0; i < contentArray.length; i++) {
+//                if (StringUtils.isEmpty(contentArray[i])) {
+//                    continue;
+//                }
+//                PatentRight patentRight = new PatentRight();
+//                patentRight.setPatentId(params.getPatentId());
+//                patentRight.setContent(contentArray[i]);
+//                patentRight.setType(0);
+//                patentRight.setSort(i);
+//                if (contentOutArray != null && i < contentOutArray.length) {
+//                    patentRight.setContentOut(contentOutArray[i]);
+//                }
+//                if (selfContentArray != null) {
+//                    String temp = Arrays.stream(selfContentArray).filter(item -> item.equals(patentRight.getContent())).findFirst().orElse(null);
+//                    if (temp != null) {
+//                        patentRight.setType(1);
+//                    }
+//                }
+//                patentRightList.add(patentRight);
+            ArrayList<PatentRight> patentRights = new ArrayList<>();
+            //先去掉所有换行符,使原文连起来
+            content = content.replaceAll("\n", "");
+            contentOut = contentOut.replaceAll("\n", "");
+
+            //根据专利所属国家,定义序号规则
+            String regex;
+            if (content.contains("1.")) {
+                regex = "[0-9]+[.]";
+            } else if (content.contains("1、")) {
+                regex = "[0-9]+[、]";
+            } else if (content.contains("[001]")) {
+                regex = "\\[[0-9]+]";
+            } else {
+                regex = "";
             }
-            for (int i = 0; i < contentArray.length; i++) {
-                if (StringUtils.isEmpty(contentArray[i])) {
-                    continue;
+
+            Pattern compile = Pattern.compile(regex);
+            Matcher matcher = compile.matcher(content);
+            Matcher matcherOut = compile.matcher(contentOut);
+            while (matcher.find()) {
+                if (!matcher.group().equals("1.") && !matcher.group().equals("1、") && !matcher.group().equals("[001]")) {
+                    content = content.replaceFirst(matcher.group(), "\n" + matcher.group());
                 }
-                PatentRight patentRight = new PatentRight();
-                patentRight.setPatentId(params.getPatentId());
-                patentRight.setContent(contentArray[i]);
-                patentRight.setType(0);
-                patentRight.setSort(i);
-                if (contentOutArray != null && i < contentOutArray.length) {
-                    patentRight.setContentOut(contentOutArray[i]);
+            }
+            String[] strs = content.split("\n");
+            while (matcherOut.find()) {
+                if (!matcherOut.group().equals("1.") && !matcherOut.group().equals("1、") && !matcherOut.group().equals("[001]")) {
+                    contentOut = contentOut.replaceFirst(matcher.group(), "\n" + matcher.group());
                 }
-                if (selfContentArray != null) {
-                    String temp = Arrays.stream(selfContentArray).filter(item -> item.equals(patentRight.getContent())).findFirst().orElse(null);
-                    if (temp != null) {
-                        patentRight.setType(1);
+            }
+            String[] strsOut = contentOut.split("\n");
+
+            //定义父权要排序号
+            String regex1 = "权利要求[0-9]+";
+            String regex2 = "权利要求[0-9]+[至或~-]+[0-9]+";
+            for (int i = 0; i < strs.length; i++) {
+                if (strs[i].contains("权利要求")) {
+                    Pattern compile1 = Pattern.compile(regex1);
+                    Matcher matcher1 = compile1.matcher(strs[i]);
+                    Pattern compile2 = Pattern.compile(regex2);
+                    Matcher matcher2 = compile2.matcher(strs[i]);
+                    if (matcher2.find()) {
+                        String parentNum = matcher2.group().substring(matcher2.group().indexOf("求") + 1);
+                        String[] parentNums;
+                        if (parentNum.contains("~")) {
+                            parentNums = parentNum.split("~");
+                        } else if (parentNum.contains("-")) {
+                            parentNums = parentNum.split("-");
+                        } else if (parentNum.contains("至")) {
+                            parentNums = parentNum.split("至");
+                        } else if (parentNum.contains("或")) {
+                            parentNums = parentNum.split("或");
+                        } else {
+                            parentNums = new String[0];
+                        }
+                        StringBuilder builder = new StringBuilder();
+                        for (int j = Integer.parseInt(parentNums[0]) - 1; j < Integer.parseInt(parentNums[parentNums.length - 1]); j++) {
+                            if ((builder + "").equals("")) {
+                                builder.append(j);
+                            } else {
+                                builder.append(",").append(j);
+                            }
+                        }
+                        PatentRight patentRight = new PatentRight()
+                                .setPatentId(params.getPatentId())
+                                .setType(1)
+                                .setContent(strs[i])
+                                .setContentOut(strsOut[i])
+                                .setSort(i)
+                                .setParentSort(builder + "");
+                        patentRights.add(patentRight);
+                    } else if (matcher1.find()) {
+                        String parentNum = matcher1.group().substring(matcher1.group().indexOf("求") + 1);
+                        PatentRight patentRight = new PatentRight()
+                                .setPatentId(params.getPatentId())
+                                .setType(1)
+                                .setContent(strs[i])
+                                .setContentOut(strsOut[i])
+                                .setSort(i)
+                                .setParentSort((Integer.parseInt(parentNum) - 1) + "");
+                        patentRights.add(patentRight);
                     }
+
+                } else {
+                    PatentRight patentRight = new PatentRight()
+                            .setPatentId(params.getPatentId())
+                            .setType(0)
+                            .setContent(strs[i])
+                            .setContentOut(strsOut[i])
+                            .setSort(i)
+                            .setParentSort("-1");
+                    patentRights.add(patentRight);
                 }
-                patentRightList.add(patentRight);
             }
-            this.saveOrUpdateBatch(patentRightList);
+            this.saveOrUpdateBatch(patentRights);
         }
     }
 }