Map oneMap=content.get(i);
for(String str:oneMap.keySet()){
int count = oneMap.get(str);
CombinerKeyNum(str,count,allKeyWords);
}
}
List> sortedMap=sortMapByValue(allKeyWords);
log.info(sortedMap);
}
/**
*
*
@param allKeyWords 需要进行排序的map
*/
public static List> sortMapByValue(Map allKeyWords){
List> sortList=new ArrayList<>(allKeyWords.entrySet());
Collections.sort(sortList, new Comparator>() {
public int compare(Map.Entry o1, Map.Entry o2) {
return (o2.getValue() - o1.getValue());
}
});
return sortList;
}
/**
*
* @param key 关键词变量
* @param value 关键词词频变量
* @param allKeyWords 存放关键词和词频的map
*/
public static void CombinerKeyNum(String key,int value,Map allKeyWords){
if(allKeyWords.containsKey(key)){
int count=allKeyWords.get(key);
count+=value;
allKeyWords.put(key, count);
}else{
allKeyWords.put(key, value);
}
}
/**
*
* @param content 需要提取关键词的字符串变量
* @return 返回关键词以及关键词词频数的map
*
*/
public static HashMap getKeyWordMap(String content) {
List list = StandardTokenizer.SEGMENT.seg(content);
TextRankKeyword textmap = new TextRankKeyword();
Map map = textmap.getTermAndRank(content);
Map mapCount = new HashMap<>();
for (String str : map.keySet()) {
String keyStr = str;
int count = 0;
for (int i = 0; i < list.size(); i++) {
if (keyStr.equals(list.get(i).word)) {
count++;
}
}
mapCount.put(keyStr, Integer.valueOf(count));
}
// log.info(mapCount);
return (HashMap) mapCount;
}
}
运行之后,结果如下:
由此可见,可以看见从excel中提取出来的热点词汇及其频率。
文章来源于计算机之wind的博客