Skip to content
Snippets Groups Projects
Commit af32a45c authored by eggle's avatar eggle
Browse files

+关键词count

parent 256490f9
No related branches found
No related tags found
No related merge requests found
......@@ -6,9 +6,7 @@ import com.example.authorservice.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.*;
@Service
......@@ -34,8 +32,38 @@ public class AuthorDisplayServiceImpl implements AuthorDisplayService{
public ResponseVO getAuthorTopicsById(String id) {
try {
String str=authorDisplayMapper.selectAuthorTopicsById(id);
List<String> res=Arrays.asList(str.split("\n|;"));
return ResponseVO.buildSuccess(res);
List<String> aff=Arrays.asList(str.split("\n|;"));
HashMap<String,Integer> res=new HashMap<>();
for(int i=0;i<aff.size();i++){
Set<String> wordSet=res.keySet();
String topic=aff.get(i);
//如果已经有这个单词了,
if(topic.equals("\r")){
continue;
}
if(wordSet.contains(topic))
{
Integer number=res.get(topic);
number++;
res.put(topic, number);
}
else {
res.put(topic, 1);
}
}
List<HashMap.Entry<String, Integer>> list = new ArrayList<HashMap.Entry<String, Integer>>(res.entrySet());
Collections.sort(list, new Comparator<HashMap.Entry<String, Integer>>() {
//降序排序
@Override
public int compare(HashMap.Entry<String, Integer> o1, HashMap.Entry<String, Integer> o2) {
return o2.getValue().compareTo(o1.getValue());
}
});
// StringBuilder resStr=new StringBuilder("{");
// for (HashMap.Entry<String, Integer> mapping : list) {
// resStr.append(mapping.getKey()).append(",").append(mapping.getValue()).append(";");
// }
return ResponseVO.buildSuccess(list);
} catch (Exception e){
e.printStackTrace();
return ResponseVO.buildFailure("失败");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment