Pārlūkot izejas kodu

20250605-生成说明书

lrj 4 mēneši atpakaļ
vecāks
revīzija
4ef8d72d12

+ 20 - 16
src/main/java/cn/cslg/pas/service/dify/GenerateInstructionService.java

@@ -73,6 +73,7 @@ public class GenerateInstructionService {
 
 
     public String getClaimContent(String claim) {
+       claim= claim.replaceAll("所述","");
         // 正则表达式模式(注意 Java 中需要双反斜杠转义)
         String regex = "其特征在于[,。;!?、]+(.+)";
         Pattern pattern = Pattern.compile(regex);
@@ -81,22 +82,18 @@ public class GenerateInstructionService {
             // 提取第一个捕获组的内容(即括号内的部分)
             return matcher.group(1).trim();
         }
-        return "其中," + claim; // 未找到匹配时返回空字符串
+
+        return claim; // 未找到匹配时返回空字符串
 
     }
 
     public String getMainClaimContent(String claim) {
+        claim= claim.replaceAll("所述","");
         // 正则表达式模式(注意 Java 中需要双反斜杠转义)
-//        String regex1 = "^[0-9]+\\.";
-//        String regex2 = "^\\[[0-9]+]";
-//        String regex3 = "^[0-9]+、";
-//        String outPut1 = claim.replaceAll(regex1, "");
-//        String outPut2 = outPut1.replaceAll(regex2, "");
-//        String outPut3 =outPut2.replaceAll(regex3,"");
-        String combinedRegex = "^(\\d+[.、]|\\[[0-9]+])";
-        String output = claim.replaceAll(combinedRegex, "").replaceAll("[\\n\\r]+$", "");
+        claim= claim.replaceAll("^(\\d+[.、]|\\[[0-9]+])","");
+        claim =claim.replaceAll("其特征在于[,。;!?、]","");
+        return claim; // 未找到匹配时返回空字符串
 
-        return  output; // 未找到匹配时返回空字符串
 
     }
     public String getClaimText(String claim) {
@@ -317,12 +314,13 @@ public class GenerateInstructionService {
 
 
         for (int i = 0; i < rePatentClaims.size(); i++) {
+            RePatentClaim rePatentClaim = rePatentClaims.get(i);
             ClaimExplainVO claimExplainVO = null;
             if (i == 0) {
                 claimExplainVO = firstClaimExplainVO;
             } else {
                 try {
-                    RePatentClaim rePatentClaim = rePatentClaims.get(i);
+
                     String claimContent = rePatentClaim.getContent();
                     GenerateInstructAnswerVO generateInstructAnswerVO = this.getAnswerFromAI(claimContent, background, i, "g&implementation", conversationId);
                     String answer = generateInstructAnswerVO.getAnswer();
@@ -340,7 +338,7 @@ public class GenerateInstructionService {
             String message = "";
             String reStr = null;
             if (claimExplainVO != null) {
-               List<String> contents = this.formatImplementation(claimExplainVO);
+               List<String> contents = this.formatImplementation(claimExplainVO,rePatentClaim);
                 if(contents.size()>0){
                     reContents.addAll(contents);
                     reStr = StringUtils.join(contents, "\n");
@@ -370,14 +368,20 @@ public class GenerateInstructionService {
      * @param claimExplainVO
      * @return
      */
-    private List<String> formatImplementation(ClaimExplainVO claimExplainVO) {
+    private List<String> formatImplementation(ClaimExplainVO claimExplainVO,RePatentClaim rePatentClaim) {
         String reStr = null;
         List<String> contents = new ArrayList<>();
         String explainVOClaim = claimExplainVO.getClaim();
         String effect = claimExplainVO.getEffects();
         String explain = claimExplainVO.getExplain();
         if (explainVOClaim != null && !explainVOClaim.trim().equals("")) {
-         String tem= this.getClaimText(explainVOClaim);
+            String tem="";
+            if (rePatentClaim != null && rePatentClaim.getType() != null && rePatentClaim.getType().equals(1)) {
+                tem =  this.getMainClaimContent(rePatentClaim.getContent());
+            } else {
+                tem = "在一实施方式中,"+this.getClaimContent(rePatentClaim.getContent());
+            }
+
             contents.add(tem);
         }
         if (effect != null && !effect.trim().equals("")) {
@@ -457,9 +461,9 @@ public class GenerateInstructionService {
             String claimContent = rePatentClaim.getContent();
             String temContent = "";
             if (rePatentClaim != null && rePatentClaim.getType() != null && rePatentClaim.getType().equals(1)) {
-                temContent = "为解决上述问题,本申请提出"+ this.getClaimText(claimContent);
+                temContent =  this.getMainClaimContent(claimContent);
             } else {
-                temContent = this.getClaimContent(claimContent);
+                temContent = "其中,"+this.getClaimContent(claimContent);
             }
             contentStrs.add(temContent);
         }

BIN
src/main/resources/file/reportTemple/patent.docx


+ 2 - 2
src/test/java/cn/cslg/pas/service/dify/GenerateInstructionServiceTests.java

@@ -35,8 +35,8 @@ public class GenerateInstructionServiceTests {
         String re = generateInstructionService.getMainClaimContent("1、一种电磁弹簧,其特征在于,包括:\n" +
                 "螺旋弹性体,由弹簧丝绕一轴线螺旋环绕形成,所述螺旋弹性体至少包括两匝;\n" +
                 "所述螺旋弹性体的至少一组相邻设置的两个匝圈上均设有一电磁件,且所述两个匝圈上的所述电磁件沿所述轴线的正投影至少部分重叠;\n" +
-                "若干线束,沿所述轴线延伸设置于所述螺旋弹性体,所述电磁件连接于至少一所述线束,所述线束用于调节所述电磁件的磁力。\n" +
-                "2、 根据权利要求1所述的电磁弹簧,其特征在于,所述弹簧丝在所述电磁件所在区域开设有若干安装槽,所述电磁件嵌设于对应的所述安装槽内。");
+                "若干线束,沿所述轴线延伸设置于所述螺旋弹性体,所述电磁件连接于至少一所述线束,所述线束用于调节所述电磁件的磁力。\n"
+                );
         System.out.println(re);
     }