|
@@ -1,10 +1,11 @@
|
|
-package org.algorithm.core.remoteModel;
|
|
|
|
|
|
+package org.algorithm.core.cnn.model.impl;
|
|
|
|
|
|
import org.algorithm.core.cnn.AlgorithmCNNExecutor;
|
|
import org.algorithm.core.cnn.AlgorithmCNNExecutor;
|
|
import org.algorithm.core.cnn.entity.Lemma;
|
|
import org.algorithm.core.cnn.entity.Lemma;
|
|
import org.algorithm.core.cnn.entity.Triad;
|
|
import org.algorithm.core.cnn.entity.Triad;
|
|
import org.algorithm.util.HttpGetAndPost;
|
|
import org.algorithm.util.HttpGetAndPost;
|
|
import org.diagbot.pub.utils.PropertiesUtil;
|
|
import org.diagbot.pub.utils.PropertiesUtil;
|
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -19,6 +20,9 @@ public class RelationExtractionModelFromHttp extends AlgorithmCNNExecutor {
|
|
public List<Triad> execute(String content, List<Lemma> lemmas) {
|
|
public List<Triad> execute(String content, List<Lemma> lemmas) {
|
|
String url = getUrl();
|
|
String url = getUrl();
|
|
String positions = makePositionsParam(lemmas);
|
|
String positions = makePositionsParam(lemmas);
|
|
|
|
+ if (StringUtils.isEmpty(positions)) {
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
+ }
|
|
String sentence = content;
|
|
String sentence = content;
|
|
String indexPairAndRelations = HttpGetAndPost.sendPost(url,
|
|
String indexPairAndRelations = HttpGetAndPost.sendPost(url,
|
|
"sentence="+sentence+"&positions="+positions);
|
|
"sentence="+sentence+"&positions="+positions);
|
|
@@ -34,7 +38,9 @@ public class RelationExtractionModelFromHttp extends AlgorithmCNNExecutor {
|
|
String results = "";
|
|
String results = "";
|
|
for(Lemma lm: lemmas)
|
|
for(Lemma lm: lemmas)
|
|
results += lm.getPosition() + "|"; // 形式:1,2|33,45|
|
|
results += lm.getPosition() + "|"; // 形式:1,2|33,45|
|
|
- results = results.substring(0, results.length() - 1); // 形式:1,2|33,45
|
|
|
|
|
|
+ if (!StringUtils.isEmpty(results)) {
|
|
|
|
+ results = results.substring(0, results.length() - 1); // 形式:1,2|33,45
|
|
|
|
+ }
|
|
return results;
|
|
return results;
|
|
}
|
|
}
|
|
|
|
|