|
@@ -0,0 +1,75 @@
|
|
|
+package com.diagbot.facade;
|
|
|
+
|
|
|
+import com.diagbot.client.AINeoServiceClient;
|
|
|
+import com.diagbot.dto.FeatureDTO;
|
|
|
+import com.diagbot.dto.RespDTO;
|
|
|
+import com.diagbot.entity.Concept;
|
|
|
+import com.diagbot.enums.LexiconTypeEnum;
|
|
|
+import com.diagbot.exception.CommonErrorCode;
|
|
|
+import com.diagbot.exception.CommonException;
|
|
|
+import com.diagbot.util.EntityUtil;
|
|
|
+import com.diagbot.util.ListUtil;
|
|
|
+import com.diagbot.util.RespDTOUtil;
|
|
|
+import com.diagbot.vo.NLPVO;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:
|
|
|
+ * @Author:zhaops
|
|
|
+ * @time: 2020/4/26 13:46
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class FeatureV2Facade {
|
|
|
+ @Autowired
|
|
|
+ private AINeoServiceClient aiNeoServiceClient;
|
|
|
+ @Autowired
|
|
|
+ private ConceptFacade conceptFacade;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 特征词提取
|
|
|
+ *
|
|
|
+ * @param nlpvo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<FeatureDTO> extract(NLPVO nlpvo) {
|
|
|
+ RespDTO<List<FeatureDTO>> respDTO = aiNeoServiceClient.extract(nlpvo);
|
|
|
+ RespDTOUtil.respNGDealCover(respDTO, "特征词提取失败");
|
|
|
+ return respDTO.data;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 症状特征词提取
|
|
|
+ *
|
|
|
+ * @param nlpvo
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<FeatureDTO> symptomFeatureV2(NLPVO nlpvo) {
|
|
|
+ List<FeatureDTO> featureList = extract(nlpvo);
|
|
|
+ if (ListUtil.isNotEmpty(featureList)) {
|
|
|
+ List<FeatureDTO> symptoms = featureList
|
|
|
+ .stream()
|
|
|
+ .filter(i -> i.getType().equals(1))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<String> names = symptoms
|
|
|
+ .stream()
|
|
|
+ .map(i -> i.getStandard())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<Concept> concepts = conceptFacade.getListByNamesAndType(names, LexiconTypeEnum.SYMPTOM.getKey());
|
|
|
+ Map<String, Long> conceptMap
|
|
|
+ = EntityUtil.makeMapWithKeyValue(concepts, "libName", "id");
|
|
|
+ symptoms.forEach(symptom -> {
|
|
|
+ if (conceptMap.containsKey(symptom.getStandard())) {
|
|
|
+ symptom.setConceptId(conceptMap.get(symptom.getStandard()));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return symptoms;
|
|
|
+ } else {
|
|
|
+ throw new CommonException(CommonErrorCode.NOT_EXISTS, "未提取到症状特征");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|