|
@@ -0,0 +1,88 @@
|
|
|
+package org.diagbot.common.push.filter.pretreat;
|
|
|
+
|
|
|
+import org.diagbot.common.push.filter.PreResult;
|
|
|
+import org.diagbot.nlp.participle.ParticipleUtil;
|
|
|
+import org.diagbot.nlp.participle.word.Lexeme;
|
|
|
+import org.diagbot.nlp.participle.word.LexemePath;
|
|
|
+import org.diagbot.nlp.util.NegativeEnum;
|
|
|
+import org.diagbot.nlp.util.NlpUtil;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by louhr on 2019/8/31.
|
|
|
+ */
|
|
|
+public abstract class Pretreatment {
|
|
|
+ protected NegativeEnum[] nees_time_and_unit = new NegativeEnum[]{NegativeEnum.EVENT_TIME, NegativeEnum.UNIT};
|
|
|
+
|
|
|
+ protected int cursor = 0;
|
|
|
+
|
|
|
+ public abstract List<PreResult> analyze(String content) throws java.io.IOException;
|
|
|
+
|
|
|
+ abstract PreResult createPreResult(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index);
|
|
|
+
|
|
|
+ protected List<PreResult> analyzeDefault(String content) throws java.io.IOException{
|
|
|
+ LexemePath<Lexeme> lexemes = ParticipleUtil.participle(content);
|
|
|
+
|
|
|
+ List<PreResult> preResultList = new ArrayList<>();
|
|
|
+ for (int i = 0; i < lexemes.size(); i++) {
|
|
|
+ Lexeme l = lexemes.get(i);
|
|
|
+ if (NlpUtil.isFeature(l.getProperty(), nees_time_and_unit)) {
|
|
|
+ PreResult result = data2Object(lexemes, l, i, l.getProperty());
|
|
|
+ if (result != null) {
|
|
|
+ preResultList.add(result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return preResultList;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected PreResult data2Object(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index, String property) {
|
|
|
+ if (index < 2) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return createPreResult(lexemes, lexeme, index);
|
|
|
+ }
|
|
|
+
|
|
|
+ public PreResult createDefaultPreResult(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
|
|
|
+ double value = findNumberValue(lexemes, lexeme, index);
|
|
|
+ if (value == -1) return null;
|
|
|
+ //继续往前找本体
|
|
|
+ String text = findBodyValue(lexemes, lexeme, index);
|
|
|
+ if (StringUtils.isEmpty(text)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ PreResult result = new PreResult();
|
|
|
+ result.setValue(value);
|
|
|
+ result.setUnits(lexeme.getText());
|
|
|
+ result.setDetailName(text);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected double findNumberValue(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
|
|
|
+ if (index < 1) return -1;
|
|
|
+ cursor = index - 1;
|
|
|
+ Lexeme leftLexeme = lexemes.get(cursor);
|
|
|
+ if ("×".equals(leftLexeme.getText())) {
|
|
|
+ if (cursor <= 0) return -1;
|
|
|
+ cursor--;
|
|
|
+ leftLexeme = lexemes.get(cursor);
|
|
|
+ }
|
|
|
+ if (NlpUtil.isNumberString(leftLexeme)) {
|
|
|
+ return NlpUtil.numberText2value(leftLexeme);
|
|
|
+ }
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ protected String findBodyValue(LexemePath<Lexeme> lexemes, Lexeme lexeme, int index) {
|
|
|
+ if (cursor > 0) cursor--;
|
|
|
+ Lexeme leftLexeme = lexemes.get(cursor);
|
|
|
+ if (NlpUtil.isFeature(leftLexeme.getProperty(), new NegativeEnum[]{NegativeEnum.VITAL_INDEX,
|
|
|
+ NegativeEnum.VITAL_INDEX_VALUE, NegativeEnum.VITAL_RESULT, NegativeEnum.SYMPTOM})) {
|
|
|
+ return leftLexeme.getText();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|