|
@@ -6,11 +6,13 @@ import com.alibaba.fastjson.JSONObject;
|
|
|
import com.alibaba.fastjson.TypeReference;
|
|
|
import org.algorithm.core.cnn.AlgorithmCNNExecutor;
|
|
|
import org.algorithm.core.cnn.dataset.RelationExtractionDataSet;
|
|
|
+import org.algorithm.core.cnn.entity.Lemma;
|
|
|
+import org.algorithm.core.cnn.entity.LemmaInfo;
|
|
|
+import org.algorithm.core.cnn.entity.Triad;
|
|
|
import org.tensorflow.SavedModelBundle;
|
|
|
import org.tensorflow.Session;
|
|
|
import org.tensorflow.Tensor;
|
|
|
|
|
|
-import java.nio.FloatBuffer;
|
|
|
import java.nio.IntBuffer;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
@@ -53,15 +55,14 @@ public class RelationExtractionModel extends AlgorithmCNNExecutor {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<Triad> execute(String content, String json_content) {
|
|
|
- List<LemmaInfo[]> combinations = new ArrayList<>();
|
|
|
- List<LemmaInfo> lemmaInfos = this.stringToObjects(json_content); // json数组字符串装对象list
|
|
|
+ public List<Triad> execute(String content, List<Lemma> lemmas) {
|
|
|
+ List<Lemma[]> combinations = new ArrayList<>();
|
|
|
// 组合
|
|
|
- for(int i=0; i < lemmaInfos.size() - 1; i++){ // 两两组合成实体对
|
|
|
- for (int j = i + 1; j< lemmaInfos.size(); j++){
|
|
|
- LemmaInfo[] pair = new LemmaInfo[2];
|
|
|
- pair[0] = lemmaInfos.get(i);
|
|
|
- pair[1] = lemmaInfos.get(j);
|
|
|
+ for(int i=0; i < lemmas.size() - 1; i++){ // 两两组合成实体对
|
|
|
+ for (int j = i + 1; j< lemmas.size(); j++){
|
|
|
+ Lemma[] pair = new Lemma[2];
|
|
|
+ pair[0] = lemmas.get(i);
|
|
|
+ pair[1] = lemmas.get(j);
|
|
|
combinations.add(pair);
|
|
|
}
|
|
|
}
|
|
@@ -69,16 +70,16 @@ public class RelationExtractionModel extends AlgorithmCNNExecutor {
|
|
|
List<Triad> triads = new ArrayList<>();
|
|
|
|
|
|
// 遍历组合
|
|
|
- for (LemmaInfo[] lemmaInfoPair: combinations) {
|
|
|
- int[][] example = dataSet.getExample(content, lemmaInfoPair[0], lemmaInfoPair[1]);
|
|
|
+ for (Lemma[] LemmaPair: combinations) {
|
|
|
+ int[][] example = dataSet.getExample(content, LemmaPair[0], LemmaPair[1]);
|
|
|
// 调用模型
|
|
|
float[][] relation = this.run(example, 1);
|
|
|
Triad triad = new Triad();
|
|
|
|
|
|
// TODO:修改triad
|
|
|
// 生成Triad(三元组)
|
|
|
- triad.setL_1(lemmaInfoPair[0].toLemma());
|
|
|
- triad.setL_2(lemmaInfoPair[1].toLemma());
|
|
|
+ triad.setL_1(LemmaPair[0]);
|
|
|
+ triad.setL_2(LemmaPair[1]);
|
|
|
triad.setRelation(relation[0][0] > relation[0][1] ? "无":"有");
|
|
|
triads.add(triad);
|
|
|
}
|