Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.nju.svcdisambiguation.serviceImp;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import com.nju.svcdisambiguation.dataMapper.acm.ACMPaperInfoMapper;
import com.nju.svcdisambiguation.dataMapper.ieee.IEEEPaperInfoMapper;
import com.nju.svcdisambiguation.service.PaperDetailService;
import com.nju.svcdisambiguation.vo.ResponseVO;
import com.nju.svcdisambiguation.vo.detail.paper.PaperInfoVO;
import com.nju.svcdisambiguation.vo.detail.paper.PaperThemeVO;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.stereotype.Service;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
@Service
public class PaperDetailServiceImp implements PaperDetailService {
private final ACMPaperInfoMapper acmPaperInfoMapper;
private final IEEEPaperInfoMapper ieeePaperInfoMapper;
public PaperDetailServiceImp(ACMPaperInfoMapper acmPaperInfoMapper, IEEEPaperInfoMapper ieeePaperInfoMapper) {
this.acmPaperInfoMapper = acmPaperInfoMapper;
this.ieeePaperInfoMapper = ieeePaperInfoMapper;
}
@Override
public ResponseVO getPaperInfoByPaperId(int paperId, String db) {
PaperInfoVO paperInfoVO = new PaperInfoVO();
String abs = "";
if(db.equals("ACM")){
paperInfoVO.setInstitutions(acmPaperInfoMapper.searchInstitutionsByPaperId(paperId));
paperInfoVO.setPdfLink(acmPaperInfoMapper.searchPdfLinkByPaperId(paperId));
abs = acmPaperInfoMapper.searchAbsByPaperId(paperId);
}
else{
paperInfoVO.setInstitutions(ieeePaperInfoMapper.searchInstitutionsByPaperId(paperId));
paperInfoVO.setPdfLink(ieeePaperInfoMapper.searchPdfLinkByPaperId(paperId));
abs = ieeePaperInfoMapper.searchAbsByPaperId(paperId);
}
paperInfoVO.setTheme(getThemes(abs));
return ResponseVO.buildSuccess(paperInfoVO);
}
private ArrayList<PaperThemeVO> getThemes(String abs){
ArrayList<PaperThemeVO> paperThemeVOS = new ArrayList<>();
String url = "http://47.106.211.96:5000/yake/";
Map<String,String> headers = new HashMap<>();
headers.put("accept","application/json");
headers.put("Content-Type","application/json");
//post 请求
HttpResponse<JsonNode> httpResponse = null;
try {
httpResponse = Unirest.post(url)
.headers(headers)
.body("{\"language\":\"en\", \"max_ngram_size\":3, \"number_of_keywords\": 15, \"text\": \"" + abs + "\"}")
.asJson();
} catch (UnirestException e) {
e.printStackTrace();
}
JSONArray jsonArray = httpResponse.getBody().getArray();
for(int i=0;i<jsonArray.length();++i){
JSONObject jsonObject = (JSONObject) jsonArray.get(i);
double score = (Double)jsonObject.get("score");
String ngram = (String)jsonObject.get("ngram");
paperThemeVOS.add(new PaperThemeVO(ngram, score));
}
return paperThemeVOS;
}
}