Browse Source

algorithm和nlp模块循环引用
maven插件版本指定
两者POM文件更新

louhr 6 years ago
parent
commit
c4aaff6759

+ 0 - 5
algorithm/pom.xml

@@ -25,11 +25,6 @@
             <artifactId>public</artifactId>
             <version>${project.version}</version>
         </dependency>
-        <dependency>
-            <groupId>org.diagbot</groupId>
-            <artifactId>nlp</artifactId>
-            <version>${project.version}</version>
-        </dependency>
         <dependency>
             <groupId>org.tensorflow</groupId>
             <artifactId>tensorflow</artifactId>

+ 49 - 8
nlp/src/main/java/org/diagbot/nlp/relation/extract/PresentExtract.java

@@ -4,7 +4,7 @@ import org.algorithm.core.cnn.model.Lemma;
 import org.algorithm.core.cnn.model.Triad;
 import org.diagbot.nlp.participle.word.Lexeme;
 import org.diagbot.nlp.participle.word.LexemePath;
-import org.diagbot.nlp.relation.extract.cell.BodyPart;
+import org.diagbot.nlp.relation.extract.cell.*;
 import org.diagbot.nlp.relation.extract.module.Symptom;
 import org.diagbot.nlp.util.NegativeEnum;
 import org.diagbot.nlp.util.NlpUtil;
@@ -22,8 +22,10 @@ import java.util.List;
 public class PresentExtract extends BaseExtract {
 
     private NegativeEnum[] symptom_type = new NegativeEnum[]{NegativeEnum.SYMPTOM};
+    private NegativeEnum[] unit_time_type = new NegativeEnum[]{NegativeEnum.EVENT_TIME, NegativeEnum.UNIT};
     private NegativeEnum[] vital_type = new NegativeEnum[]{NegativeEnum.VITAL_INDEX};
     private NegativeEnum[] body_part_type = new NegativeEnum[]{NegativeEnum.BODY_PART};
+    private NegativeEnum[] position_type = new NegativeEnum[]{NegativeEnum.POSITION};
     private NegativeEnum[] property_type = new NegativeEnum[]{NegativeEnum.PROPERTY};
     private NegativeEnum[] degree_type = new NegativeEnum[]{NegativeEnum.DEEP};
     private NegativeEnum[] cause_type = new NegativeEnum[]{NegativeEnum.CAUSE};
@@ -38,26 +40,65 @@ public class PresentExtract extends BaseExtract {
             property = param_lemma.getProperty();
             if (NlpUtil.isFeature(property, symptom_type)) {          //特征词 症状
                 Symptom symptom = new Symptom();
-                lookSymptomRelations(param_lemma, triads, symptom);
+                lookSymptomRelations(param_lemma, cnn_lemmas, symptom);
             }
         }
     }
 
-    private void lookSymptomRelations(Lemma param_lemma, List<Triad> triads, Symptom symptom) {
-        Lemma lemma = null;
-        for (Triad triad : triads) {
-            if (triad.getL_1().getText().equals(param_lemma.getText())
-                    && triad.getL_1().getPosition().equals(param_lemma.getPosition())) {
-                addFeatureToSymptom(triad.getL_2(), symptom);
+    private void lookSymptomRelations(Lemma param_lemma, List<Lemma> cnn_lemmas, Symptom symptom) {
+        for (Lemma cnn_l : cnn_lemmas) {
+            if (cnn_l.getText().equals(param_lemma.getText())
+                    && cnn_l.getPosition().equals(param_lemma.getPosition())) {
+                for (Lemma relation_l : cnn_l.getRelationLemmas()) {
+                    addFeatureToSymptom(relation_l, symptom);
+                }
             }
         }
     }
 
     private void addFeatureToSymptom(Lemma lemma, Symptom symptom) {
+        //时间信息
+        if (NlpUtil.isFeature(lemma.getProperty(), unit_time_type)) {
+            PD pd = new PD();
+            pd.setValue(lemma.getText());
+            symptom.setPd(pd);
+        }
         //部位信息
         if (NlpUtil.isFeature(lemma.getProperty(), body_part_type)) {
             BodyPart bodyPart = new BodyPart();
             bodyPart.setPartBodyName(lemma.getText());
+            if (lemma.getRelationLemmas().size() > 0) {
+                Lemma l = lemma.getRelationLemmas().get(0);
+                if (NlpUtil.isFeature(l.getProperty(), position_type)) {
+                    bodyPart.setDirection(l.getText());
+                }
+            }
+            symptom.setBodyPart(bodyPart);
+        }
+        //程度
+        if (NlpUtil.isFeature(lemma.getProperty(), degree_type)) {
+            Degree degree = new Degree();
+            degree.setDegreeName(lemma.getText());
+            for (Lemma l : lemma.getRelationLemmas()) {
+                if (NlpUtil.isFeature(l.getProperty(), unit_time_type)) {
+                    PD pd = new PD();
+                    pd.setValue(l.getText());
+                    degree.setPd(pd);
+                }
+            }
+            symptom.setDegree(degree);
+        }
+        //性质
+        if (NlpUtil.isFeature(lemma.getProperty(), property_type)) {
+            Property property = new Property();
+            property.setPropertyName(lemma.getText());
+            symptom.setProperty(property);
+        }
+        //诱因
+        if (NlpUtil.isFeature(lemma.getProperty(), cause_type)) {
+            Cause cause = new Cause();
+            cause.setCauseName(lemma.getText());
+            symptom.setCause(cause);
         }
     }
 

+ 72 - 0
nlp/src/main/java/org/diagbot/nlp/relation/extract/module/Symptom.java

@@ -1,5 +1,7 @@
 package org.diagbot.nlp.relation.extract.module;
 
+import org.diagbot.nlp.relation.extract.cell.*;
+
 /**
  * @ClassName org.diagbot.nlp.relation.extract.cell.Symptom
  * @Description TODO
@@ -11,4 +13,74 @@ public class Symptom {
     private String symptomName;
     private String negative;
 
+    private BodyPart  bodyPart;
+    private Degree degree;
+    private Cause cause;
+    private Property property;
+    private PD pd;
+    private Factor factor;
+
+    public String getSymptomName() {
+        return symptomName;
+    }
+
+    public void setSymptomName(String symptomName) {
+        this.symptomName = symptomName;
+    }
+
+    public String getNegative() {
+        return negative;
+    }
+
+    public void setNegative(String negative) {
+        this.negative = negative;
+    }
+
+    public BodyPart getBodyPart() {
+        return bodyPart;
+    }
+
+    public void setBodyPart(BodyPart bodyPart) {
+        this.bodyPart = bodyPart;
+    }
+
+    public Degree getDegree() {
+        return degree;
+    }
+
+    public void setDegree(Degree degree) {
+        this.degree = degree;
+    }
+
+    public Cause getCause() {
+        return cause;
+    }
+
+    public void setCause(Cause cause) {
+        this.cause = cause;
+    }
+
+    public Property getProperty() {
+        return property;
+    }
+
+    public void setProperty(Property property) {
+        this.property = property;
+    }
+
+    public PD getPd() {
+        return pd;
+    }
+
+    public void setPd(PD pd) {
+        this.pd = pd;
+    }
+
+    public Factor getFactor() {
+        return factor;
+    }
+
+    public void setFactor(Factor factor) {
+        this.factor = factor;
+    }
 }

+ 1 - 7
pom.xml

@@ -294,6 +294,7 @@
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-compiler-plugin</artifactId>
+                <version>3.8.0</version>
                 <configuration>
                     <compilerVersion>1.8</compilerVersion>
                     <source>1.8</source>
@@ -312,13 +313,6 @@
                 </includes>
                 <filtering>false</filtering>
             </resource>
-            <resource>
-                <directory>src/main/resources</directory>
-                <excludes>
-                    <exclude>**/model/*.*</exclude>
-                    <exclude>**/*.txt</exclude>
-                </excludes>
-            </resource>
         </resources>
 
         <finalName>push</finalName>

+ 1 - 1
push-web/pom.xml

@@ -64,7 +64,7 @@
 			<resource>
 				<directory>src/main/resources</directory>
 				<includes>
-					<include>**/*.yml</include>
+					<include>**/*.*</include>
 				</includes>
 			</resource>
 		</resources>