|
@@ -1,12 +1,10 @@
|
|
package org.diagbot.nlp.relation.extract;
|
|
package org.diagbot.nlp.relation.extract;
|
|
|
|
|
|
import org.algorithm.core.cnn.entity.Lemma;
|
|
import org.algorithm.core.cnn.entity.Lemma;
|
|
-import org.algorithm.core.cnn.entity.Triad;
|
|
|
|
-import org.diagbot.nlp.participle.word.Lexeme;
|
|
|
|
-import org.diagbot.nlp.participle.word.LexemePath;
|
|
|
|
import org.diagbot.nlp.relation.extract.cell.*;
|
|
import org.diagbot.nlp.relation.extract.cell.*;
|
|
import org.diagbot.nlp.relation.extract.module.Symptom;
|
|
import org.diagbot.nlp.relation.extract.module.Symptom;
|
|
-import org.diagbot.nlp.util.NegativeEnum;
|
|
|
|
|
|
+import org.diagbot.nlp.relation.extract.output.OutputInfo;
|
|
|
|
+import org.diagbot.nlp.util.Constants;
|
|
import org.diagbot.nlp.util.NlpUtil;
|
|
import org.diagbot.nlp.util.NlpUtil;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -20,67 +18,63 @@ import java.util.List;
|
|
* @Version 1.0
|
|
* @Version 1.0
|
|
**/
|
|
**/
|
|
public class PresentExtract extends BaseExtract {
|
|
public class PresentExtract extends BaseExtract {
|
|
|
|
+ private List<Lemma> containsLemmaTree = new ArrayList<>();
|
|
|
|
|
|
- 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};
|
|
|
|
-
|
|
|
|
- public void extract(List<Triad> triads, LexemePath<Lexeme> lexemes) {
|
|
|
|
- List<Lemma> param_lemmas = this.lexemeToTriadLemma(lexemes);
|
|
|
|
- //三元组关系对转树形结构
|
|
|
|
- List<Lemma> cnn_lemmas = this.traidToTree(triads);
|
|
|
|
|
|
+ public OutputInfo extract(List<Lemma> lemmaTree, List<Lemma> lemmaParticiple) {
|
|
|
|
+ OutputInfo outputInfo = new OutputInfo();
|
|
String property = "";
|
|
String property = "";
|
|
- for (int index = 0; index < param_lemmas.size(); index++) {
|
|
|
|
- Lemma param_lemma = param_lemmas.get(index);
|
|
|
|
- property = param_lemma.getProperty();
|
|
|
|
- if (NlpUtil.isFeature(property, symptom_type)) { //特征词 症状
|
|
|
|
|
|
+ for (int index = 0; index < lemmaParticiple.size(); index++) {
|
|
|
|
+ Lemma participle_lemma = lemmaParticiple.get(index);
|
|
|
|
+ property = participle_lemma.getProperty();
|
|
|
|
+ if (NlpUtil.isFeature(property, Constants.symptom_type)) { //特征词 症状
|
|
Symptom symptom = new Symptom();
|
|
Symptom symptom = new Symptom();
|
|
- lookSymptomRelations(param_lemma, cnn_lemmas, symptom);
|
|
|
|
|
|
+ symptom.setSymptomName(participle_lemma.getText());
|
|
|
|
+
|
|
|
|
+ lookSymptomRelations(participle_lemma, lemmaTree, symptom);
|
|
|
|
+ outputInfo.getSymptoms().add(symptom);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ lemmaTree.removeAll(containsLemmaTree);
|
|
|
|
+ return outputInfo;
|
|
}
|
|
}
|
|
|
|
|
|
- private void lookSymptomRelations(Lemma param_lemma, List<Lemma> cnn_lemmas, Symptom symptom) {
|
|
|
|
- for (Lemma cnn_l : cnn_lemmas) {
|
|
|
|
|
|
+ private void lookSymptomRelations(Lemma param_lemma, List<Lemma> lemmaTree, Symptom symptom) {
|
|
|
|
+ for (Lemma cnn_l : lemmaTree) {
|
|
if (cnn_l.getText().equals(param_lemma.getText())
|
|
if (cnn_l.getText().equals(param_lemma.getText())
|
|
&& cnn_l.getPosition().equals(param_lemma.getPosition())) {
|
|
&& cnn_l.getPosition().equals(param_lemma.getPosition())) {
|
|
for (Lemma relation_l : cnn_l.getRelationLemmas()) {
|
|
for (Lemma relation_l : cnn_l.getRelationLemmas()) {
|
|
addFeatureToSymptom(relation_l, symptom);
|
|
addFeatureToSymptom(relation_l, symptom);
|
|
}
|
|
}
|
|
|
|
+ containsLemmaTree.add(cnn_l);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void addFeatureToSymptom(Lemma lemma, Symptom symptom) {
|
|
private void addFeatureToSymptom(Lemma lemma, Symptom symptom) {
|
|
//时间信息
|
|
//时间信息
|
|
- if (NlpUtil.isFeature(lemma.getProperty(), unit_time_type)) {
|
|
|
|
|
|
+ if (NlpUtil.isFeature(lemma.getProperty(), Constants.unit_time_type)) {
|
|
PD pd = new PD();
|
|
PD pd = new PD();
|
|
pd.setValue(lemma.getText());
|
|
pd.setValue(lemma.getText());
|
|
symptom.setPd(pd);
|
|
symptom.setPd(pd);
|
|
}
|
|
}
|
|
//部位信息
|
|
//部位信息
|
|
- if (NlpUtil.isFeature(lemma.getProperty(), body_part_type)) {
|
|
|
|
|
|
+ if (NlpUtil.isFeature(lemma.getProperty(), Constants.body_part_type)) {
|
|
BodyPart bodyPart = new BodyPart();
|
|
BodyPart bodyPart = new BodyPart();
|
|
bodyPart.setPartBodyName(lemma.getText());
|
|
bodyPart.setPartBodyName(lemma.getText());
|
|
if (lemma.getRelationLemmas().size() > 0) {
|
|
if (lemma.getRelationLemmas().size() > 0) {
|
|
Lemma l = lemma.getRelationLemmas().get(0);
|
|
Lemma l = lemma.getRelationLemmas().get(0);
|
|
- if (NlpUtil.isFeature(l.getProperty(), position_type)) {
|
|
|
|
|
|
+ if (NlpUtil.isFeature(l.getProperty(), Constants.position_type)) {
|
|
bodyPart.setDirection(l.getText());
|
|
bodyPart.setDirection(l.getText());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
symptom.setBodyPart(bodyPart);
|
|
symptom.setBodyPart(bodyPart);
|
|
}
|
|
}
|
|
//程度
|
|
//程度
|
|
- if (NlpUtil.isFeature(lemma.getProperty(), degree_type)) {
|
|
|
|
|
|
+ if (NlpUtil.isFeature(lemma.getProperty(), Constants.degree_type)) {
|
|
Degree degree = new Degree();
|
|
Degree degree = new Degree();
|
|
degree.setDegreeName(lemma.getText());
|
|
degree.setDegreeName(lemma.getText());
|
|
for (Lemma l : lemma.getRelationLemmas()) {
|
|
for (Lemma l : lemma.getRelationLemmas()) {
|
|
- if (NlpUtil.isFeature(l.getProperty(), unit_time_type)) {
|
|
|
|
|
|
+ if (NlpUtil.isFeature(l.getProperty(), Constants.unit_time_type)) {
|
|
PD pd = new PD();
|
|
PD pd = new PD();
|
|
pd.setValue(l.getText());
|
|
pd.setValue(l.getText());
|
|
degree.setPd(pd);
|
|
degree.setPd(pd);
|
|
@@ -89,68 +83,23 @@ public class PresentExtract extends BaseExtract {
|
|
symptom.setDegree(degree);
|
|
symptom.setDegree(degree);
|
|
}
|
|
}
|
|
//性质
|
|
//性质
|
|
- if (NlpUtil.isFeature(lemma.getProperty(), property_type)) {
|
|
|
|
|
|
+ if (NlpUtil.isFeature(lemma.getProperty(), Constants.property_type)) {
|
|
Property property = new Property();
|
|
Property property = new Property();
|
|
property.setPropertyName(lemma.getText());
|
|
property.setPropertyName(lemma.getText());
|
|
symptom.setProperty(property);
|
|
symptom.setProperty(property);
|
|
}
|
|
}
|
|
//诱因
|
|
//诱因
|
|
- if (NlpUtil.isFeature(lemma.getProperty(), cause_type)) {
|
|
|
|
|
|
+ if (NlpUtil.isFeature(lemma.getProperty(), Constants.cause_type)) {
|
|
Cause cause = new Cause();
|
|
Cause cause = new Cause();
|
|
cause.setCauseName(lemma.getText());
|
|
cause.setCauseName(lemma.getText());
|
|
symptom.setCause(cause);
|
|
symptom.setCause(cause);
|
|
}
|
|
}
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 分词结果转词元结构
|
|
|
|
- * @param lexemes
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- private List<Lemma> lexemeToTriadLemma(LexemePath<Lexeme> lexemes) {
|
|
|
|
- List<Lemma> lemmas = new ArrayList<>();
|
|
|
|
- for (Lexeme lexeme : lexemes) {
|
|
|
|
- Lemma lemma = new Lemma();
|
|
|
|
- lemma.setLen(lexeme.getLength());
|
|
|
|
- lemma.setPosition(lexeme.getOffset() + "," + (lexeme.getOffset() + lexeme.getLength()));
|
|
|
|
- lemma.setText(lexeme.getText());
|
|
|
|
- lemma.setProperty(lexeme.getProperty());
|
|
|
|
-
|
|
|
|
- lemmas.add(lemma);
|
|
|
|
- }
|
|
|
|
- return lemmas;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private List<Lemma> traidToTree(List<Triad> triads) {
|
|
|
|
- List<Lemma> lemmas = new ArrayList<>();
|
|
|
|
- for (Triad triad : triads) {
|
|
|
|
- if (NlpUtil.isFeature(triad.getL_1().getProperty(), symptom_type)
|
|
|
|
- || NlpUtil.isFeature(triad.getL_1().getProperty(), vital_type)) {
|
|
|
|
- Lemma lemma = triad.getL_1();
|
|
|
|
- lemma.add(this.findRelationTriad(triads, triad.getL_2()));
|
|
|
|
- lemmas.add(lemma);
|
|
|
|
- }
|
|
|
|
- if (NlpUtil.isFeature(triad.getL_2().getProperty(), symptom_type)
|
|
|
|
- || NlpUtil.isFeature(triad.getL_1().getProperty(), vital_type)) {
|
|
|
|
- Lemma lemma = triad.getL_2();
|
|
|
|
- lemma.add(this.findRelationTriad(triads, triad.getL_1()));
|
|
|
|
- lemmas.add(lemma);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return lemmas;
|
|
|
|
- }
|
|
|
|
|
|
|
|
- private Lemma findRelationTriad(List<Triad> triads, Lemma lemma) {
|
|
|
|
- for (Triad triad : triads) {
|
|
|
|
- if (triad.getL_1().getText().equals(lemma.getText())
|
|
|
|
- && triad.getL_1().getPosition().equals(lemma.getPosition())) {
|
|
|
|
- lemma.add(triad.getL_2());
|
|
|
|
- }
|
|
|
|
- if (triad.getL_2().getText().equals(lemma.getText())
|
|
|
|
- && triad.getL_2().getPosition().equals(lemma.getPosition())) {
|
|
|
|
- lemma.add(triad.getL_1());
|
|
|
|
- }
|
|
|
|
|
|
+ //阴性
|
|
|
|
+ if (NlpUtil.isFeature(lemma.getProperty(), Constants.negative_type)) {
|
|
|
|
+ Negative negative = new Negative();
|
|
|
|
+ negative.setNegaName(lemma.getProperty());
|
|
|
|
+ symptom.setNegative(negative);
|
|
}
|
|
}
|
|
- return lemma;
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|