|
@@ -16,6 +16,7 @@ import cn.cslg.pas.domain.es.Text;
|
|
|
import cn.cslg.pas.exception.XiaoShiException;
|
|
|
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
|
import co.elastic.clients.elasticsearch._types.InlineScript;
|
|
|
+import co.elastic.clients.elasticsearch._types.Refresh;
|
|
|
import co.elastic.clients.elasticsearch._types.Script;
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
|
import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
@@ -37,6 +38,8 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@@ -147,7 +150,7 @@ public class TranslateService {
|
|
|
IndexResponse indexResponse = client.index(i -> i
|
|
|
.index("translate")
|
|
|
//传入user对象
|
|
|
- .document(translate)
|
|
|
+ .document(translate).refresh(Refresh.True)
|
|
|
);
|
|
|
return indexResponse.id();
|
|
|
}
|
|
@@ -177,7 +180,7 @@ public class TranslateService {
|
|
|
i += 1;
|
|
|
}
|
|
|
//译文
|
|
|
- String translateContent = this.getTranslateContent(textContent);
|
|
|
+ String translateContent = this.getLimitTranslateContent(textContent);
|
|
|
String s1 = this.loadingTranslate(patentNo, patentField, "CN", false, 0, "-1", translateContent);
|
|
|
if (StringUtils.isNotEmpty(s1)) {
|
|
|
i += 1;
|
|
@@ -417,10 +420,7 @@ public class TranslateService {
|
|
|
for (EsTranslateDTO translateDTO : translateDTOS) {
|
|
|
Content content = translateDTO.getContent();
|
|
|
String textContent = content.getTextContent();
|
|
|
- if (textContent.contains("\r\n")) {
|
|
|
- textContent = textContent.replaceAll("\r\n", "");
|
|
|
- }
|
|
|
- String translateContent = this.getTranslateContent(textContent);
|
|
|
+ String translateContent = this.getLimitTranslateContent(textContent);
|
|
|
String s = this.loadingTranslate(translateDTO.getPatentNo(), translateDTO.getPatentField(), "CN", false,
|
|
|
content.getOrder(), content.getParentSort(), translateContent);
|
|
|
if (StringUtils.isNotEmpty(s)) {
|
|
@@ -443,6 +443,47 @@ public class TranslateService {
|
|
|
return translateVOS;
|
|
|
}
|
|
|
|
|
|
+ //判断文本翻译是否超出限制5000
|
|
|
+ public String getLimitTranslateContent(String content) throws Exception {
|
|
|
+ /*if (content.length() > 5000) {
|
|
|
+ String s = content.substring(0, 5000);
|
|
|
+ int i = s.lastIndexOf(",") + 1;
|
|
|
+ String s1 = s.substring(0, i);
|
|
|
+ str = str + this.getTranslateContent(s1);
|
|
|
+ String s2 = s.substring(i);
|
|
|
+ String s3 = this.getLimitTranslateContent(s2);
|
|
|
+ str = str + s3;
|
|
|
+ } else {
|
|
|
+ str = this.getTranslateContent(content);
|
|
|
+ }*/
|
|
|
+ String str = "";
|
|
|
+ String regex = "(?<!\\d)\\.(?!\\d)|[;。;]";
|
|
|
+ String regex1 = "(?<!\\d)\\.(?!\\d)";
|
|
|
+ Pattern pattern = Pattern.compile(regex);
|
|
|
+ Pattern pattern1 = Pattern.compile(regex1);
|
|
|
+ while (content.length() > 5000) {
|
|
|
+ String s2 = content.substring(0, 5000);
|
|
|
+ Matcher matcher = pattern.matcher(s2);
|
|
|
+ Matcher matcher1 = pattern1.matcher(s2);
|
|
|
+ int lastIndex = -1;
|
|
|
+ while (matcher.find()) {
|
|
|
+ lastIndex = matcher.end() - 1; // matcher.end() 返回的是匹配项之后的索引,所以减1得到最后一个字符的索引
|
|
|
+ }
|
|
|
+ if (lastIndex == -1) {
|
|
|
+ while (matcher1.find()) {
|
|
|
+ lastIndex = matcher1.end() - 1; // matcher.end() 返回的是匹配项之后的索引,所以减1得到最后一个字符的索引
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String s = content.substring(0, lastIndex + 1);
|
|
|
+ String translateContent = this.getTranslateContent(s);
|
|
|
+ str = str + translateContent;
|
|
|
+ content = content.substring(lastIndex + 1);
|
|
|
+ }
|
|
|
+ String translateContent = this.getTranslateContent(content);
|
|
|
+ str = str + translateContent;
|
|
|
+ return str;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据文本获取翻译内容
|
|
|
*
|
|
@@ -450,7 +491,7 @@ public class TranslateService {
|
|
|
* @return
|
|
|
*/
|
|
|
public TranslateVO getTranslateByText(TranslateDTO vo) throws Exception {
|
|
|
- String translateContent = this.getTranslateContent(vo.getContent());
|
|
|
+ String translateContent = this.getLimitTranslateContent(vo.getContent());
|
|
|
TranslateVO translateVO = new TranslateVO();
|
|
|
translateVO.setOriginalContent(vo.getContent());
|
|
|
translateVO.setTranslationContent(translateContent);
|
|
@@ -481,6 +522,7 @@ public class TranslateService {
|
|
|
return explainTextVOS;
|
|
|
}
|
|
|
|
|
|
+ //根据专利号和序号查询是否已有翻译
|
|
|
public List<String> getTranslateOrder(String patentNo, Integer sort) throws IOException {
|
|
|
List<String> list = new ArrayList<>();
|
|
|
SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
@@ -505,4 +547,29 @@ public class TranslateService {
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
|
+
|
|
|
+ //根据专利号和序号查询是否已有翻译
|
|
|
+ public Long getTranslateByPatentNo(String patentNo) throws IOException {
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
+ //设置查询索引
|
|
|
+ builder.index("translate");
|
|
|
+ Query q1 = QueryBuilders.term(t -> t.field("patent_no").value(patentNo));
|
|
|
+ Query q2 = QueryBuilders.term(t -> t.field("patent_field").value("3"));
|
|
|
+ Query q3 = QueryBuilders.term(t -> t.field("if_origin").value(true));
|
|
|
+ Query bool = QueryBuilders.bool(i -> i.must(q1, q2, q3));
|
|
|
+ builder.query(bool);
|
|
|
+ builder.size(1000);
|
|
|
+ builder.trackTotalHits(i -> i.enabled(true));
|
|
|
+ SearchResponse<PatentTranslate> response = client.search(builder.build(), PatentTranslate.class);
|
|
|
+// List<Hit<PatentTranslate>> hits = response.hits().hits();
|
|
|
+// for (Hit<PatentTranslate> hit : hits) {
|
|
|
+// PatentTranslate source = hit.source();
|
|
|
+// String content = source.getContent().getTextContent();
|
|
|
+// if (StringUtils.isNotEmpty(content)) {
|
|
|
+// list.add(content);
|
|
|
+// }
|
|
|
+// }
|
|
|
+ return response.hits().total().value();
|
|
|
+ }
|
|
|
}
|