Pārlūkot izejas kodu

判断模型抓取的药用信息是否在20个字节之内

wangsy 4 gadi atpakaļ
vecāks
revīzija
3b0505db8a

+ 48 - 3
kernel/src/main/java/com/lantone/qc/kernel/structure/ai/process/EntityProcessDrug.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.lantone.qc.kernel.structure.ai.model.EntityEnum;
 import com.lantone.qc.kernel.structure.ai.model.Lemma;
 import com.lantone.qc.pub.model.entity.*;
+import org.apache.commons.beanutils.BeanUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
@@ -20,10 +21,15 @@ public class EntityProcessDrug extends EntityProcess {
         //药物
         List<Drug> drugs = new ArrayList<>();
         try {
-            List<Lemma> DrugLemmas = createEntityTree(aiOut, EntityEnum.DRUG.toString());
-            for (Lemma lemma : DrugLemmas) {
+            List<Lemma> drugLemmas = createEntityTree(aiOut, EntityEnum.DRUG.toString());
+            List<Lemma> consumptionLemmas = createEntityTree(aiOut, EntityEnum.CONSUMPTION.toString().split("-")[0]);
+            List<Lemma> usageWardRoundLemmas = createEntityTree(aiOut, EntityEnum.USAGE_WARD_ROUND.toString());
+            List<Lemma> frequencyLemmas = createEntityTree(aiOut, EntityEnum.FREQUENCY.toString());
+            List<Lemma> stopLemmas = createEntityTree(aiOut, EntityEnum.STOP.toString());
+            List<Lemma> reasonsForAntibioticLemmas = createEntityTree(aiOut, EntityEnum.REASONS_FOR_ANTIBIOTIC.toString());
+            for (Lemma lemma : drugLemmas) {
                 int lemmaPosition = Integer.parseInt(lemma.getPosition());
-                if (content.substring(Math.max(0, lemmaPosition - 10), lemmaPosition).contains("暂停")){
+                if (content.substring(Math.max(0, lemmaPosition - 10), lemmaPosition).contains("暂停")) {
                     continue;
                 }
                 Drug drug = new Drug();
@@ -33,6 +39,26 @@ public class EntityProcessDrug extends EntityProcess {
                 drug.setFrequency(findTAfter(lemma, new Frequency(), EntityEnum.FREQUENCY.toString()));
                 drug.setStop(findTAfter(lemma, new Stop(), EntityEnum.STOP.toString()));
                 drug.setReasonsForAntibiotic(findTAfter(lemma, new ReasonsForAntibiotic(), EntityEnum.REASONS_FOR_ANTIBIOTIC.toString()));
+                //用量
+                if (drug.getConsumption() == null) {
+                    drug.setConsumption(setDrugs(consumptionLemmas, lemma, new Consumption()));
+                }
+                //用法
+                if (drug.getUsageWardRound() == null) {
+                    drug.setUsageWardRound(setDrugs(usageWardRoundLemmas, lemma, new UsageWardRound()));
+                }
+                //频率
+                if (drug.getFrequency() == null) {
+                    drug.setFrequency(setDrugs(frequencyLemmas, lemma, new Frequency()));
+                }
+                //停用
+                if (drug.getStop() == null) {
+                    drug.setStop(setDrugs(stopLemmas, lemma, new Stop()));
+                }
+                //抗生素使用原因
+                if (drug.getReasonsForAntibiotic() == null) {
+                    drug.setReasonsForAntibiotic(setDrugs(reasonsForAntibioticLemmas, lemma, new ReasonsForAntibiotic()));
+                }
                 drugs.add(drug);
             }
         } catch (Exception e) {
@@ -41,4 +67,23 @@ public class EntityProcessDrug extends EntityProcess {
         }
         return drugs;
     }
+
+    /**
+     * 模型抓取抗生素信息为空的时候判断是否在20个字节之内
+     *
+     * @param Lemmas
+     * @param lemma
+     * @param t
+     * @return
+     * @throws Exception
+     */
+    private <T> T setDrugs(List<Lemma> Lemmas, Lemma lemma, T t) throws Exception {
+        for (Lemma lem : Lemmas) {
+            if (Integer.parseInt(lem.getPosition()) - Integer.parseInt(lemma.getPosition()) <= 20) {
+                BeanUtils.copyProperty(t, "name", lemma.getText());
+                return t;
+            }
+        }
+        return null;
+    }
 }