|
@@ -10,6 +10,10 @@ import java.util.Map.Entry;
|
|
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
|
|
+import org.json.JSONArray;
|
|
|
+import org.json.JSONObject;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -172,6 +176,16 @@ public class RecommendService {
|
|
|
}
|
|
|
|
|
|
Map<String, String> map = (Map<String, String>)session.getAttribute("path");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
return finalScore(mirrors, map);
|
|
|
}
|
|
|
|
|
@@ -314,7 +328,8 @@ public class RecommendService {
|
|
|
else { results = recommend(case_take_id, type, content, true, session); }
|
|
|
return results;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
@SuppressWarnings("unchecked")
|
|
|
private Map<BugMirror, Float> count(String content, List<BugMirror> lists, boolean type, HttpSession session) {
|
|
|
StringMatch match = new StringMatch();
|
|
@@ -324,17 +339,24 @@ public class RecommendService {
|
|
|
Map<String, String> titleMap = new HashMap<String, String>();
|
|
|
Map<String, String> desMap = new HashMap<String, String>();
|
|
|
Map<String, String> pmap = null;
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
for(BugMirror mirror: lists) {
|
|
|
String id = mirror.getId();
|
|
|
bmap.put(id, mirror);
|
|
|
titleMap.put(id, kwdao.findById(id).getTitle());
|
|
|
desMap.put(id, kwdao.findById(id).getDescription());
|
|
|
}
|
|
|
+
|
|
|
for(BugMirror mirror: lists) {
|
|
|
String id = mirror.getId();
|
|
|
float score = 0;
|
|
|
+
|
|
|
+
|
|
|
if(type) {
|
|
|
+
|
|
|
+
|
|
|
score += match.score(match.Ansj(content), match.Ansj(titleMap.get(id))) * 30;
|
|
|
if(session.getAttribute("des") != null) {
|
|
|
score += match.score(match.Ansj((String)session.getAttribute("des")), match.Ansj(desMap.get(id))) * 40;
|
|
@@ -348,11 +370,13 @@ public class RecommendService {
|
|
|
tmap.put(mirror, score);
|
|
|
}
|
|
|
List<Entry<BugMirror, Float>> tlist = new ArrayList<Entry<BugMirror, Float>>(tmap.entrySet());
|
|
|
+
|
|
|
Collections.sort(tlist, (a, b) -> (Float.compare(b.getValue(), a.getValue())));
|
|
|
if(session.getAttribute("path") != null) {
|
|
|
pmap = (Map<String, String>)session.getAttribute("path");
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
for(int i = 0; i < tlist.size() && i < 6; i ++) {
|
|
|
float score = (float) (tlist.get(i).getValue());
|
|
|
result.put(tlist.get(i).getKey(), score + categoryCount(tlist.get(i).getKey(), pmap));
|
|
@@ -436,5 +460,96 @@ public class RecommendService {
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
+
|
|
|
+ public void createSimilarBugLog(HttpSession session,List<BugMirror> mirrorList,List<Float> scores){
|
|
|
+ Bug userBug=constructUserBug(session);
|
|
|
+ JSONObject similarJson=new JSONObject();
|
|
|
+ similarJson.put("type","similarJson");
|
|
|
+ similarJson.put("userJson",new JSONObject(userBug));
|
|
|
+ JSONArray similarBugJSONArray=new JSONArray();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ for(int i=0;i<mirrorList.size();i++){
|
|
|
+ Bug similarBug=bugdao.findByid(mirrorList.get(i).getId());
|
|
|
+ JSONObject similarBugJSONObject=new JSONObject();
|
|
|
+ similarBugJSONObject.put("bugDetail",new JSONObject(similarBug));
|
|
|
+ similarBugJSONObject.put("score",scores.get(i));
|
|
|
+ similarBugJSONArray.put(similarBugJSONObject);
|
|
|
+ }
|
|
|
+
|
|
|
+ similarJson.put("similarJson",similarBugJSONArray);
|
|
|
+
|
|
|
+ Logger logger= LoggerFactory.getLogger(RecommendService.class);
|
|
|
+ logger.info(String.valueOf(similarJson));
|
|
|
+ }
|
|
|
+
|
|
|
+ private Bug constructUserBug( HttpSession session){
|
|
|
+ String case_take_id="";
|
|
|
+ String create_time_millis=Long.toString(System.currentTimeMillis());
|
|
|
+ String bug_category="";
|
|
|
+ String description="";
|
|
|
+ String img_url="";
|
|
|
+ int severity=0;
|
|
|
+ int recurrent=0;
|
|
|
+ String title="";
|
|
|
+ String report_id="";
|
|
|
+ String bug_page="";
|
|
|
+ String case_id="";
|
|
|
+ if(session.getAttribute("case")!=null){
|
|
|
+ case_take_id=(String)session.getAttribute("case");
|
|
|
+ case_id=case_take_id.split("-")[0];
|
|
|
+ }
|
|
|
+ if(session.getAttribute("path")!=null){
|
|
|
+ LinkedHashMap<String,String> path=(LinkedHashMap<String,String>)session.getAttribute("path");
|
|
|
+ if(path.containsKey("page1")){
|
|
|
+ bug_page+=path.get("page1");
|
|
|
+ if(path.containsKey("page2")){
|
|
|
+ bug_page+=("-"+path.get("page2"));
|
|
|
+ if(path.containsKey("page3")){
|
|
|
+ bug_page+=("-"+path.get("page3"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(path.containsKey("bug_category")){
|
|
|
+ bug_category=path.get("bug_category");
|
|
|
+ }
|
|
|
+ if(path.containsKey("severity")){
|
|
|
+ severity=severityTranse(path.get("severity"));
|
|
|
+ }
|
|
|
+ if(path.containsKey("recurrent")){
|
|
|
+ recurrent=recurrentTranse(path.get("recurrent"));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if(session.getAttribute("title")!=null){
|
|
|
+ title=(String)session.getAttribute("title");
|
|
|
+ }
|
|
|
+ if(session.getAttribute("des")!=null){
|
|
|
+ description=(String)session.getAttribute("des");
|
|
|
+ }
|
|
|
+ Bug userBug=new Bug(case_take_id,create_time_millis,bug_category,description,img_url,severity,recurrent,title,report_id,bug_page,case_id);
|
|
|
+
|
|
|
+
|
|
|
+ return userBug;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|