|
@@ -1,33 +1,36 @@
|
|
|
package cn.cslg.pas.service.common;
|
|
|
|
|
|
-import cn.cslg.pas.common.dto.OPS.GetSearchBiblioParamsDTO;
|
|
|
-import cn.cslg.pas.common.utils.DataUtils;
|
|
|
-import cn.cslg.pas.common.utils.DateUtils;
|
|
|
-import cn.hutool.crypto.SecureUtil;
|
|
|
-import cn.hutool.crypto.digest.HMac;
|
|
|
+import cn.cslg.pas.common.dto.PatentColumnDTO;
|
|
|
+import cn.cslg.pas.common.dto.TranslateDTO;
|
|
|
+import cn.cslg.pas.common.dto.business.SelectClaimDTO;
|
|
|
+import cn.cslg.pas.common.dto.es.EsTranslateDTO;
|
|
|
+import cn.cslg.pas.common.vo.TranslateVO;
|
|
|
+import cn.cslg.pas.domain.es.Patent;
|
|
|
+import cn.cslg.pas.domain.es.PatentTranslate;
|
|
|
+import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
|
|
+import co.elastic.clients.elasticsearch._types.query_dsl.Query;
|
|
|
+import co.elastic.clients.elasticsearch._types.query_dsl.QueryBuilders;
|
|
|
+import co.elastic.clients.elasticsearch.core.SearchRequest;
|
|
|
+import co.elastic.clients.elasticsearch.core.SearchResponse;
|
|
|
+import co.elastic.clients.elasticsearch.core.search.Hit;
|
|
|
import com.aliyun.alimt20181012.models.TranslateGeneralResponse;
|
|
|
import com.aliyun.tea.TeaException;
|
|
|
-import okhttp3.MediaType;
|
|
|
-import okhttp3.OkHttpClient;
|
|
|
-import okhttp3.Request;
|
|
|
-import okhttp3.RequestBody;
|
|
|
-import org.springframework.beans.factory.annotation.Value;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.util.Base64;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.Objects;
|
|
|
-import java.util.UUID;
|
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
-import java.util.Base64.Encoder;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
+@RequiredArgsConstructor(onConstructor_ = {@Lazy})
|
|
|
public class TranslateService {
|
|
|
+ private final ElasticsearchClient client;
|
|
|
|
|
|
-
|
|
|
+ //---------------------外部翻译接口------------------------
|
|
|
public static com.aliyun.alimt20181012.Client createClient() throws Exception {
|
|
|
-
|
|
|
String key = "LTAI5tGyG1Q7fKprgg1nWhXj";
|
|
|
String sercet = "Y6Erboh5lEFiRPR4XK8oCPMvUzYGLN";
|
|
|
// 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
|
|
@@ -42,19 +45,19 @@ public class TranslateService {
|
|
|
return new com.aliyun.alimt20181012.Client(config);
|
|
|
}
|
|
|
|
|
|
- public String translateGeneral() throws Exception {
|
|
|
+ public String getTranslateContent(String content) throws Exception {
|
|
|
com.aliyun.alimt20181012.Client client = TranslateService.createClient();
|
|
|
com.aliyun.alimt20181012.models.TranslateGeneralRequest translateGeneralRequest = new com.aliyun.alimt20181012.models.TranslateGeneralRequest()
|
|
|
.setFormatType("text")
|
|
|
.setSourceLanguage("auto")
|
|
|
.setTargetLanguage("zh")
|
|
|
- .setSourceText("my name is limeimei")
|
|
|
+ .setSourceText(content)
|
|
|
.setScene("general");
|
|
|
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
|
|
try {
|
|
|
// 复制代码运行请自行打印 API 的返回值
|
|
|
TranslateGeneralResponse translateGeneralResponse = client.translateGeneralWithOptions(translateGeneralRequest, runtime);
|
|
|
- String re= translateGeneralResponse.getBody().getData().translated;
|
|
|
+ String re = translateGeneralResponse.getBody().getData().translated;
|
|
|
return re;
|
|
|
} catch (TeaException error) {
|
|
|
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
|
@@ -74,4 +77,107 @@ public class TranslateService {
|
|
|
}
|
|
|
return "";
|
|
|
}
|
|
|
+
|
|
|
+ //根据专利号获取专利信息
|
|
|
+ public PatentColumnDTO getPatentByPatentNo(String patentNo) throws IOException {
|
|
|
+ PatentColumnDTO patentColumnDTO = new PatentColumnDTO();
|
|
|
+ SearchRequest.Builder builder = new SearchRequest.Builder();
|
|
|
+ //设置查询索引
|
|
|
+ builder.index("patent");
|
|
|
+ Query query = QueryBuilders.term(t -> t.field("patent_no.keyword").value(patentNo));
|
|
|
+ builder.query(query);
|
|
|
+ SearchResponse<Patent> response = client.search(builder.build(), Patent.class);
|
|
|
+ List<Hit<Patent>> hits = response.hits().hits();
|
|
|
+ for (Hit<Patent> hit : hits) {
|
|
|
+ Patent patent = hit.source();
|
|
|
+ BeanUtils.copyProperties(patent, patentColumnDTO);
|
|
|
+ }
|
|
|
+ return patentColumnDTO;
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据专利号、字段栏位、序号获取专利翻译信息
|
|
|
+ public List<EsTranslateDTO> getPatentTranslateByPatentNo(TranslateDTO vo) throws IOException {
|
|
|
+ String patentNo = vo.getPatentNo();
|
|
|
+ String patentField = vo.getPatentField();
|
|
|
+ Integer order = vo.getOrder();
|
|
|
+ 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(patentField));
|
|
|
+ Query bool = null;
|
|
|
+ if (patentField.equals("3") || patentField.equals("4")) {
|
|
|
+ Query q3 = QueryBuilders.term(t -> t.field("content.order").value(order));
|
|
|
+ bool = QueryBuilders.bool(i -> i.must(q1, q2, q3));
|
|
|
+ } else {
|
|
|
+ bool = QueryBuilders.bool(i -> i.must(q1, q2));
|
|
|
+ }
|
|
|
+ builder.query(bool);
|
|
|
+ SearchResponse<PatentTranslate> response = client.search(builder.build(), PatentTranslate.class);
|
|
|
+ List<Hit<PatentTranslate>> hits = response.hits().hits();
|
|
|
+ List<EsTranslateDTO> translateDTOS = new ArrayList<>();
|
|
|
+ for (Hit<PatentTranslate> hit : hits) {
|
|
|
+ PatentTranslate translate = hit.source();
|
|
|
+ EsTranslateDTO translateDTO = new EsTranslateDTO();
|
|
|
+ BeanUtils.copyProperties(translate, translateDTO);
|
|
|
+ translateDTOS.add(translateDTO);
|
|
|
+ }
|
|
|
+ return translateDTOS;
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加专利翻译
|
|
|
+
|
|
|
+
|
|
|
+ //------------------------------------返回翻译内容--------------------------
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据标题和摘要获取翻译内容
|
|
|
+ * @param vo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public TranslateVO getTranslateByTIAndAb(TranslateDTO vo) throws IOException {
|
|
|
+ List<EsTranslateDTO> translateDTOS = this.getPatentTranslateByPatentNo(vo);
|
|
|
+ if (CollectionUtils.isEmpty(translateDTOS)) {
|
|
|
+
|
|
|
+ }
|
|
|
+ TranslateVO translateVO = new TranslateVO();
|
|
|
+ translateVO.setOriginalContent(vo.getContent());
|
|
|
+ translateVO.setTranslationContent("");
|
|
|
+ return translateVO;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据权利要求获取翻译内容
|
|
|
+ * @param vo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<TranslateVO> getTranslateByClaim(TranslateDTO vo) {
|
|
|
+ List<TranslateVO> translateVOS = new ArrayList<>();
|
|
|
+ return translateVOS;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据说明书获取翻译内容
|
|
|
+ * @param vo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<TranslateVO> getTranslateByPFT(TranslateDTO vo) {
|
|
|
+ List<TranslateVO> translateVOS = new ArrayList<>();
|
|
|
+ return translateVOS;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据文本获取翻译内容
|
|
|
+ * @param vo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public TranslateVO getTranslateByText(TranslateDTO vo) throws Exception {
|
|
|
+ String translateContent = this.getTranslateContent(vo.getContent());
|
|
|
+ TranslateVO translateVO = new TranslateVO();
|
|
|
+ translateVO.setOriginalContent(vo.getContent());
|
|
|
+ translateVO.setTranslationContent(translateContent);
|
|
|
+ return translateVO;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|