Quellcode durchsuchen

关系抽取症状 体征反写

louhr vor 6 Jahren
Ursprung
Commit
58be63d76b

+ 1 - 1
algorithm/src/main/java/org/algorithm/core/cnn/entity/Lemma.java

@@ -16,7 +16,7 @@ public class Lemma {
     private int len;
     private String property;
 
-    private List<Lemma> relationLemmas;
+    private List<Lemma> relationLemmas = new ArrayList<>();
 
     public String getText() {
         return text;

+ 53 - 22
nlp/src/main/java/org/diagbot/nlp/relation/RelationAnalyze.java

@@ -1,16 +1,15 @@
 package org.diagbot.nlp.relation;
 
-import com.alibaba.fastjson.JSON;
 import org.algorithm.core.cnn.AlgorithmCNNExecutor;
 import org.algorithm.core.cnn.entity.Lemma;
 import org.algorithm.core.cnn.entity.Triad;
-import org.algorithm.core.cnn.model.RelationExtractionModel;
 import org.algorithm.core.cnn.model.impl.RelationExtractionModelImpl;
 import org.diagbot.nlp.feature.FeatureType;
 import org.diagbot.nlp.participle.ParticipleUtil;
 import org.diagbot.nlp.participle.word.Lexeme;
 import org.diagbot.nlp.participle.word.LexemePath;
 import org.diagbot.nlp.relation.extract.PresentExtract;
+import org.diagbot.nlp.relation.extract.VitalExtract;
 import org.diagbot.nlp.relation.extract.output.OutputInfo;
 import org.diagbot.nlp.util.Constants;
 import org.diagbot.nlp.util.NegativeEnum;
@@ -28,7 +27,7 @@ import java.util.List;
  **/
 public class RelationAnalyze {
     public List<OutputInfo> analyze(String content, FeatureType featureType) throws Exception {
-        String[] part_contents = content.split("\\。|\\;|\\;");
+        String[] part_contents = content.split("\\。|\\;\\\r|\\\n|\\;");
 
         List<OutputInfo> outputInfos = new ArrayList<>();
         for (String part_content : part_contents) {
@@ -37,14 +36,17 @@ public class RelationAnalyze {
             List<Lemma> lemmaParticiple = lexemeToTriadLemma(lexemes);
             //调用CNN模型
             AlgorithmCNNExecutor executor = new RelationExtractionModelImpl();
-            List<Triad> triads = executor.execute(content, lemmaParticiple);
+            List<Triad> triads = executor.execute(part_content, lemmaParticiple);
             //模型返回的三元组转树形结构
             List<Lemma> lemmaTree = traidToTree(triads, featureType);
-            OutputInfo outputInfo = null;
+            OutputInfo outputInfo = new OutputInfo();
             switch (featureType) {
                 case SYMPTOM:
                     PresentExtract presentExtract = new PresentExtract();
-                    outputInfo = presentExtract.extract(lemmaTree, lemmaParticiple);
+                    outputInfo = presentExtract.extract(outputInfo, lemmaTree, lemmaParticiple);
+                    //如果还有体征信息 也需要抽取
+                    VitalExtract vitalExtract = new VitalExtract();
+                    outputInfo = vitalExtract.extract(outputInfo, lemmaTree, lemmaParticiple);
             }
             if (outputInfo != null) {
                 outputInfos.add(outputInfo);
@@ -64,7 +66,7 @@ public class RelationAnalyze {
             if (!lexeme.getProperty().equals("99")) {
                 Lemma lemma = new Lemma();
                 lemma.setLen(lexeme.getLength());
-                lemma.setPosition(lexeme.getOffset() + "," + (lexeme.getOffset() + lexeme.getLength()));
+                lemma.setPosition(lexeme.getOffset() + "," + (lexeme.getOffset() + lexeme.getLength() - 1));
                 lemma.setText(lexeme.getText());
                 lemma.setProperty(lexeme.getProperty());
                 lemmas.add(lemma);
@@ -92,18 +94,30 @@ public class RelationAnalyze {
     private void select(List<Lemma> lemmaTree, List<Triad> triads, NegativeEnum[] type) {
         List<Triad> has_add_triads = new ArrayList<>();
         for (Triad triad : triads) {
+            Lemma origin_l = null;
+            Lemma relation_l = null;
             if (NlpUtil.isFeature(triad.getL_1().getProperty(), type)) {
-                Lemma lemma = triad.getL_1();
-                lemma.add(this.findRelationTriad(triads, has_add_triads, triad.getL_2()));
-                lemmaTree.add(lemma);
-                //已添加到树中的三元组
-                has_add_triads.add(triad);
+                origin_l = this.copyProperties(triad.getL_1());
+                relation_l = this.copyProperties(triad.getL_2());
             }
             if (NlpUtil.isFeature(triad.getL_2().getProperty(), type)) {
-                Lemma lemma = triad.getL_2();
-                lemma.add(this.findRelationTriad(triads, has_add_triads, triad.getL_1()));
-                lemmaTree.add(lemma);
-
+                origin_l = this.copyProperties(triad.getL_2());
+                relation_l = this.copyProperties(triad.getL_1());
+            }
+            if (origin_l != null && relation_l != null) {
+                boolean isFindFromTree = false;
+                for (Lemma l : lemmaTree) {
+                    if (l.getText().equals(origin_l.getText()) && l.getPosition().equals(origin_l.getPosition())) {
+                        origin_l = l;
+                        isFindFromTree = true;
+                        break;
+                    }
+                }
+                this.findRelationTriad(triads, triad, has_add_triads, relation_l, type);
+                origin_l.add(relation_l);
+                if (!isFindFromTree) {      //树上已有节点 不需要添加
+                    lemmaTree.add(origin_l);
+                }
                 //已添加到树中的三元组
                 has_add_triads.add(triad);
             }
@@ -111,21 +125,38 @@ public class RelationAnalyze {
         triads.removeAll(has_add_triads);
     }
 
-    private Lemma findRelationTriad(List<Triad> triads, List<Triad> has_add_triads, Lemma lemma) {
+    private boolean findRelationTriad(List<Triad> triads, Triad current_triad, List<Triad> has_add_triads, Lemma lemma, NegativeEnum[] type) {
+        boolean isFindRelation = false;
         for (Triad triad : triads) {
+            if (current_triad == triad) {
+                continue;
+            }
             if (triad.getL_1().getText().equals(lemma.getText())
-                    && triad.getL_1().getPosition().equals(lemma.getPosition())) {
-                lemma.add(triad.getL_2());
+                    && triad.getL_1().getPosition().equals(lemma.getPosition())
+                    && !NlpUtil.isFeature(triad.getL_2().getProperty(), type)) {
+                lemma.add(this.copyProperties(triad.getL_2()));
+                isFindRelation = true;
                 //已添加到树中的三元组
                 has_add_triads.add(triad);
             }
             if (triad.getL_2().getText().equals(lemma.getText())
-                    && triad.getL_2().getPosition().equals(lemma.getPosition())) {
-                lemma.add(triad.getL_1());
+                    && triad.getL_2().getPosition().equals(lemma.getPosition())
+                    && !NlpUtil.isFeature(triad.getL_1().getProperty(), type)) {
+                lemma.add(this.copyProperties(triad.getL_1()));
+                isFindRelation = true;
                 //已添加到树中的三元组
                 has_add_triads.add(triad);
             }
         }
-        return lemma;
+        return isFindRelation;
+    }
+
+    private Lemma copyProperties(Lemma lemma) {
+        Lemma l = new Lemma();
+        l.setLen(lemma.getLen());
+        l.setPosition(lemma.getPosition());
+        l.setProperty(lemma.getProperty());
+        l.setText(lemma.getText());
+        return l;
     }
 }

+ 6 - 0
nlp/src/main/java/org/diagbot/nlp/relation/extract/BaseExtract.java

@@ -1,5 +1,10 @@
 package org.diagbot.nlp.relation.extract;
 
+import org.algorithm.core.cnn.entity.Lemma;
+
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * @ClassName org.diagbot.nlp.relation.extract.BaseExtract
  * @Description TODO
@@ -8,4 +13,5 @@ package org.diagbot.nlp.relation.extract;
  * @Version 1.0
  **/
 public class BaseExtract {
+    protected List<Lemma> containsLemmaTree = new ArrayList<>();
 }

+ 28 - 24
nlp/src/main/java/org/diagbot/nlp/relation/extract/PresentExtract.java

@@ -7,7 +7,6 @@ import org.diagbot.nlp.relation.extract.output.OutputInfo;
 import org.diagbot.nlp.util.Constants;
 import org.diagbot.nlp.util.NlpUtil;
 
-import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -18,19 +17,12 @@ import java.util.List;
  * @Version 1.0
  **/
 public class PresentExtract extends BaseExtract {
-    private List<Lemma> containsLemmaTree = new ArrayList<>();
-
-    public OutputInfo extract(List<Lemma> lemmaTree, List<Lemma> lemmaParticiple) {
-        OutputInfo outputInfo = new OutputInfo();
-        String property = "";
+    public OutputInfo extract(OutputInfo outputInfo, List<Lemma> lemmaTree, List<Lemma> lemmaParticiple) {
         for (int index = 0; index < lemmaParticiple.size(); index++) {
             Lemma participle_lemma = lemmaParticiple.get(index);
-            property = participle_lemma.getProperty();
+            String property = participle_lemma.getProperty();
             if (NlpUtil.isFeature(property, Constants.symptom_type)) {          //特征词 症状
-                Symptom symptom = new Symptom();
-                symptom.setSymptomName(participle_lemma.getText());
-
-                lookSymptomRelations(participle_lemma, lemmaTree, symptom);
+                Symptom symptom = lookSymptomRelations(participle_lemma, lemmaTree);
                 outputInfo.getSymptoms().add(symptom);
             }
         }
@@ -38,33 +30,43 @@ public class PresentExtract extends BaseExtract {
         return outputInfo;
     }
 
-    private void lookSymptomRelations(Lemma param_lemma, List<Lemma> lemmaTree, Symptom symptom) {
+    private Symptom lookSymptomRelations(Lemma participle_lemma, List<Lemma> lemmaTree) {
+        Symptom symptom = new Symptom();
+        symptom.setSymptomName(participle_lemma.getText());
         for (Lemma cnn_l : lemmaTree) {
-            if (cnn_l.getText().equals(param_lemma.getText())
-                    && cnn_l.getPosition().equals(param_lemma.getPosition())) {
+            if (cnn_l.getText().equals(participle_lemma.getText())
+                    && cnn_l.getPosition().equals(participle_lemma.getPosition())) {
                 for (Lemma relation_l : cnn_l.getRelationLemmas()) {
                     addFeatureToSymptom(relation_l, symptom);
                 }
                 containsLemmaTree.add(cnn_l);
             }
         }
+        return symptom;
     }
 
     private void addFeatureToSymptom(Lemma lemma, Symptom symptom) {
         //时间信息
         if (NlpUtil.isFeature(lemma.getProperty(), Constants.unit_time_type)) {
-            PD pd = new PD();
-            pd.setValue(lemma.getText());
+            PD pd = symptom.getPd();
+            if (symptom.getPd() == null) {
+                pd = new PD();
+                pd.setValue(lemma.getText());
+            } else {
+                pd.setValue(pd.getValue() + "、" + lemma.getText());
+            }
             symptom.setPd(pd);
         }
         //部位信息
         if (NlpUtil.isFeature(lemma.getProperty(), Constants.body_part_type)) {
             BodyPart bodyPart = new BodyPart();
             bodyPart.setPartBodyName(lemma.getText());
-            if (lemma.getRelationLemmas().size() > 0) {
+            if (lemma.getRelationLemmas() != null && lemma.getRelationLemmas().size() > 0) {
                 Lemma l = lemma.getRelationLemmas().get(0);
                 if (NlpUtil.isFeature(l.getProperty(), Constants.position_type)) {
-                    bodyPart.setDirection(l.getText());
+                    Position position = new Position();
+                    position.setPositionName(l.getText());
+                    bodyPart.setPosition(position);
                 }
             }
             symptom.setBodyPart(bodyPart);
@@ -73,11 +75,13 @@ public class PresentExtract extends BaseExtract {
         if (NlpUtil.isFeature(lemma.getProperty(), Constants.degree_type)) {
             Degree degree = new Degree();
             degree.setDegreeName(lemma.getText());
-            for (Lemma l : lemma.getRelationLemmas()) {
-                if (NlpUtil.isFeature(l.getProperty(), Constants.unit_time_type)) {
-                    PD pd = new PD();
-                    pd.setValue(l.getText());
-                    degree.setPd(pd);
+            if (lemma.getRelationLemmas() != null) {
+                for (Lemma l : lemma.getRelationLemmas()) {
+                    if (NlpUtil.isFeature(l.getProperty(), Constants.unit_time_type)) {
+                        PD pd = new PD();
+                        pd.setValue(l.getText());
+                        degree.setPd(pd);
+                    }
                 }
             }
             symptom.setDegree(degree);
@@ -98,7 +102,7 @@ public class PresentExtract extends BaseExtract {
         //阴性
         if (NlpUtil.isFeature(lemma.getProperty(), Constants.negative_type)) {
             Negative negative = new Negative();
-            negative.setNegaName(lemma.getProperty());
+            negative.setNegaName(lemma.getText());
             symptom.setNegative(negative);
         }
     }

+ 76 - 0
nlp/src/main/java/org/diagbot/nlp/relation/extract/VitalExtract.java

@@ -0,0 +1,76 @@
+package org.diagbot.nlp.relation.extract;
+
+import org.algorithm.core.cnn.entity.Lemma;
+import org.diagbot.nlp.relation.extract.cell.*;
+import org.diagbot.nlp.relation.extract.module.Vital;
+import org.diagbot.nlp.relation.extract.output.OutputInfo;
+import org.diagbot.nlp.util.Constants;
+import org.diagbot.nlp.util.NlpUtil;
+
+import java.util.List;
+
+/**
+ * @ClassName org.diagbot.nlp.relation.extract.VitalExtract
+ * @Description TODO
+ * @Author fyeman
+ * @Date 2019/1/24/024 10:28
+ * @Version 1.0
+ **/
+public class VitalExtract extends BaseExtract {
+    public OutputInfo extract(OutputInfo outputInfo, List<Lemma> lemmaTree, List<Lemma> lemmaParticiple) {
+        for (int index = 0; index < lemmaParticiple.size(); index++) {
+            Lemma participle_lemma = lemmaParticiple.get(index);
+            String property = participle_lemma.getProperty();
+            if (NlpUtil.isFeature(property, Constants.vital_type)) {          //特征词 体征指标、体征结果、部位
+                Vital vital = lookVitalRelations(participle_lemma, lemmaTree);
+                if (vital != null) {
+                    outputInfo.getVitals().add(vital);
+                }
+            }
+        }
+        lemmaTree.removeAll(containsLemmaTree);
+        return outputInfo;
+    }
+
+    private Vital lookVitalRelations(Lemma participle_lemma, List<Lemma> lemmaTree) {
+        //在三元组中查找是否有该特征信息
+        Vital vital = null;
+        for (Lemma cnn_l : lemmaTree) {
+            if (cnn_l.getText().equals(participle_lemma.getText())
+                    && cnn_l.getPosition().equals(participle_lemma.getPosition())) {    //三元组中存在该特征
+                vital = new Vital();
+                vital.setVitalName(cnn_l.getText());
+                for (Lemma l : cnn_l.getRelationLemmas()) {
+                    if (NlpUtil.isFeature(l.getProperty(), Constants.negative_type)) {      //阴性
+                        Negative negative = new Negative();
+                        negative.setNegaName(l.getText());
+                        vital.setNegative(negative);
+                    } else if (NlpUtil.isFeature(l.getProperty(), Constants.degree_type)) {   //程度
+                        Degree degree = new Degree();
+                        degree.setDegreeName(l.getText());
+                        vital.setDegree(degree);
+                    } else if (NlpUtil.isFeature(l.getProperty(), Constants.body_part_type)) {   //方位
+                        BodyPart bodyPart = new BodyPart();
+                        bodyPart.setPartBodyName(l.getText());
+                        //部位需要查看下有没有方位
+                        for (Lemma position_l : l.getRelationLemmas()) {
+                            if (NlpUtil.isFeature(l.getProperty(), Constants.position_type)) {
+                                Position position = new Position();
+                                position.setPositionName(position_l.getText());
+                                bodyPart.setPosition(position);
+                            }
+                        }
+                        vital.setBodyPart(bodyPart);
+                    } else if (NlpUtil.isFeature(l.getProperty(), Constants.vital_index_type)) {
+                        Item item = new Item();
+                        item.setItemName(l.getText());
+                        vital.setItem(item);
+                    }
+                }
+                containsLemmaTree.add(cnn_l);
+                break;
+            }
+        }
+        return vital;
+    }
+}

+ 5 - 5
nlp/src/main/java/org/diagbot/nlp/relation/extract/cell/BodyPart.java

@@ -2,7 +2,7 @@ package org.diagbot.nlp.relation.extract.cell;
 
 public class BodyPart {
     private String partBodyName;
-    private String direction;
+    private Position position;
 
     public String getPartBodyName() {
         return partBodyName;
@@ -12,11 +12,11 @@ public class BodyPart {
         this.partBodyName = partBodyName;
     }
 
-    public String getDirection() {
-        return direction;
+    public Position getPosition() {
+        return position;
     }
 
-    public void setDirection(String direction) {
-        this.direction = direction;
+    public void setPosition(Position position) {
+        this.position = position;
     }
 }

+ 29 - 0
nlp/src/main/java/org/diagbot/nlp/relation/extract/cell/Desc.java

@@ -0,0 +1,29 @@
+package org.diagbot.nlp.relation.extract.cell;
+
+/**
+ * @ClassName org.diagbot.nlp.relation.extract.cell.Desc
+ * @Description TODO
+ * @Author fyeman
+ * @Date 2019/1/23/023 13:40
+ * @Version 1.0
+ **/
+public class Desc {
+    private String name;
+    private String value;
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getValue() {
+        return value;
+    }
+
+    public void setValue(String value) {
+        this.value = value;
+    }
+}

+ 20 - 0
nlp/src/main/java/org/diagbot/nlp/relation/extract/cell/Item.java

@@ -0,0 +1,20 @@
+package org.diagbot.nlp.relation.extract.cell;
+
+/**
+ * @ClassName org.diagbot.nlp.relation.extract.cell.Item
+ * @Description TODO
+ * @Author fyeman
+ * @Date 2019/1/23/023 13:44
+ * @Version 1.0
+ **/
+public class Item {
+    private String itemName;
+
+    public String getItemName() {
+        return itemName;
+    }
+
+    public void setItemName(String itemName) {
+        this.itemName = itemName;
+    }
+}

+ 20 - 0
nlp/src/main/java/org/diagbot/nlp/relation/extract/cell/Position.java

@@ -0,0 +1,20 @@
+package org.diagbot.nlp.relation.extract.cell;
+
+/**
+ * @ClassName org.diagbot.nlp.relation.extract.cell.Position
+ * @Description TODO
+ * @Author fyeman
+ * @Date 2019/1/23/023 16:52
+ * @Version 1.0
+ **/
+public class Position {
+    private String positionName;
+
+    public String getPositionName() {
+        return positionName;
+    }
+
+    public void setPositionName(String positionName) {
+        this.positionName = positionName;
+    }
+}

+ 50 - 0
nlp/src/main/java/org/diagbot/nlp/relation/extract/module/Vital.java

@@ -1,5 +1,10 @@
 package org.diagbot.nlp.relation.extract.module;
 
+import org.diagbot.nlp.relation.extract.cell.BodyPart;
+import org.diagbot.nlp.relation.extract.cell.Degree;
+import org.diagbot.nlp.relation.extract.cell.Item;
+import org.diagbot.nlp.relation.extract.cell.Negative;
+
 /**
  * @ClassName org.diagbot.nlp.relation.extract.module.Vital
  * @Description TODO
@@ -8,4 +13,49 @@ package org.diagbot.nlp.relation.extract.module;
  * @Version 1.0
  **/
 public class Vital {
+    private String vitalName;
+    private BodyPart bodyPart;
+    private Degree degree;
+    private Negative negative;
+    private Item item;
+
+    public String getVitalName() {
+        return vitalName;
+    }
+
+    public void setVitalName(String vitalName) {
+        this.vitalName = vitalName;
+    }
+
+    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 Negative getNegative() {
+        return negative;
+    }
+
+    public void setNegative(Negative negative) {
+        this.negative = negative;
+    }
+
+    public Item getItem() {
+        return item;
+    }
+
+    public void setItem(Item item) {
+        this.item = item;
+    }
 }

+ 4 - 3
nlp/src/main/java/org/diagbot/nlp/relation/extract/output/OutputInfo.java

@@ -1,6 +1,7 @@
 package org.diagbot.nlp.relation.extract.output;
 
 import org.diagbot.nlp.relation.extract.module.Symptom;
+import org.diagbot.nlp.relation.extract.module.Vital;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -14,7 +15,7 @@ import java.util.List;
  **/
 public class OutputInfo {
     List<Symptom> symptoms = new ArrayList<>();
-    List<Symptom> vitals = new ArrayList<>();
+    List<Vital> vitals = new ArrayList<>();
 
     public List<Symptom> getSymptoms() {
         return symptoms;
@@ -24,11 +25,11 @@ public class OutputInfo {
         this.symptoms = symptoms;
     }
 
-    public List<Symptom> getVitals() {
+    public List<Vital> getVitals() {
         return vitals;
     }
 
-    public void setVitals(List<Symptom> vitals) {
+    public void setVitals(List<Vital> vitals) {
         this.vitals = vitals;
     }
 }

+ 4 - 1
nlp/src/main/java/org/diagbot/nlp/util/Constants.java

@@ -19,7 +19,10 @@ public class Constants {
 
     public static NegativeEnum[] symptom_type = new NegativeEnum[]{NegativeEnum.SYMPTOM};
     public static NegativeEnum[] unit_time_type = new NegativeEnum[]{NegativeEnum.EVENT_TIME, NegativeEnum.UNIT};
-    public static NegativeEnum[] vital_type = new NegativeEnum[]{NegativeEnum.VITAL_INDEX};
+    public static NegativeEnum[] vital_type = new NegativeEnum[]{NegativeEnum.VITAL_INDEX_VALUE, NegativeEnum.VITAL_RESULT};
+    public static NegativeEnum[] vital_index_type = new NegativeEnum[]{NegativeEnum.VITAL_INDEX};
+    public static NegativeEnum[] vital_result_type = new NegativeEnum[]{NegativeEnum.VITAL_RESULT};
+    public static NegativeEnum[] vital_value_type = new NegativeEnum[]{NegativeEnum.VITAL_INDEX_VALUE};
     public static NegativeEnum[] body_part_type = new NegativeEnum[]{NegativeEnum.BODY_PART};
     public static NegativeEnum[] position_type = new NegativeEnum[]{NegativeEnum.POSITION};
     public static NegativeEnum[] property_type = new NegativeEnum[]{NegativeEnum.PROPERTY};

+ 5 - 5
push-web/src/main/resources/static/pages/algorithm/list.html

@@ -344,11 +344,11 @@
         var diag = $("#diag_id").val();
         if (diag == '') {
             startDiag('/algorithm/page_neural', '#symptom_list', '1', resourceType, '11');
-//            startDiag('/algorithm/page_neural', '#vital_list', '3', resourceType, '31');
-//            startDiag('/algorithmp/age_neural', '#lis_list', '4', resourceType, '41');
-//            startDiag('/algorithmp/page_neural', '#pacs_list', '5', resourceType, '51');
-//
-//            startDiagMapping('/algorithmp/page_neural', '#diag_list', '2', resourceType, '21');
+            startDiag('/algorithm/page_neural', '#vital_list', '3', resourceType, '31');
+            startDiag('/algorithmp/age_neural', '#lis_list', '4', resourceType, '41');
+            startDiag('/algorithmp/page_neural', '#pacs_list', '5', resourceType, '51');
+
+            startDiagMapping('/algorithmp/page_neural', '#diag_list', '2', resourceType, '21');
         } else {
             $('#diag_list').html("");
             startDiag('/algorithmp/page_neural', '#symptom_list', '1', resourceType, '111');

+ 88 - 29
push-web/src/main/resources/static/pages/relation/sample.html

@@ -109,7 +109,7 @@
                             <!-- textarea -->
                             <div class="form-group">
                 <textarea class="form-control" rows="5" placeholder="Enter ..." name="content" id="content">
-患者11天前烧水时出现心悸,胸闷,感全身不适全身血管跳动,头晕,四肢乏力,视物旋转,恶心,耳鸣,持续1小时后好转。10天前再次出现心悸,胸闷,感全身血管跳动,四肢乏力。6天前聊天时再次出现意识丧失,症状同前,建议转上级医院诊治,遂来我院就诊。
+鼻塞流白涕3天,少许咳嗽,少白痰,无咽痛,无发热。既往鼻炎。PE:双肺清。随诊。
 </textarea>
                             </div>
                         </form>
@@ -127,6 +127,16 @@
             <script>
                 function _ajax(url) {
                     $.support.cors = true;
+                    $.ajax({
+                        url: nlp_web_url + '/participle/split_and_highlight',
+                        data: $("#participle_form").serialize(),
+                        dataType: "json",
+                        type: "post",
+                        success: function (data) {
+                            $("#participle_result").html(data.data);
+                        }
+                    });
+
                     $.ajax({
                         url: nlp_web_url + url,
                         data: $("#participle_form").serialize(),
@@ -135,36 +145,81 @@
                         success: function (data) {
                             var outputInfos = data.data;
                             var h = "";
-                            $.each(outputInfos, function (index, symptoms) {
-                                $.each(symptoms, function (symptom_index, symptom) {
-                                    h += "<dt>" + symptom.symptomName + "</dt>";
-                                    if (symptom.bodyPart != null) {
-                                        if (symptom.bodyPart.direction != null) {
-                                            h += "<dd>" + symptom.bodyPart.direction + symptom.bodyPart.partBodyName + "</dd>";
-                                        } else {
-                                            h += "<dd>" + symptom.bodyPart.partBodyName + "</dd>";
+                            $.each(outputInfos, function (index, outputInfo) {
+                                var symptoms = outputInfo.symptoms;
+                                if (symptoms != null) {
+                                    $.each(symptoms, function (symptom_index, symptom) {
+                                        var hasProp = false;
+                                        h += "<dt>" + symptom.symptomName + "</dt>";
+                                        if (symptom.bodyPart != null) {
+                                            if (symptom.bodyPart.position != null) {
+                                                h += "<dd>" + symptom.bodyPart.position.positionName + symptom.bodyPart.partBodyName + "</dd>";
+                                            } else {
+                                                h += "<dd>" + symptom.bodyPart.partBodyName + "</dd>";
+                                            }
+                                            hasProp = true;
+                                        }
+                                        if (symptom.property != null) {
+                                            h += "<dd>" + symptom.property.propertyName + "</dd>";
+                                            hasProp = true;
                                         }
-                                    }
-                                    if (symptom.property != null) {
-                                        h += "<dd>" + symptom.property.propertyName + "</dd>";
-                                    }
-                                    if (symptom.cause != null) {
-                                        h += "<dd>" + symptom.cause.causeName + "</dd>";
-                                    }
-                                    if (symptom.pd != null) {
-                                        h += "<dd>" + symptom.pd.value + "</dd>";
-                                    }
-                                    if (symptom.degree != null) {
-                                        if (symptom.degree.pd != null) {
-                                            h += "<dd>" + symptom.degree.degreeName + "(" + symptom.degree.pd.value + ")</dd>";
-                                        } else {
-                                            h += "<dd>" + symptom.degree.degreeName + "</dd>";
+                                        if (symptom.cause != null) {
+                                            h += "<dd>" + symptom.cause.causeName + "</dd>";
+                                            hasProp = true;
                                         }
-                                    }
-                                    if (symptom.negative != null) {
-                                        h += "<dd>" + symptom.negative.negaName + "</dd>";
-                                    }
-                                });
+                                        if (symptom.pd != null) {
+                                            h += "<dd>" + symptom.pd.value + "</dd>";
+                                            hasProp = true;
+                                        }
+                                        if (symptom.degree != null) {
+                                            if (symptom.degree.pd != null) {
+                                                h += "<dd>" + symptom.degree.degreeName + "(" + symptom.degree.pd.value + ")</dd>";
+                                            } else {
+                                                h += "<dd>" + symptom.degree.degreeName + "</dd>";
+                                            }
+                                            hasProp = true;
+                                        }
+                                        if (symptom.negative != null) {
+                                            h += "<dd>" + symptom.negative.negaName + "</dd>";
+                                            hasProp = true;
+                                        }
+                                        if (hasProp == false) {
+                                            h += "<dd></dd>";
+                                        }
+                                    });
+                                }
+                                var vitals = outputInfo.vitals;
+                                if (vitals != null) {
+                                    $.each(vitals, function (vital_index, vital) {
+                                        var hasProp = false;
+                                        if (vital.bodyPart != null) {
+                                            h += "<dt>" + vital.vitalName + "</dt>";
+                                            if (vital.item != null) {
+                                                h += "<dd>" + vital.item.itemName + "</dd>";
+                                                hasProp = true;
+                                            }
+                                            if (vital.bodyPart != null) {
+                                                if (vital.bodyPart.position != null) {
+                                                    h += "<dd>" + vital.bodyPart.position.positionName + vital.bodyPart.partBodyName + "</dd>";
+                                                } else {
+                                                    h += "<dd>" + vital.bodyPart.partBodyName + "</dd>";
+                                                }
+                                                hasProp = true;
+                                            }
+                                            if (vital.degree != null) {
+                                                h += "<dd>" + vital.degree.degreeName + "</dd>";
+                                                hasProp = true;
+                                            }
+                                            if (vital.negative != null) {
+                                                h += "<dd>" + vital.negative.negaName + "</dd>";
+                                                hasProp = true;
+                                            }
+                                        }
+                                        if (hasProp == false) {
+                                            h += "<dd></dd>";
+                                        }
+                                    });
+                                }
                             });
                             $("#relation_result").html(h);
                         }
@@ -179,6 +234,10 @@
                             <h3 class="box-title">结 构 化</h3>
                         </div>
                         <!-- /.box-header -->
+                        <div class="box-body">
+                            <dl class="dl-horizontal" id="participle_result">
+                            </dl>
+                        </div>
                         <div class="box-body">
                             <dl class="dl-horizontal" id="relation_result">
                             </dl>