|
@@ -1,5 +1,7 @@
|
|
package edu.nju.service;
|
|
package edu.nju.service;
|
|
|
|
|
|
|
|
+import java.lang.reflect.Field;
|
|
|
|
+import java.lang.reflect.Method;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
@@ -10,6 +12,10 @@ import java.util.Map.Entry;
|
|
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
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.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -172,6 +178,16 @@ public class RecommendService {
|
|
}
|
|
}
|
|
|
|
|
|
Map<String, String> map = (Map<String, String>)session.getAttribute("path");
|
|
Map<String, String> map = (Map<String, String>)session.getAttribute("path");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
return finalScore(mirrors, map);
|
|
return finalScore(mirrors, map);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -314,7 +330,8 @@ public class RecommendService {
|
|
else { results = recommend(case_take_id, type, content, true, session); }
|
|
else { results = recommend(case_take_id, type, content, true, session); }
|
|
return results;
|
|
return results;
|
|
}
|
|
}
|
|
-
|
|
+
|
|
|
|
+
|
|
@SuppressWarnings("unchecked")
|
|
@SuppressWarnings("unchecked")
|
|
private Map<BugMirror, Float> count(String content, List<BugMirror> lists, boolean type, HttpSession session) {
|
|
private Map<BugMirror, Float> count(String content, List<BugMirror> lists, boolean type, HttpSession session) {
|
|
StringMatch match = new StringMatch();
|
|
StringMatch match = new StringMatch();
|
|
@@ -324,17 +341,24 @@ public class RecommendService {
|
|
Map<String, String> titleMap = new HashMap<String, String>();
|
|
Map<String, String> titleMap = new HashMap<String, String>();
|
|
Map<String, String> desMap = new HashMap<String, String>();
|
|
Map<String, String> desMap = new HashMap<String, String>();
|
|
Map<String, String> pmap = null;
|
|
Map<String, String> pmap = null;
|
|
-
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
for(BugMirror mirror: lists) {
|
|
for(BugMirror mirror: lists) {
|
|
String id = mirror.getId();
|
|
String id = mirror.getId();
|
|
bmap.put(id, mirror);
|
|
bmap.put(id, mirror);
|
|
titleMap.put(id, kwdao.findById(id).getTitle());
|
|
titleMap.put(id, kwdao.findById(id).getTitle());
|
|
desMap.put(id, kwdao.findById(id).getDescription());
|
|
desMap.put(id, kwdao.findById(id).getDescription());
|
|
}
|
|
}
|
|
|
|
+
|
|
for(BugMirror mirror: lists) {
|
|
for(BugMirror mirror: lists) {
|
|
String id = mirror.getId();
|
|
String id = mirror.getId();
|
|
float score = 0;
|
|
float score = 0;
|
|
|
|
+
|
|
|
|
+
|
|
if(type) {
|
|
if(type) {
|
|
|
|
+
|
|
|
|
+
|
|
score += match.score(match.Ansj(content), match.Ansj(titleMap.get(id))) * 30;
|
|
score += match.score(match.Ansj(content), match.Ansj(titleMap.get(id))) * 30;
|
|
if(session.getAttribute("des") != null) {
|
|
if(session.getAttribute("des") != null) {
|
|
score += match.score(match.Ansj((String)session.getAttribute("des")), match.Ansj(desMap.get(id))) * 40;
|
|
score += match.score(match.Ansj((String)session.getAttribute("des")), match.Ansj(desMap.get(id))) * 40;
|
|
@@ -348,11 +372,13 @@ public class RecommendService {
|
|
tmap.put(mirror, score);
|
|
tmap.put(mirror, score);
|
|
}
|
|
}
|
|
List<Entry<BugMirror, Float>> tlist = new ArrayList<Entry<BugMirror, Float>>(tmap.entrySet());
|
|
List<Entry<BugMirror, Float>> tlist = new ArrayList<Entry<BugMirror, Float>>(tmap.entrySet());
|
|
|
|
+
|
|
Collections.sort(tlist, (a, b) -> (Float.compare(b.getValue(), a.getValue())));
|
|
Collections.sort(tlist, (a, b) -> (Float.compare(b.getValue(), a.getValue())));
|
|
if(session.getAttribute("path") != null) {
|
|
if(session.getAttribute("path") != null) {
|
|
pmap = (Map<String, String>)session.getAttribute("path");
|
|
pmap = (Map<String, String>)session.getAttribute("path");
|
|
}
|
|
}
|
|
-
|
|
+
|
|
|
|
+
|
|
for(int i = 0; i < tlist.size() && i < 6; i ++) {
|
|
for(int i = 0; i < tlist.size() && i < 6; i ++) {
|
|
float score = (float) (tlist.get(i).getValue());
|
|
float score = (float) (tlist.get(i).getValue());
|
|
result.put(tlist.get(i).getKey(), score + categoryCount(tlist.get(i).getKey(), pmap));
|
|
result.put(tlist.get(i).getKey(), score + categoryCount(tlist.get(i).getKey(), pmap));
|
|
@@ -436,5 +462,130 @@ public class RecommendService {
|
|
}
|
|
}
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public void createSimilarBugLog(HttpSession session,List<BugMirror> mirrorList,List<Float> scores){
|
|
|
|
+ Bug userBug=constructUserBug(session);
|
|
|
|
+ StringBuilder log=new StringBuilder("userJson:");
|
|
|
|
+ log.append(objectToStr(userBug,','));
|
|
|
|
+ log.append("\n");
|
|
|
|
+ log.append("similarJson:");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ for(int i=0;i<mirrorList.size();i++){
|
|
|
|
+ Bug similarBug=bugdao.findByid(mirrorList.get(i).getId());
|
|
|
|
+ log.append(objectToStr(similarBug,','));
|
|
|
|
+ log.append("score:"+scores.get(i)+",");
|
|
|
|
+ log.append("\n");
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ Logger logger= LoggerFactory.getLogger(RecommendService.class);
|
|
|
|
+ logger.info(String.valueOf(log));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private static StringBuilder objectToStr(Object o,char separator){
|
|
|
|
+ StringBuilder sb=new StringBuilder();
|
|
|
|
+ Field[] fields=o.getClass().getDeclaredFields();
|
|
|
|
+ String[] fieldNames=new String[fields.length];
|
|
|
|
+ for(int i=0;i<fields.length;i++){
|
|
|
|
+
|
|
|
|
+ fieldNames[i]=fields[i].getName();
|
|
|
|
+ sb.append(fieldNames[i]+":");
|
|
|
|
+ sb.append(getFieldValueByName(fieldNames[i],o));
|
|
|
|
+ sb.append(separator);
|
|
|
|
+ }
|
|
|
|
+ return sb;
|
|
|
|
+ }
|
|
|
|
+ private static Object getFieldValueByName(String fieldName, Object o) {
|
|
|
|
+ try {
|
|
|
|
+ String firstLetter = fieldName.substring(0, 1).toUpperCase();
|
|
|
|
+ String getter = "get" + firstLetter + fieldName.substring(1);
|
|
|
|
+ Method method = o.getClass().getMethod(getter, new Class[] {});
|
|
|
|
+ Object value = method.invoke(o, new Object[] {});
|
|
|
|
+ return value;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|