Commit 2fb7eb7f by 徐甲彬

Merge remote-tracking branch 'origin/master'

2 parents fc6d3125 20856bae
......@@ -22,6 +22,7 @@ import com.dookay.cihai.core.aip.consts.LexerNeConst;
import com.dookay.cihai.core.aip.consts.LexerPosConst;
import com.dookay.cihai.core.aip.model.DepParserItem;
import com.dookay.cihai.core.aip.model.LexerItem;
import com.dookay.cihai.core.aip.model.WordCount;
import com.dookay.cihai.core.aip.model.WordRelation;
import com.dookay.coral.common.core.exception.ServiceException;
import com.dookay.coral.common.core.utils.lang.CollectionUtils;
......@@ -142,8 +143,9 @@ public final class AipWordUtilBean {
* @author houkun
* @date 2017/12/6
*/
public Map<String, Long> extractNounWordsWithCount(String document) throws JSONException {
public List<WordCount> extractNounWordsWithCount(String document) throws JSONException {
List<LexerItem> lexerItems = getLexerItems(document);
ArrayList<WordCount> wordCounts = new ArrayList<>();
Map<String, Long> itemCount = lexerItems.stream()
.filter(l -> LexerPosConst.inThis(l.getPos())
|| LexerNeConst.inThis(l.getNe()))
......@@ -151,7 +153,16 @@ public final class AipWordUtilBean {
LexerItem::getItem,
Collectors.counting()
));
return itemCount;
int i = 0;
for (Map.Entry<String, Long> entry : itemCount.entrySet()) {
WordCount wordCount = new WordCount();
wordCount.setId(i);
wordCount.setLabel(entry.getKey());
wordCount.setValue(entry.getValue());
wordCounts.add(wordCount);
i++;
}
return wordCounts;
}
/**
......
package com.dookay.cihai.core.aip.model;
/*****************************************
* *
* @dookay.com Internet make it happen *
* ----------- ----------------------- *
* dddd ddddd Internet make it happen *
* o o o Internet make it happen *
* k k k Internet make it happen *
* a a a Internet make it happen *
* yyyy yyyyy Internet make it happen *
* ----------- ----------------------- *
* @dookay.com Internet make it happen *
* *
****************************************/
import lombok.Data;
/**
* 关键词次数
*
* @author houkun
* @date 2017/12/7
*/
@Data
public class WordCount {
private int id;
private String label;
private long value;
}
......@@ -16,6 +16,7 @@ package com.dookay.cihai.wechat.controller;
import com.alibaba.fastjson.JSONObject;
import com.dookay.cihai.core.aip.AipWordUtilBean;
import com.dookay.cihai.core.aip.model.WordCount;
import com.dookay.cihai.core.aip.model.WordRelation;
import com.dookay.cihai.core.aip.model.WordSequence;
import com.dookay.cihai.core.theme.domain.ThemeDomain;
......@@ -30,8 +31,9 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
......@@ -71,8 +73,12 @@ public class ThemeController extends BaseController {
public JsonResult related(@PathVariable Long id) {
ThemeDomain themeDomain = themeService.get(id);
String document = themeDomain.getIntroduce();
Map<String, Long> wordCountMap = aipWordUtilBean.extractNounWordsWithCount(document);
return successResult("关联词出现次数", wordCountMap);
List<WordCount> wordCounts = aipWordUtilBean.extractNounWordsWithCount(document);
List<WordCount> collect = wordCounts.stream().sorted(Comparator.comparingDouble(l -> Math.random())).limit(8).collect(Collectors.toList());
JSONObject result = new JSONObject();
result.put("nodes", collect);
result.put("edges", new ArrayList<>(0));
return successResult("关联词出现次数", result);
}
/**
......
......@@ -339,8 +339,32 @@
<script src="${ctx}/static/js/special.js"></script>
<script>
function loadMap() {
jQuery.get(location.href + "/map", {}, function (data) {
if (data.code == "OK") {
mapData = data.data;
relationPic('relation-pic', mapData);
} else {
console.log("请求数据失败");
}
});
}
function loadRelated() {
jQuery.get(location.href + "/related", {}, function (data) {
if (data.code == "OK") {
mapData = data.data;
relationPic('word-analysis', relateData);
} else {
console.log("请求数据失败");
}
});
}
function relationPic(id, data) {
return new vis.Network(document.getElementById(id), relationPicData, {
return new vis.Network(document.getElementById(id), mapData, {
nodes: {
shape: 'dot',
borderWidth: 3,
......@@ -358,57 +382,16 @@
}
});
};
var relationPicData = {
nodes: [{
id: 1,
label: 'Node 1',
value: 15
},
{
id: 2,
label: 'Node 2',
value: 25
},
{
id: 3,
label: 'Node 3',
value: 50
},
{
id: 4,
label: 'Node 4',
value: 30
},
{
id: 5,
label: 'Node 5',
value: 8
}
],
edges: [{
from: 1,
to: 3
},
{
from: 1,
to: 2
},
{
from: 2,
to: 4
},
{
from: 2,
to: 5
}
]
};
relationPic('relation-pic', relationPicData);
relationPicData.edges = [];
var wordAnalysis = relationPic('word-analysis', relationPicData);
$('.js-refresh').click(function () {
wordAnalysis.destroy();
wordAnalysis = relationPic('word-analysis', relationPicData);
loadRelated();
});
var mapData = {};
var relateData = {};
relationPic('relation-pic', mapData);
var wordAnalysis = relationPic('word-analysis', mapData);
loadMap();
loadRelated();
</script>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!