|
@@ -0,0 +1,74 @@
|
|
|
+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;
|
|
|
+import org.diagbot.nlp.participle.word.Lexeme;
|
|
|
+import org.diagbot.nlp.participle.word.LexemePath;
|
|
|
+import org.diagbot.nlp.util.Constants;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description:
|
|
|
+ * @Author: HUJING
|
|
|
+ * @Date: 2019/9/9 17:30
|
|
|
+ */
|
|
|
+public class RelationExtractionCreateSearchData {
|
|
|
+ public List<Triad> createSearchData(SearchData searchData) throws IOException {
|
|
|
+ List<Triad> triads = new ArrayList<>();
|
|
|
+ String[] pacsSplits = searchData.getPacs().trim().split("。|\n");
|
|
|
+ List<Lemma> lemmaList = new ArrayList<>();
|
|
|
+ Lemma lemma = null;
|
|
|
+ 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())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ lemma = new Lemma();
|
|
|
+ lemma.setText(pacsLexemes.get(i).getText());
|
|
|
+ lemma.setPosition(String.valueOf(pacsLexemes.get(i).getOffset()) + "," + (Integer.valueOf(pacsLexemes.get(i).getOffset() + pacsLexemes.get(i).getLength()) - 1));
|
|
|
+ lemma.setProperty(PushConstants.featureTypeMap.get(pacsLexemes.get(i).getProperty()));
|
|
|
+ lemmaList.add(lemma);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (int i = 0; i < lemmaList.size() - 1; i++) {
|
|
|
+ for (int j = i + 1; j < lemmaList.size(); j++) {
|
|
|
+ Triad triad = new Triad();
|
|
|
+ triad.setL_1(lemmaList.get(i));
|
|
|
+ triad.setL_2(lemmaList.get(j));
|
|
|
+ triads.add(triad);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return triads;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void start(List<List<String>> relationExtractionContents, SearchData searchData) throws Exception {
|
|
|
+ StringBuffer sb = null;
|
|
|
+ for (List<String> contents : relationExtractionContents) {
|
|
|
+ sb = new StringBuffer();
|
|
|
+ for (String content : contents) {
|
|
|
+ sb.append(content);
|
|
|
+ }
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ map.put("featureType", "4");
|
|
|
+ map.put("featureName", sb.toString());
|
|
|
+ map.put("property", "17");
|
|
|
+ map.put("concept", sb.toString());
|
|
|
+ //全是有
|
|
|
+ map.put("negative", Constants.default_negative);
|
|
|
+ if (searchData.getInputs().get(map.get("featureName")) == null) {
|
|
|
+ searchData.getInputs().put(map.get("featureName"), map);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|