Pārlūkot izejas kodu

修改关系抽取模型工具类

hujing 5 gadi atpakaļ
vecāks
revīzija
2cd8fa62f5

+ 3 - 22
common-push/src/main/java/org/diagbot/common/push/work/ParamsDataProxy.java

@@ -24,25 +24,6 @@ import java.util.*;
  **/
 public class ParamsDataProxy {
     Logger logger = LoggerFactory.getLogger(ParamsDataProxy.class);
-    //标准词只处理的词性
-    public static NegativeEnum[] negativeEnums = new NegativeEnum[] { NegativeEnum.VITAL_INDEX, NegativeEnum.SYMPTOM
-            , NegativeEnum.DIGITS, NegativeEnum.EVENT_TIME, NegativeEnum.UNIT, NegativeEnum.DIAG_STAND
-            , NegativeEnum.OTHER };
-    //标准词处理的三元组
-    public static NegativeEnum[][] negativeEnumTriple = {
-            { NegativeEnum.VITAL_INDEX, NegativeEnum.DIGITS, NegativeEnum.UNIT },
-            { NegativeEnum.VITAL_INDEX, NegativeEnum.DIGITS, NegativeEnum.EVENT_TIME },
-            { NegativeEnum.SYMPTOM, NegativeEnum.DIGITS, NegativeEnum.UNIT },
-            { NegativeEnum.SYMPTOM, NegativeEnum.DIGITS, NegativeEnum.EVENT_TIME },
-            { NegativeEnum.DIAG_STAND, NegativeEnum.DIGITS, NegativeEnum.UNIT },
-            { NegativeEnum.DIAG_STAND, NegativeEnum.DIGITS, NegativeEnum.EVENT_TIME },
-            { NegativeEnum.DIAG_STAND, NegativeEnum.DIGITS, NegativeEnum.OTHER }
-    };
-    //标准词处理的二元组
-    public static NegativeEnum[][] negativeEnumTwoTuple = {
-            { NegativeEnum.VITAL_INDEX, NegativeEnum.DIGITS },
-            { NegativeEnum.SYMPTOM, NegativeEnum.DIGITS }
-    };
 
     public void createNormalInfo(SearchData searchData) throws Exception {
         //计算年龄区间
@@ -142,11 +123,11 @@ public class ParamsDataProxy {
         if (!StringUtils.isEmpty(searchData.getPacs())) {
             //关系抽取模型
             AlgorithmCNNExecutorPacs algorithmCNNExecutor = RelationExtractionFactory.getInstance();
-            RelationExtractionCreateSearchData re = new RelationExtractionCreateSearchData();
+            RelationExtractionUtil re = new RelationExtractionUtil();
             //Pacs原始分词结果
-            List<List<String>> execute = algorithmCNNExecutor.execute(searchData.getPacs(), re.createSearchData(searchData));
+            List<List<String>> execute = algorithmCNNExecutor.execute(searchData.getPacs(), re.createTriad(searchData));
             if (execute != null && execute.size() > 0) {
-                re.start(execute, searchData);
+                re.addToSearchDataInputs(execute, searchData);
             }
         }
     }

+ 5 - 5
common-push/src/main/java/org/diagbot/common/push/work/RelationExtractionCreateSearchData.java

@@ -2,7 +2,6 @@ package org.diagbot.common.push.work;
 
 import org.algorithm.core.cnn.entity.Lemma;
 import org.algorithm.core.cnn.entity.Triad;
-import org.apache.commons.lang3.StringUtils;
 import org.diagbot.common.push.bean.SearchData;
 import org.diagbot.common.push.util.PushConstants;
 import org.diagbot.nlp.participle.ParticipleUtil;
@@ -21,8 +20,8 @@ import java.util.Map;
  * @Author: HUJING
  * @Date: 2019/9/9 17:30
  */
-public class RelationExtractionCreateSearchData {
-    public List<Triad> createSearchData(SearchData searchData) throws IOException {
+public class RelationExtractionUtil {
+    public List<Triad> createTriad(SearchData searchData) throws IOException {
         List<Triad> triads = new ArrayList<>();
         String[] pacsSplits = searchData.getPacs().trim().split("。|\n");
         List<Lemma> lemmaList = new ArrayList<>();
@@ -30,7 +29,8 @@ public class RelationExtractionCreateSearchData {
         for (String pacsSplit : pacsSplits) {
             LexemePath<Lexeme> pacsLexemes = ParticipleUtil.participlePacs(pacsSplit);
             for (int i = 0; i < pacsLexemes.size(); i++) {
-                if ("44".contains(pacsLexemes.get(i).getProperty())) {
+                //跳过非医学词
+                if (Constants.word_property_other.contains(pacsLexemes.get(i).getProperty())) {
                     continue;
                 }
                 lemma = new Lemma();
@@ -51,7 +51,7 @@ public class RelationExtractionCreateSearchData {
         return triads;
     }
 
-    public void start(List<List<String>> relationExtractionContents, SearchData searchData) throws Exception {
+    public void addToSearchDataInputs(List<List<String>> relationExtractionContents, SearchData searchData) throws Exception {
         StringBuffer sb = null;
         for (List<String> contents : relationExtractionContents) {
             sb = new StringBuffer();