|
@@ -12,6 +12,7 @@ import org.apache.http.entity.StringEntity;
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.util.*;
|
|
@@ -26,11 +27,13 @@ public class NLPRemoteService {
|
|
|
|
|
|
private final CloseableHttpClient client = HttpPoolFactory.nlpPool();
|
|
|
private static final String scoreListUrl = "http://61.48.133.26:6060/score_list";
|
|
|
+ private static final String backUrl = "http://61.48.133.26:6060/score_list";
|
|
|
|
|
|
public Map<String, Double> score(String accountName, List<Content> contentList) {
|
|
|
long start = System.currentTimeMillis();
|
|
|
Map<String, Double> result = new HashMap<>();
|
|
|
List<String> titleList = contentList.stream().map(Content::getTitle).collect(Collectors.toList());
|
|
|
+ String url = scoreListUrl;
|
|
|
JSONObject bodyParam = new JSONObject();
|
|
|
bodyParam.put("account_nickname_list", Collections.singletonList(accountName));
|
|
|
bodyParam.put("text_list", titleList);
|
|
@@ -41,7 +44,7 @@ public class NLPRemoteService {
|
|
|
while (retry < 3) {
|
|
|
retry++;
|
|
|
try {
|
|
|
- HttpPost httpPost = new HttpPost(scoreListUrl);
|
|
|
+ HttpPost httpPost = new HttpPost(url);
|
|
|
StringEntity stringEntity = new StringEntity(bodyParam.toJSONString(), StandardCharsets.UTF_8);
|
|
|
httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
|
|
|
httpPost.setEntity(stringEntity);
|
|
@@ -66,6 +69,9 @@ public class NLPRemoteService {
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
+ if (StringUtils.hasText(e.getMessage()) && e.getMessage().contains("Connection")) {
|
|
|
+ url = backUrl;
|
|
|
+ }
|
|
|
log.error("score error", e);
|
|
|
}
|
|
|
}
|